Skip to main content
code<spar>
Providers

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/mcp
pnpm add -g @codespar/mcp
yarn global add @codespar/mcp

[!TIP] You do not need to install globally. The MCP configuration below uses npx, which will download and run @codespar/mcp automatically. Global installation is only needed if you want to avoid the npx startup 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));
Output
{
  "command": "npx",
  "args": ["@codespar/mcp", "serve", "--servers", "stripe,mercadopago,correios"],
  "env": {
    "CODESPAR_API_KEY": "csk_live_..."
  }
}

Parameters:

ParameterTypeRequiredDescription
apiKeystringYesYour CodeSpar API key (csk_live_ or csk_test_)
serversstring[]NoMCP 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));
Output
{
  "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));
Output
{
  "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:

claude_desktop_config.json
{
  "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:

claude_desktop_config.json (with specific servers)
{
  "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:

.cursor/mcp.json
{
  "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.json file is project-scoped. Add it to .gitignore if 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:

  1. Open Cursor settings (Cmd+,)
  2. Search for "MCP" in the settings search bar
  3. 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:

Windsurf MCP config
{
  "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:

custom-client.ts
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 args

The MCP server exposes tools following the Model Context Protocol specification. Each tool includes:

FieldTypeDescription
namestringTool identifier (e.g., codespar_checkout)
descriptionstringHuman-readable description of what the tool does
inputSchemaJSONSchemaJSON 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:

Payments only
{
  "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:

Multiple scoped servers
{
  "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:

Sandbox configuration
{
  "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

  1. Verify the config file location. Claude Desktop looks for claude_desktop_config.json in:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
    • Linux: ~/.config/Claude/claude_desktop_config.json
  2. Validate JSON syntax. A missing comma or bracket will silently fail. Use cat claude_desktop_config.json | python3 -m json.tool to validate.

  3. Check that npx is available. Open a terminal and run npx --version. If it is not installed, install Node.js 18+.

  4. Check the API key. Ensure it starts with csk_live_ or csk_test_. Keys are case-sensitive.

MCP server crashes on startup

Check the MCP server logs:

  • Claude Desktop: Open the developer console (Cmd+Option+I on macOS) and look for MCP-related errors.
  • Cursor: Check the Output panel (Cmd+Shift+U) and select "MCP" from the dropdown.

Common causes:

SymptomCauseFix
ENOENT: npx not foundNode.js not in PATHAdd Node.js to your shell PATH or use the full path to npx in the config
INVALID_API_KEYWrong or missing API keyVerify the key in your dashboard at codespar.dev/dashboard/settings
EACCES: permission deniednpm cache permissionsRun sudo chown -R $(whoami) ~/.npm on macOS/Linux
TIMEOUTNetwork issuesCheck your internet connection and verify api.codespar.dev is reachable

Tool calls return errors

If the MCP server is running but tool calls fail:

  1. Check server availability. Not all 57 servers are available in all regions. Use codespar_discover to see which servers are active for your account.
  2. Verify parameters. Tool call errors often come from missing required parameters. Check the tool's inputSchema for required fields.
  3. 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/mcp

Then 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