>_ DOCS / HOW-TO GUIDES
SET UP THE
MCP SERVER.
Connect Claude Desktop, Cursor, or any MCP-compatible host to P402 routing — no SDK, no code changes to your existing agents.
How It Works
The P402 MCP server exposes six tools over the Model Context Protocol (MCP). When your AI host calls p402_chat, P402 routes the request to the cheapest capable provider, applies your session budget, and returns an OpenAI-compatible response — all transparently.
Run the Server
The server ships as an npm package. No global install needed — npx handles it.
P402_API_KEY=your_key npx -y @p402/mcp-server@latestThe server starts on stdio (default) or --transport sse --port 3100 for HTTP SSE mode.
Configure Claude Desktop
Open claude_desktop_config.json and add the P402 server block. Claude Desktop auto-restarts the server on each session.
{
"mcpServers": {
"p402": {
"command": "npx",
"args": ["-y", "@p402/mcp-server@latest"],
"env": {
"P402_API_KEY": "your_p402_api_key_here"
}
}
}
}Restart Claude Desktop
After saving the config, fully quit and reopen Claude Desktop. You should see a hammer icon (🔨) in the composer — that's the MCP tools menu.
Configure Cursor
In Cursor: Settings → MCP → Add Server. Use the stdio transport.
{
"mcpServers": {
"p402": {
"command": "npx",
"args": ["-y", "@p402/mcp-server@latest"],
"env": { "P402_API_KEY": "your_key" }
}
}
}Custom MCP Host (SSE)
For programmatic access, start the server in HTTP SSE mode and connect with the official MCP TypeScript SDK.
# Terminal 1 — start the server
P402_API_KEY=your_key npx -y @p402/mcp-server@latest --transport sse --port 3100// Terminal 2 — connect via SDK
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
const client = new Client({ name: 'my-agent', version: '1.0' }, { capabilities: {} });
const transport = new SSEClientTransport(new URL('http://localhost:3100/sse'));
await client.connect(transport);
// Call p402_chat
const result = await client.callTool({
name: 'p402_chat',
arguments: {
messages: [{ role: 'user', content: 'What is EIP-3009?' }],
mode: 'cost',
cache: true,
session_id: 'YOUR_SESSION_ID', // optional
},
});
console.log(result.content[0].text);