Integrate with MCP
The Model Context Protocol (MCP) is an open protocol developed by Anthropic to standardize how language models interact with external systems—such as tools, memory backends, and context managers. MCP enables structured, dynamic communication between an LLM and its environment, empowering models to access external tools, retrieve real-time information, and perform complex, multi-step reasoning.
Using MCP with Ailoy
Ailoy Agents can seamlessly integrate with existing MCP-compliant servers. For example, the following code connects to the official GitHub MCP server:
- Python
- JavaScript(Node)
from mcp import StdioServerParameters
agent.add_tools_from_mcp_server(
StdioServerParameters(
"github",
command="npx",
args=["-y", "@modelcontextprotocol/server-github"]
)
)
await agent.addToolsFromMcpServer("github", {
command: "npx",
args: ["-y", "@modelcontextprotocol/server-github"],
});
This launches the GitHub MCP server as a subprocess using standard I/O for communication. The agent automatically discovers the tools exposed by the server and registers them into its internal toolset.
Querying via MCP Tools
Once the tools are registered, the agent can invoke them as needed when you call the query() method:
- Python
- JavaScript(Node)
question = "Search the repository named brekkylab/ailoy and describe what it does based on its README.md."
for resp in agent.query(question):
agent.print(resp)
const question =
"Search the repository named brekkylab/ailoy and describe what it does based on its README.md.";
for await (const resp of agent.query(question)) {
agent.print(resp);
}
This demonstrates how the agent utilizes the GitHub MCP tools to search repositories and summarize their contents.
Complete Example
Here is the full source code to set up an agent, connect it to the GitHub MCP server, and issue a query:
- Python
- JavaScript(Node)
from ailoy import Runtime, Agent
from mcp import StdioServerParameters
rt = Runtime()
with Agent(rt, model_name="Qwen/Qwen3-8B") as agent:
# Add tools from Github MCP server
agent.add_tools_from_mcp_server(
"github",
StdioServerParameters(
command="npx",
args=["-y", "@modelcontextprotocol/server-github"]
)
)
question = "Search the repository named brekkylab/ailoy and describe what it does based on its README.md."
for resp in agent.query(question):
agent.print(resp)
import { startRuntime, defineAgent } from "ailoy-node";
(async () => {
const rt = await startRuntime();
const agent = await defineAgent(rt, "Qwen/Qwen3-8B");
// Add tools from Github MCP server
await agent.addToolsFromMcpServer("github", {
command: "npx",
args: ["-y", "@modelcontextprotocol/server-github"],
});
const question =
"Search the repository named brekkylab/ailoy and describe what it does based on its README.md.";
for await (const resp of agent.query(question)) {
agent.print(resp);
}
})();