Skip to main content
The MCP (Model Context Protocol), developed by Anthropic, is an open protocol that standardizes how applications provide context to LLMs.

Prerequisites

  • BeeAI Framework installed with pip install beeai-framework
  • BeeAI Framework extension for MCP installed with pip install 'beeai-framework[mcp]'

MCP Client

MCPTool allows you to consume external tools exposed via MCP protocol. See the MCP Tool page for more information.

MCP Server

MCPServer allows you to expose your components (Tools, Agents, Chat Models, Runnable) to external systems that support the Model Context Protocol (MCP) standard, enabling seamless integration with LLM tools ecosystems. Key benefits
  • Fast setup with minimal configuration
  • Support for multiple transport options
  • Register multiple tools on a single server
  • Custom server settings and instructions
from beeai_framework.adapters.mcp.serve.server import MCPServer, MCPServerConfig, MCPSettings
from beeai_framework.tools import tool
from beeai_framework.tools.types import StringToolOutput
from beeai_framework.tools.weather.openmeteo import OpenMeteoTool


@tool
def reverse_tool(word: str) -> StringToolOutput:
    """A tool that reverses a word"""
    return StringToolOutput(result=word[::-1])


def main() -> None:
    """Create an MCP server with custom config, register ReverseTool and OpenMeteoTool to the MCP server and run it."""

    config = MCPServerConfig(transport="streamable-http", settings=MCPSettings(port=8001))  # optional
    server = MCPServer(config=config)
    server.register_many([reverse_tool, OpenMeteoTool()])
    server.serve()


if __name__ == "__main__":
    main()

You can also register agents, chat models, or any other runnable.

Configuration

The MCP Server Adapter uses the MCPServerConfig class to configure the MCP server:
class MCPServerConfig(BaseModel):
	transport: Literal["stdio", "sse", "streamable-http"] = "stdio"
	name: str = "MCP Server"
	instructions: str | None = None
	settings: MCPSettings | mcp_server.Settings = Field(default_factory=lambda: MCPSettings())
Transport Options:
  • stdio: Uses standard input/output for communication (default)
  • streamable-http: Uses HTTP POST and GET requests (replaces sse)
  • sse: Uses server-sent events over HTTP (deprecated)

Custom Instances

If you want to make your custom class compatible with an MCP server, you can do so by registering a custom mapper via MCPServer.register_factory(...).