enableMcpServer

View as MarkdownOpen in Claude

Expose this agent’s tools 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 agent’s tools.

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

Parameters

None.

Returns

AgentBase — Returns this for method chaining.

Example

1import { AgentBase, FunctionResult } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'assistant', route: '/assistant' });
4agent.setPromptText('You are a helpful assistant.');
5agent.defineTool({
6 name: 'get_weather',
7 description: 'Get the current weather for a city',
8 parameters: {
9 type: 'object',
10 properties: {
11 city: { type: 'string', description: 'City name' },
12 },
13 },
14 handler: async (args) => {
15 const city = args.city ?? 'Unknown';
16 const result = new FunctionResult(`The weather in ${city} is sunny.`);
17 return result;
18 },
19});
20agent.enableMcpServer();
21await agent.serve();