mcpField
S
Swap Api

Swap Api

Local
github.com/Swap-APIDeveloper Tools22Updated 30w ago

About Swap Api

Swap Api MCP Server is the MCP server for SwapAPI, providing AI agents with executable token swap transaction data on EVM chains. It targets developers building agents that perform token swaps and, according to its README, requires no API keys.

Key features

  1. 01Returns executable swap transaction calldata
  2. 02Supports EVM networks selected by chain ID
  3. 03Configurable maximum slippage, default 0.5%
  4. 04Returns router address, calldata, value and gas estimate

Use cases

  1. 01AI agents performing token swaps on EVM chains
  2. 02Preparing swap quotes and transaction data before submission
  3. 03Calling swap functions from Claude Desktop or Cursor

MCP support

This is an MCP server that exposes the swap_tokens tool, which returns transaction data for token swaps to MCP clients.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

mcp.json · Universal config
{
"mcpServers": {
"swap-api": {
"command": "npx",
"args": [
"-y",
"@swapapi/mcp"
]
}
}
}
Run commandnpx -y @swapapi/mcp

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
npm@swapapi/mcp0.1.0

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

SwapAPI MCP Server

MCP (Model Context Protocol) server for SwapAPI. Enables AI agents to get executable token swap calldata for any EVM chain.

Installation

npm install -g @swapapi/mcp

Or use directly with npx:

npx @swapapi/mcp

Client Configuration

Claude Desktop

Add to your Claude Desktop config:

{
  "mcpServers": {
    "swapapi": {
      "command": "npx",
      "args": ["@swapapi/mcp"]
    }
  }
}

Or with a local install:

{
  "mcpServers": {
    "swapapi": {
      "command": "npx",
      "args": ["tsx", "/path/to/swap-api/mcp/mcp-server.ts"]
    }
  }
}
Cursor

Add to your Cursor settings (Settings → MCP):

{
  "mcpServers": {
    "swapapi": {
      "command": "npx",
      "args": ["@swapapi/mcp"]
    }
  }
}
Other Clients

Any MCP-compatible client can use the same configuration format. Check your client's documentation for where to add MCP server settings.

Available Tools

swap_tokens

Get executable transaction data to swap tokens on EVM chains.

Parameters:

ParameterTypeRequiredDescription
chainIdnumberYesChain ID (1=Ethereum, 8453=Base, 42161=Arbitrum, etc.)
tokenInstringYesInput token address. Use 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE for native token (ETH, MATIC, etc.)
tokenOutstringYesOutput token address
amountInstringYesAmount in smallest unit (wei for 18-decimal tokens, micro-units for 6-decimal tokens)
senderstringYesWallet address that will sign and send the transaction
maxSlippagenumberNoMax slippage tolerance 0-1 (default: 0.005 = 0.5%)

Returns:

{
  "to": "0x...",           // Router contract address to call
  "data": "0x...",         // ABI-encoded swap calldata
  "value": "1000000000000000000",  // Native token value (if swapping from native)
  "gas": "150000",         // Estimated gas limit
  "guaranteedOut": "..."   // Minimum output amount after slippage
}

Examples

Swap 0.001 ETH to USDC on Base
{
  "chainId": 8453,
  "tokenIn": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
  "tokenOut": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
  "amountIn": "1000000000000000",
  "sender": "0xYourAddress"
}
Swap USDC to ETH on Arbitrum with 1% slippage
{
  "chainId": 42161,
  "tokenIn": "0xaf88d065e77c8cC2239327C5EDb3A432268e5831",
  "tokenOut": "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE",
  "amountIn": "10000000",
  "sender": "0xYourAddress",
  "maxSlippage": 0.01
}

Pre-flight Checklist

Before submitting any swap transaction:

  1. ERC-20 Approval: If tokenIn is not native token, ensure sender has approved the router for at least amountIn
  2. Balance Check: Verify sender has sufficient balance for amountIn (plus value if native token)
  3. Gas Estimation: Call eth_estimateGas on the transaction and add 20% buffer
  4. Simulation: Run eth_call to verify the transaction won't revert
  5. Timing: Submit within 30 seconds of fetching the quote (calldata has expiry)

See the main README.md for full API documentation.

Development

cd mcp
npm install
npm start
Testing

Run the test suite:

npm test

Or use the MCP Inspector:

npx @modelcontextprotocol/inspector tsx mcp-server.ts

License

MIT

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.