Stdio Transport

The stdio (standard input/output) transport is the default one in Kern's integration. It works best for local integrations.

To use it, simply initialize the MCPTools class with the command argument. The command you want to pass is the one used to run the MCP server the agent will have access to.

For example uvx mcp-server-git, which runs a git MCP server:

1from kern.agent import Agent
2from kern.models.openai import OpenAIResponses
3from kern.tools.mcp import MCPTools
4
5# Initialize and connect to the MCP server
6# Can also use custom binaries: command="./my-mcp-server"
7mcp_tools = MCPTools(command="uvx mcp-server-git")
8await mcp_tools.connect()
9
10try:
11 agent = Agent(model=OpenAIResponses(id="gpt-5.2"), tools=[mcp_tools])
12 await agent.aprint_response("What is the license for this project?", stream=True)
13finally:
14 # Always close the connection when done
15 await mcp_tools.close()

You can also use multiple MCP servers at once, with the MultiMCPTools class. For example:

1import asyncio
2import os
3
4from kern.agent import Agent
5from kern.tools.mcp import MultiMCPTools
6
7
8async def run_agent(message: str) -> None:
9 """Run the Airbnb and Google Maps agent with the given message."""
10
11 env = {
12 **os.environ,
13 "GOOGLE_MAPS_API_KEY": os.getenv("GOOGLE_MAPS_API_KEY"),
14 }
15
16 # Initialize and connect to multiple MCP servers
17 mcp_tools = MultiMCPTools(
18 commands=[
19 "npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt",
20 "npx -y @modelcontextprotocol/server-google-maps",
21 ],
22 env=env,
23 )
24 await mcp_tools.connect()
25
26 try:
27 agent = Agent(
28 tools=[mcp_tools],
29 markdown=True,
30 )
31
32 await agent.aprint_response(message, stream=True)
33 finally:
34 # Always close the connection when done
35 await mcp_tools.close()
36
37
38# Example usage
39if __name__ == "__main__":
40 # Pull request example
41 asyncio.run(
42 run_agent(
43 "What listings are available in Cape Town for 2 people for 3 nights from 1 to 4 August 2025?"
44 )
45 )