SSE Transport
Kern's MCP integration supports the SSE transport. This transport enables server-to-client streaming, and can prove more useful than stdio when working with restricted networks.
Note
This transport is not recommended anymore by the MCP protocol. Use the Streamable HTTP transport instead.
To use it, initialize the MCPTools passing the URL of the MCP server and setting the transport to sse:
1from kern.agent import Agent2from kern.models.openai import OpenAIResponses3from kern.tools.mcp import MCPTools45server_url = "http://localhost:8000/sse"67# Initialize and connect to the SSE MCP server8mcp_tools = MCPTools(url=server_url, transport="sse")9await mcp_tools.connect()1011try:12 agent = Agent(model=OpenAIResponses(id="gpt-5.2"), tools=[mcp_tools])13 await agent.aprint_response("What is the license for this project?", stream=True)14finally:15 # Always close the connection when done16 await mcp_tools.close()You can also use the server_params argument to define the MCP connection. This way you can specify the headers to send to the MCP server with every request, and the timeout values:
1from kern.tools.mcp import MCPTools, SSEClientParams23server_params = SSEClientParams(4 url=...,5 headers=...,6 timeout=...,7 sse_read_timeout=...,8)910# Initialize and connect using server parameters11mcp_tools = MCPTools(server_params=server_params, transport="sse")12await mcp_tools.connect()1314try:15 # Use mcp_tools with your agent16 pass17finally:18 await mcp_tools.close()Complete example
Let's set up a simple local server and connect to it using the SSE transport:
Setup the server
1from mcp.server.fastmcp import FastMCP23mcp = FastMCP("calendar_assistant")456@mcp.tool()7def get_events(day: str) -> str:8 return f"There are no events scheduled for {day}."91011@mcp.tool()12def get_birthdays_this_week() -> str:13 return "It is your mom's birthday tomorrow"141516if __name__ == "__main__":17 mcp.run(transport="sse")Setup the client
1import asyncio23from kern.agent import Agent4from kern.models.openai import OpenAIResponses5from kern.tools.mcp import MCPTools, MultiMCPTools67# This is the URL of the MCP server we want to use.8server_url = "http://localhost:8000/sse"91011async def run_agent(message: str) -> None:12 # Initialize and connect to the SSE MCP server13 mcp_tools = MCPTools(transport="sse", url=server_url)14 await mcp_tools.connect()1516 try:17 agent = Agent(18 model=OpenAIResponses(id="gpt-5.2"),19 tools=[mcp_tools],20 markdown=True,21 )22 await agent.aprint_response(message=message, stream=True, markdown=True)23 finally:24 await mcp_tools.close()252627# Using MultiMCPTools, we can connect to multiple MCP servers at once, even if they use different transports.28# In this example we connect to both our example server (SSE transport), and a different server (stdio transport).29async def run_agent_with_multimcp(message: str) -> None:30 # Initialize and connect to multiple MCP servers with different transports31 mcp_tools = MultiMCPTools(32 commands=["npx -y @openbnb/mcp-server-airbnb --ignore-robots-txt"],33 urls=[server_url],34 urls_transports=["sse"],35 )36 await mcp_tools.connect()3738 try:39 agent = Agent(40 model=OpenAIResponses(id="gpt-5.2"),41 tools=[mcp_tools],42 markdown=True,43 )44 await agent.aprint_response(message=message, stream=True, markdown=True)45 finally:46 await mcp_tools.close()474849if __name__ == "__main__":50 asyncio.run(run_agent("Do I have any birthdays this week?"))51 asyncio.run(52 run_agent_with_multimcp(53 "Can you check when is my mom's birthday, and if there are any AirBnb listings in SF for two people for that day?"54 )55 )Run the server
1python sse_server.pyRun the client
1python sse_client.py