MCPServer allows you to expose your tools 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
Copy
Ask AI
from mcp.server.fastmcp.server import Settingsfrom beeai_framework.adapters.mcp.serve.server import MCPServer, MCPServerConfigfrom beeai_framework.tools import toolfrom beeai_framework.tools.types import StringToolOutputfrom beeai_framework.tools.weather.openmeteo import OpenMeteoTool@tooldef reverse_tool(word: str) -> StringToolOutput: """ A tool that reverses a word """ return StringToolOutput(result=word[::-1])def main() -> None: # create a MCP server with custom config, register ReverseTool and OpenMeteoTool to the MCP server and run it MCPServer(config=MCPServerConfig(transport="sse", settings=Settings(port=8001))).register_many( [reverse_tool, OpenMeteoTool()] ).serve()if __name__ == "__main__": main()
The MCP adapter uses the MCPServerConfig class to configure the MCP server:
Copy
Ask AI
class MCPServerConfig(BaseModel):"""Configuration for the MCPServer."""transport: Literal["stdio", "sse"] = "stdio" # Transport protocol (stdio or server-sent events)name: str = "MCP Server" # Name of the MCP serverinstructions: str | None = None # Optional instructions for the serversettings: mcp_server.Settings[Any] = Field(default_factory=lambda: mcp_server.Settings())
Transport Options
stdio: Uses standard input/output for communication (default)
sse: Uses server-sent events over HTTP
Creating an MCP server is easy. You instantiate the MCPServer class with your configuration, register your tools, and then call serve() to start the server:
Copy
Ask AI
from beeai_framework.adapters.mcp import MCPServer, MCPServerConfigfrom beeai_framework.tools.weather import OpenMeteoTool# Create an MCP server with default configurationserver = MCPServer()# Register toolsserver.register(OpenMeteoTool())# Start servingserver.serve()
You can configure the server behavior by passing a custom configuration: