MCP
Use @codespar/mcp to connect CodeSpar tools to Claude Desktop, Cursor, and other MCP-compatible clients.
MCP Adapter
The @codespar/mcp adapter exposes CodeSpar tools as an MCP (Model Context Protocol) server, allowing you to use them in Claude Desktop, Cursor, Windsurf, and any other MCP-compatible client. No code required -- configure the MCP server, restart your client, and the 6 meta-tools appear in the tool palette.
This is the fastest way to try CodeSpar. If you already use Claude Desktop or Cursor, you can be up and running in under 2 minutes.
Installation
npm install -g @codespar/mcppnpm add -g @codespar/mcpyarn global add @codespar/mcp[!TIP] You do not need to install globally. The MCP configuration below uses
npx, which will download and run@codespar/mcpautomatically. Global installation is only needed if you want to avoid thenpxstartup delay.
API Reference
getMcpConfig(options): McpConfig
Returns a generic MCP server configuration object that can be used with any MCP-compatible client. This is the base function -- the client-specific helpers below call it internally.
import { getMcpConfig } from "@codespar/mcp";
const config = getMcpConfig({
apiKey: process.env.CODESPAR_API_KEY,
servers: ["stripe", "mercadopago", "correios"],
});
console.log(JSON.stringify(config, null, 2));{
"command": "npx",
"args": ["@codespar/mcp", "serve", "--servers", "stripe,mercadopago,correios"],
"env": {
"CODESPAR_API_KEY": "csk_live_..."
}
}Parameters:
| Parameter | Type | Required | Description |
|---|---|---|---|
apiKey | string | Yes | Your CodeSpar API key (csk_live_ or csk_test_) |
servers | string[] | No | MCP servers to connect. Omit to connect all available servers. |
getClaudeDesktopConfig(options): ClaudeDesktopConfig
Returns a configuration snippet ready to paste into Claude Desktop's claude_desktop_config.json. The output is the complete mcpServers block.
import { getClaudeDesktopConfig } from "@codespar/mcp";
const config = getClaudeDesktopConfig({
apiKey: "csk_live_your_key_here",
servers: ["stripe", "asaas", "correios", "twilio"],
});
console.log(JSON.stringify(config, null, 2));{
"mcpServers": {
"codespar": {
"command": "npx",
"args": ["@codespar/mcp", "serve", "--servers", "stripe,asaas,correios,twilio"],
"env": {
"CODESPAR_API_KEY": "csk_live_your_key_here"
}
}
}
}getCursorConfig(options): CursorConfig
Returns a configuration snippet for Cursor's MCP settings file (.cursor/mcp.json).
import { getCursorConfig } from "@codespar/mcp";
const config = getCursorConfig({
apiKey: "csk_live_your_key_here",
servers: ["stripe", "twilio"],
});
console.log(JSON.stringify(config, null, 2));{
"mcpServers": {
"codespar": {
"command": "npx",
"args": ["@codespar/mcp", "serve", "--servers", "stripe,twilio"],
"env": {
"CODESPAR_API_KEY": "csk_live_your_key_here"
}
}
}
}Setup guides
Claude Desktop
Open Claude Desktop and go to Settings (gear icon).
Navigate to Developer and click Edit Config. This opens the claude_desktop_config.json file.
Add the CodeSpar MCP server configuration. If you already have other MCP servers configured, add the codespar entry to the existing mcpServers object:
{
"mcpServers": {
"codespar": {
"command": "npx",
"args": ["@codespar/mcp", "serve"],
"env": {
"CODESPAR_API_KEY": "csk_live_your_key_here"
}
}
}
}To limit which servers are accessible, add the --servers flag:
{
"mcpServers": {
"codespar": {
"command": "npx",
"args": ["@codespar/mcp", "serve", "--servers", "stripe,mercadopago,correios"],
"env": {
"CODESPAR_API_KEY": "csk_live_your_key_here"
}
}
}
}Save the file and restart Claude Desktop.
Look for the hammer icon in the chat input. Click it to see the list of available CodeSpar tools. You should see all 6 meta-tools: codespar_discover, codespar_checkout, codespar_pay, codespar_invoice, codespar_ship, and codespar_notify.
[!NOTE] Claude Desktop discovers all 6 meta-tools automatically. You can now ask Claude to process payments, create invoices, ship packages, and send notifications -- all from the chat interface.
Example prompts to try:
- "Discover what payment tools are available"
- "Create a R$49.90 checkout link for the Pro Plan using Stripe"
- "Generate a Pix QR code for R$250"
- "Check shipping rates from Sao Paulo to Rio de Janeiro for a 2kg package"
- "Send an order confirmation via WhatsApp to +5511999887766"
Cursor
Create a .cursor directory in your project root (if it does not exist) and add an mcp.json file:
{
"mcpServers": {
"codespar": {
"command": "npx",
"args": ["@codespar/mcp", "serve"],
"env": {
"CODESPAR_API_KEY": "csk_live_your_key_here"
}
}
}
}Restart Cursor or reload the window (Cmd+Shift+P then "Developer: Reload Window").
Open the Cursor agent panel (Cmd+L or the chat sidebar). CodeSpar tools are now available in agent mode. You can ask the agent to perform commerce operations directly.
[!TIP] The
.cursor/mcp.jsonfile is project-scoped. Add it to.gitignoreif it contains your API key, or use environment variables in your shell profile and reference them in the config.
To use global Cursor MCP settings instead:
- Open Cursor settings (
Cmd+,) - Search for "MCP" in the settings search bar
- Add the same configuration in the global MCP settings field
Windsurf
Open Windsurf settings and navigate to the MCP configuration section.
Add the CodeSpar MCP server:
{
"mcpServers": {
"codespar": {
"command": "npx",
"args": ["@codespar/mcp", "serve"],
"env": {
"CODESPAR_API_KEY": "csk_live_your_key_here"
}
}
}
}Restart Windsurf. CodeSpar tools will appear in the agent's available tools list.
Custom MCP Client
If you are building your own MCP client or integrating with a less common one, use the generic getMcpConfig function:
import { getMcpConfig } from "@codespar/mcp";
const config = getMcpConfig({
apiKey: process.env.CODESPAR_API_KEY,
servers: ["stripe", "mercadopago", "correios", "twilio"],
});
// Pass this config to your MCP client implementation
// The MCP server will spawn as a child process using the command and argsThe MCP server exposes tools following the Model Context Protocol specification. Each tool includes:
| Field | Type | Description |
|---|---|---|
name | string | Tool identifier (e.g., codespar_checkout) |
description | string | Human-readable description of what the tool does |
inputSchema | JSONSchema | JSON Schema defining the tool's parameters |
Example tool listing from the MCP server:
{
"tools": [
{
"name": "codespar_discover",
"description": "Find available commerce tools by domain",
"inputSchema": {
"type": "object",
"properties": {
"domain": {
"type": "string",
"enum": ["payments", "fiscal", "logistics", "messaging", "banking", "erp", "crypto"]
}
},
"required": ["domain"]
}
},
{
"name": "codespar_checkout",
"description": "Create a checkout session for a product or service",
"inputSchema": {
"type": "object",
"properties": {
"provider": { "type": "string" },
"amount": { "type": "number" },
"currency": { "type": "string" },
"description": { "type": "string" },
"payment_methods": {
"type": "array",
"items": { "type": "string" }
}
},
"required": ["provider", "amount", "currency"]
}
}
]
}Specifying servers
By default, the MCP adapter connects to all available servers. You can limit which servers are accessible using the --servers flag. This is useful for scoping the tool set to a specific domain:
{
"mcpServers": {
"codespar-payments": {
"command": "npx",
"args": ["@codespar/mcp", "serve", "--servers", "stripe,mercadopago,asaas"],
"env": {
"CODESPAR_API_KEY": "csk_live_your_key_here"
}
}
}
}You can also run multiple CodeSpar MCP servers with different scopes:
{
"mcpServers": {
"codespar-payments": {
"command": "npx",
"args": ["@codespar/mcp", "serve", "--servers", "stripe,mercadopago"],
"env": {
"CODESPAR_API_KEY": "csk_live_your_key_here"
}
},
"codespar-logistics": {
"command": "npx",
"args": ["@codespar/mcp", "serve", "--servers", "correios,jadlog,melhorenvio"],
"env": {
"CODESPAR_API_KEY": "csk_live_your_key_here"
}
}
}
}[!TIP] Scoping servers improves tool selection accuracy. When the model has fewer tools to choose from, it makes better decisions about which one to call.
Using sandbox keys
For testing, use a csk_test_ API key. The MCP server will route all tool calls to sandbox servers that return realistic mock data:
{
"mcpServers": {
"codespar-sandbox": {
"command": "npx",
"args": ["@codespar/mcp", "serve"],
"env": {
"CODESPAR_API_KEY": "csk_test_your_key_here"
}
}
}
}[!NOTE] Sandbox and production share the same tool interface. Switching from test to live is a single environment variable change.
Troubleshooting
Tools do not appear after restart
-
Verify the config file location. Claude Desktop looks for
claude_desktop_config.jsonin:- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json - Linux:
~/.config/Claude/claude_desktop_config.json
- macOS:
-
Validate JSON syntax. A missing comma or bracket will silently fail. Use
cat claude_desktop_config.json | python3 -m json.toolto validate. -
Check that
npxis available. Open a terminal and runnpx --version. If it is not installed, install Node.js 18+. -
Check the API key. Ensure it starts with
csk_live_orcsk_test_. Keys are case-sensitive.
MCP server crashes on startup
Check the MCP server logs:
- Claude Desktop: Open the developer console (
Cmd+Option+Ion macOS) and look for MCP-related errors. - Cursor: Check the Output panel (
Cmd+Shift+U) and select "MCP" from the dropdown.
Common causes:
| Symptom | Cause | Fix |
|---|---|---|
ENOENT: npx not found | Node.js not in PATH | Add Node.js to your shell PATH or use the full path to npx in the config |
INVALID_API_KEY | Wrong or missing API key | Verify the key in your dashboard at codespar.dev/dashboard/settings |
EACCES: permission denied | npm cache permissions | Run sudo chown -R $(whoami) ~/.npm on macOS/Linux |
TIMEOUT | Network issues | Check your internet connection and verify api.codespar.dev is reachable |
Tool calls return errors
If the MCP server is running but tool calls fail:
- Check server availability. Not all 57 servers are available in all regions. Use
codespar_discoverto see which servers are active for your account. - Verify parameters. Tool call errors often come from missing required parameters. Check the tool's
inputSchemafor required fields. - Check rate limits. Sandbox keys have lower rate limits than production keys.
Slow startup
The first run with npx downloads the @codespar/mcp package, which takes a few seconds. Subsequent runs use the cached version. To eliminate this delay, install globally:
npm install -g @codespar/mcpThen update the config to use the global binary:
{
"mcpServers": {
"codespar": {
"command": "codespar-mcp",
"args": ["serve"],
"env": {
"CODESPAR_API_KEY": "csk_live_your_key_here"
}
}
}
}Next steps
- Introduction -- Architecture overview and the Complete Loop
- Sessions -- How sessions and servers work under the hood
- Tools and Meta-Tools -- The 6 meta-tools explained in detail
- Claude Adapter -- Programmatic integration with the Anthropic SDK
- OpenAI Adapter -- Programmatic integration with the OpenAI SDK
- Quickstart -- End-to-end setup for programmatic usage