Skip to main content

Model Context Protocol (MCP)

MCP provides a standardized transport for connecting agents to external tools, resources, and prompts over stdio or streamable HTTP. ish-harness keeps JSON-RPC framing, protocol negotiation (2025-03-26), tool normalization, and structured schema validation in Rust while exposing language-native transport clients and server adapters in every SDK.

import asyncio
from ish import Agent, OpenAICompatibleModel
from ish.integrations.protocols import load_mcp_tools

async def main() -> None:
async with await load_mcp_tools(command=["python3", "mcp_server.py"]) as tools:
agent = Agent(
name="mcp_user",
model=OpenAICompatibleModel(model="gpt-4o-mini"),
instructions="Use connected MCP tools when needed.",
tools=list(tools),
)
result = await agent.run("Add 40 and 2 using the MCP tool.")
print(result.content)

asyncio.run(main())

Load MCP tools into an agent​

Connect to a local stdio or remote HTTP MCP server, discover its tool catalog, and wire those tools into an Agent run:

Read resources, retrieve prompts​

Inspect and fetch server-hosted resources and reusable prompt templates over stdio or remote HTTP transports:

import asyncio
from ish.integrations.protocols import RemoteMCPClient

async def main() -> None:
async with RemoteMCPClient(
url="https://mcp.example.com/mcp",
headers={"Authorization": "Bearer token"},
) as client:
resources = await client.list_resources()
doc = await client.read_resource(resources[0]["uri"])
prompts = await client.list_prompts()
rendered = await client.get_prompt(prompts[0]["name"], {"topic": "sandboxes"})
print(doc, rendered)

asyncio.run(main())

Serve tools, resources, prompts​

Expose custom tools, read-only resources, and prompt definitions over stdio (serve_stdio / runStdio) or embed request handling (handleRequest) inside your own server:

from ish import tool
from ish.integrations.protocols import (
MCPPromptDefinition,
MCPResourceDefinition,
MCPServer,
)

@tool
def add(a: int, b: int) -> int:
"""Add two integers."""
return a + b

server = MCPServer(
tools=[add],
resources=[
MCPResourceDefinition(
uri="docs://guide",
name="guide",
description="Project guide",
mimeType="text/plain",
read=lambda _uri: "Use MCP tools and resources safely.",
)
],
prompts=[
MCPPromptDefinition(
name="review",
description="Review a topic",
arguments=[{"name": "topic", "required": True}],
handler=lambda topic: {
"messages": [{"role": "user", "content": {"type": "text", "text": f"Review {topic}"}}]
},
)
],
)

if __name__ == "__main__":
server.serve_stdio()