Skip to content

Using MCP

An agent can use the tools of any MCP server. Register the server, and you get back a description of each of its tools. Pass those to the AgentBuilder with tools(...).

Each tool is registered as {prefix}__{name}, so tools from different servers don’t clash. For example, the fetch tool of a server registered under fetch becomes fetch__fetch.

register_mcp_stdio starts the server as a local process and talks to it over stdin and stdout. This runs mcp-server-fetch with uvx:

import asyncio
from ailoy import AgentBuilder, register_mcp_stdio
async def main() -> None:
tools = await register_mcp_stdio("fetch", "uvx", ["mcp-server-fetch"])
agent = await (
AgentBuilder("anthropic/claude-haiku-5-5")
.tools(tools)
.build()
)
async for output in agent.run("Summarize https://modelcontextprotocol.io in three sentences."):
for part in output["message"]["contents"]:
if part["type"] == "text":
print(part["text"])
asyncio.run(main())

register_mcp_streamable_http connects to a remote server by its URL. This registers DeepWiki’s server, which answers questions about GitHub repositories:

from ailoy import register_mcp_streamable_http
tools = await register_mcp_streamable_http("deepwiki", "https://mcp.deepwiki.com/mcp")

Pass tools to AgentBuilder.tools(...) as above.

unregister_mcp (unregisterMcp in Node.js) removes a server’s tools by their prefix and closes the connection to the server.

from ailoy import unregister_mcp
unregister_mcp("fetch")