Module adcp.server.mcp_tools
MCP server integration helpers.
Provides utilities for registering ADCP handlers with MCP servers.
Functions
def create_mcp_tools(handler: ADCPHandler) ‑> MCPToolSet-
Expand source code
def create_mcp_tools(handler: ADCPHandler) -> MCPToolSet: """Create MCP tools from an ADCP handler. This is the main entry point for MCP server integration. Example with mcp library: from mcp.server import Server from adcp.server import ContentStandardsHandler, create_mcp_tools class MyHandler(ContentStandardsHandler): # ... implement methods handler = MyHandler() tools = create_mcp_tools(handler) server = Server("my-content-agent") @server.list_tools() async def list_tools(): return tools.tool_definitions @server.call_tool() async def call_tool(name: str, arguments: dict): return await tools.call_tool(name, arguments) Args: handler: ADCP handler instance Returns: MCPToolSet with tool definitions and handlers """ return MCPToolSet(handler)Create MCP tools from an ADCP handler.
This is the main entry point for MCP server integration.
Example with mcp library: from mcp.server import Server from adcp.server import ContentStandardsHandler, create_mcp_tools
class MyHandler(ContentStandardsHandler): # ... implement methods handler = MyHandler() tools = create_mcp_tools(handler) server = Server("my-content-agent") @server.list_tools() async def list_tools(): return tools.tool_definitions @server.call_tool() async def call_tool(name: str, arguments: dict): return await tools.call_tool(name, arguments)Args
handler- ADCP handler instance
Returns
MCPToolSet with tool definitions and handlers
def create_tool_caller(handler: ADCPHandler, method_name: str) ‑> Callable[[dict[str, typing.Any]], typing.Any]-
Expand source code
def create_tool_caller( handler: ADCPHandler, method_name: str, ) -> Callable[[dict[str, Any]], Any]: """Create a tool caller function for an ADCP handler method. Args: handler: The ADCP handler instance method_name: Name of the method to call Returns: Async callable that invokes the handler method """ method = getattr(handler, method_name) async def call_tool(params: dict[str, Any]) -> Any: context = ToolContext() result = await method(params, context) # Convert Pydantic models to dicts for MCP serialization if hasattr(result, "model_dump"): return result.model_dump(exclude_none=True) return result return call_toolCreate a tool caller function for an ADCP handler method.
Args
handler- The ADCP handler instance
method_name- Name of the method to call
Returns
Async callable that invokes the handler method
Classes
class MCPToolSet (handler: ADCPHandler)-
Expand source code
class MCPToolSet: """Collection of MCP tools from an ADCP handler. Provides tool definitions and handlers for registering with an MCP server. """ def __init__(self, handler: ADCPHandler): """Create tool set from handler. Args: handler: ADCP handler instance """ self.handler = handler self._tools: dict[str, Callable[[dict[str, Any]], Any]] = {} # Create tool callers for all methods for tool_def in ADCP_TOOL_DEFINITIONS: name = tool_def["name"] self._tools[name] = create_tool_caller(handler, name) @property def tool_definitions(self) -> list[dict[str, Any]]: """Get MCP tool definitions.""" return ADCP_TOOL_DEFINITIONS.copy() async def call_tool(self, name: str, params: dict[str, Any]) -> Any: """Call a tool by name. Args: name: Tool name params: Tool parameters Returns: Tool result Raises: KeyError: If tool not found """ if name not in self._tools: raise KeyError(f"Unknown tool: {name}") return await self._tools[name](params) def get_tool_names(self) -> list[str]: """Get list of available tool names.""" return list(self._tools.keys())Collection of MCP tools from an ADCP handler.
Provides tool definitions and handlers for registering with an MCP server.
Create tool set from handler.
Args
handler- ADCP handler instance
Instance variables
prop tool_definitions : list[dict[str, Any]]-
Expand source code
@property def tool_definitions(self) -> list[dict[str, Any]]: """Get MCP tool definitions.""" return ADCP_TOOL_DEFINITIONS.copy()Get MCP tool definitions.
Methods
async def call_tool(self, name: str, params: dict[str, Any]) ‑> Any-
Expand source code
async def call_tool(self, name: str, params: dict[str, Any]) -> Any: """Call a tool by name. Args: name: Tool name params: Tool parameters Returns: Tool result Raises: KeyError: If tool not found """ if name not in self._tools: raise KeyError(f"Unknown tool: {name}") return await self._tools[name](params)Call a tool by name.
Args
name- Tool name
params- Tool parameters
Returns
Tool result
Raises
KeyError- If tool not found
def get_tool_names(self) ‑> list[str]-
Expand source code
def get_tool_names(self) -> list[str]: """Get list of available tool names.""" return list(self._tools.keys())Get list of available tool names.