Skip to navigation

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.

The endpoint requires the agent’s basic auth credentials, so an MCP client must send an Authorization header. It lists and calls only the tools the agent runs itself, not DataMap or external webhook 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

import { AgentBase, FunctionResult } from '@signalwire/sdk';
const agent = new AgentBase({ name: 'assistant', route: '/assistant' });
agent.setPromptText('You are a helpful assistant.');
agent.defineTool({
name: 'get_weather',
description: 'Get the current weather for a city',
parameters: {
type: 'object',
properties: {
city: { type: 'string', description: 'City name' },
},
},
handler: async (args) => {
const city = args.city ?? 'Unknown';
const result = new FunctionResult(`The weather in ${city} is sunny.`);
return result;
},
});
agent.enableMcpServer();
await agent.serve();