← Back to honi.dev

MCP Server

Expose your agent's tools as a Model Context Protocol (MCP) endpoint — connect from Claude Desktop, Cursor, or any MCP-compatible client.

How it works

Honi agents automatically expose a /mcp route when tools are defined. The endpoint speaks JSON-RPC 2.0 and implements the MCP 2024-11-05 protocol spec. No extra config needed — tools you define with tool() are automatically available over MCP.

Endpoints

EndpointMethodDescription
/mcpPOSTJSON-RPC 2.0 MCP endpoint (initialize, tools/list, tools/call)
/mcp/toolsGETConvenience endpoint — lists available tools as JSON

Connect from Claude Desktop

Add your deployed agent to Claude Desktop's MCP config:

JSON — claude_desktop_config.json
1{
2 "mcpServers": {
3 "my-honi-agent": {
4 "url": "https://my-agent.workers.dev/mcp"
5 }
6 }
7}

Connect from Cursor

In Cursor settings → MCP, add a new server with the /mcp URL of your deployed worker.

Authentication

The /mcp endpoint is unauthenticated by default — fine for local Claude Desktop (stdio transport). For remote connections, lock it down with a Bearer token.

Set mcp.secretEnvVar in your agent config:

TypeScript
1createAgent({
2 name: 'my-agent',
3 model: 'claude-sonnet-4-5',
4 tools: [searchDocs],
5 mcp: { secretEnvVar: 'MCP_SECRET' }
6})

Set the secret via Wrangler:

Shell
$wrangler secret put MCP_SECRET

Clients send Authorization: Bearer <secret> on every request. For Claude Desktop with a remote agent:

JSON — claude_desktop_config.json
1{
2 "mcpServers": {
3 "my-honi-agent": {
4 "url": "https://my-agent.workers.dev/mcp",
5 "headers": { "Authorization": "Bearer your-secret" }
6 }
7 }
8}

Standalone MCP Server

You can also use createMcpServer directly without createAgent — useful for exposing a set of tools without a chat interface:

TypeScript
1import { createMcpServer, tool, z } from 'honidev'
2
3const searchDocs = tool({
4 name: 'search_docs',
5 description: 'Search internal documentation',
6 input: z.object({ query: z.string() }),
7 handler: async ({ query }) => searchIndex(query)
8})
9
10const mcp = createMcpServer([searchDocs])
11
12export default {
13 async fetch(req: Request) {
14 return mcp.handleHttp(req)
15 }
16}

API Reference

createMcpServer(tools)

Creates an MCP server from an array of tool definitions. Returns an object with:

PropertyTypeDescription
handleHttp(req: Request) => Promise<Response>HTTP handler — wire directly to your Worker's fetch
handleRequest(req: McpRequest) => Promise<McpResponse>Low-level JSON-RPC handler
toolsMcpToolInfo[]Tool definitions in MCP format

toolsToMcp(tools)

Converts an array of Honi ToolDefinition objects to MCP tool format (with JSON Schema). Useful if you need the tool list for other purposes.

Supported MCP Methods

MethodDescription
initializeHandshake — returns protocol version and capabilities
tools/listReturns all tools with their JSON Schema definitions
tools/callExecutes a tool by name with validated arguments
pingHealth check