AgentsAgentBase

enable_mcp_server

View as MarkdownOpen in Claude

Expose this agent’s @tool functions as a Model Context Protocol (MCP) server endpoint. Adds a /mcp route that speaks JSON-RPC 2.0, allowing external MCP clients (Claude Desktop, other agents, etc.) to discover and invoke the same tools.

This method only registers the /mcp HTTP route. It does not automatically add the endpoint to the agent’s SWML output. To include the MCP server in your SWML document for native tool discovery, also call add_mcp_server() pointing at the agent’s own /mcp URL.

This method exposes your agent’s tools as an MCP server. To connect your agent to an external MCP server as a client, use add_mcp_server().

Parameters

None.

Returns

AgentBase — Returns self for method chaining.

Example

1from signalwire import AgentBase
2from signalwire.core.function_result import FunctionResult
3
4agent = AgentBase(name="assistant", route="/assistant")
5agent.set_prompt_text("You are a helpful assistant.")
6
7@agent.tool(name="get_weather", description="Get weather for a city")
8def get_weather(args, raw_data):
9 city = args.get("city", "Unknown")
10 return FunctionResult(f"The weather in {city} is sunny.")
11
12agent.enable_mcp_server()
13agent.serve()