MCP Server
Expose agents using the Model Context Protocol (MCP).
What is MCP?
MCP (Model Context Protocol) is a standardized protocol for AI systems to interact with external tools and data sources.
Enabling MCP
export AK_MCP__ENABLED=true
or
mcp:
enabled: true
Endpoint: The MCP server is always mounted at
/mcpon the main API server. The full endpoint ishttp://{api.host}:{api.port}/mcp. Useapi.port(orAK_API__PORT) to change the port.
Starting MCP Server
from agentkernel.api import RESTAPI
if __name__ == "__main__":
RESTAPI.run()
Agent as MCP Tool
Agents are automatically exposed as MCP tools if you set mcp.expose_agents to true. You can selectively expose agents as well.
Custom Tools
Expose custom tools via MCP:
from agentkernel.mcp import MCP
from agentkernel.api import RESTAPI
mcp = MCP.get()
@mcp.tool
def custom_tool(param: str) -> str:
return f"Processed: {param}"
RESTAPI.run()
Configuration
mcp:
enabled: true
expose_agents: true
agents: ['*']
stateless_http: false # Set to true for stateless mode (no Mcp-Session-Id)
Integration
Use agents from other AI systems:
result = mcp_client.call_tool(
"custom_tool",
{"message": "Hello!"}
)
