MCP Server Setup

The Starknet MCP Server enables AI assistants to interact with Starknet through the Model Context Protocol (MCP). Once configured, your AI can check balances, execute swaps, transfer tokens, and call smart contracts.

What is MCP?

Model Context Protocol (MCP) is an open standard developed by Anthropic that allows AI assistants to connect to external data sources and tools. Instead of the AI generating code that you run manually, MCP lets the AI execute operations directly.

Traditional Approach:

You: "Transfer 10 USDC to 0x123..."
AI: "Here's the code to do that: ..."
You: *copy, paste, run code manually*

With MCP:

You: "Transfer 10 USDC to 0x123..."
AI: *executes starknet_transfer tool*
AI: "Done! Transaction hash: 0xabc..."

Why Starknet + MCP?

Starknet's native account abstraction makes it ideal for AI agent operations:

FeatureBenefit
Account AbstractionEvery account is a smart contract with custom validation logic
Session KeysTemporary keys with spending limits and time bounds
Paymaster SupportGas fees paid in any token, or sponsored entirely
Low FeesExecute complex operations affordably
V3 TransactionsModern transaction format with STRK fee payments

Architecture

+-------------------------------------------------------------+
|                      AI Assistant                           |
|            (Claude, Cursor, ChatGPT, etc.)                  |
+-----------------------------+-------------------------------+
                              | MCP Protocol (stdio)
                              v
+-------------------------------------------------------------+
|                   Starknet MCP Server                       |
|                                                             |
|   +-------------+  +-------------+  +-------------+         |
|   |   Balance   |  |  Transfer   |  |    Swap     |         |
|   |    Tools    |  |    Tool     |  |    Tools    |         |
|   +------+------+  +------+------+  +------+------+         |
|          |                |                |                |
|   +------+----------------+----------------+------+         |
|   |            Token Service (caching)            |         |
|   +------------------------+----------------------+         |
+----------------------------|--------------------------------+
                             |
            +----------------+----------------+
            |                |                |
            v                v                v
      +----------+     +----------+     +----------+
      | Starknet |     |   avnu   |     | Balance  |
      |   RPC    |     |   API    |     | Checker  |
      +----------+     +----------+     +----------+

Prerequisites

Before configuring any AI client, you need:

  1. Node.js 18+ - Download
  2. A Starknet Account - With private key access
  3. RPC Endpoint - From Alchemy, Infura, or Blast
  4. The MCP Server Built - See installation below

Installation

Clone the repository

git clone https://github.com/keep-starknet-strange/starknet-agentic.git
cd starknet-agentic

Install dependencies

pnpm install

Build the MCP server

pnpm build

The built server will be at packages/starknet-mcp-server/dist/index.js.

Note the absolute path

You'll need the full path to the server for configuration:

# Get the absolute path
echo "$(pwd)/packages/starknet-mcp-server/dist/index.js"

Configuration

Choose your AI assistant below:

Claude Desktop

Config Location

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Windows: %APPDATA%\Claude\claude_desktop_config.json

Linux: ~/.config/Claude/claude_desktop_config.json

Create or edit the config file:

{
  "mcpServers": {
    "starknet": {
      "command": "node",
      "args": ["/absolute/path/to/starknet-agentic/packages/starknet-mcp-server/dist/index.js"],
      "env": {
        "STARKNET_RPC_URL": "https://starknet-sepolia.g.alchemy.com/v2/YOUR_API_KEY",
        "STARKNET_ACCOUNT_ADDRESS": "0x0123456789abcdef...",
        "STARKNET_PRIVATE_KEY": "0x..."
      }
    }
  }
}

Security

The private key is stored in plaintext. For production, consider using environment variables or a secrets manager.

Restart Claude Desktop after saving the config. You should see "starknet" appear in the MCP servers list.

Claude Code (CLI)

Claude Code reads MCP configuration from .mcp.json in your project or home directory.

Config Location

Project-level: .mcp.json in your project root

Global: ~/.mcp.json in your home directory

Create .mcp.json:

{
  "mcpServers": {
    "starknet": {
      "command": "node",
      "args": ["/absolute/path/to/starknet-agentic/packages/starknet-mcp-server/dist/index.js"],
      "env": {
        "STARKNET_RPC_URL": "https://starknet-sepolia.g.alchemy.com/v2/YOUR_API_KEY",
        "STARKNET_ACCOUNT_ADDRESS": "0x0123456789abcdef...",
        "STARKNET_PRIVATE_KEY": "0x..."
      }
    }
  }
}

The server connects automatically when Claude Code starts. Verify with:

claude /mcp

Cursor

Cursor supports MCP through its settings.

Open Cursor Settings

Press Cmd+, (macOS) or Ctrl+, (Windows/Linux), then search for "MCP".

Add MCP Server

In the MCP configuration section, add:

{
  "starknet": {
    "command": "node",
    "args": ["/absolute/path/to/starknet-agentic/packages/starknet-mcp-server/dist/index.js"],
    "env": {
      "STARKNET_RPC_URL": "https://starknet-sepolia.g.alchemy.com/v2/YOUR_API_KEY",
      "STARKNET_ACCOUNT_ADDRESS": "0x...",
      "STARKNET_PRIVATE_KEY": "0x..."
    }
  }
}

Restart Cursor

Restart the editor to load the MCP server.

ChatGPT Desktop

ChatGPT desktop app now natively supports MCP. OpenAI adopted MCP in March 2025 and integrated it across their products.

Native MCP Support

ChatGPT desktop has built-in MCP support. See the OpenAI MCP documentation for configuration instructions.

VS Code with Continue

Continue is an open-source AI code assistant that supports MCP.

Edit ~/.continue/config.json:

{
  "mcpServers": [
    {
      "name": "starknet",
      "command": "node",
      "args": ["/absolute/path/to/starknet-agentic/packages/starknet-mcp-server/dist/index.js"],
      "env": {
        "STARKNET_RPC_URL": "https://starknet-sepolia.g.alchemy.com/v2/YOUR_API_KEY",
        "STARKNET_ACCOUNT_ADDRESS": "0x...",
        "STARKNET_PRIVATE_KEY": "0x..."
      }
    }
  ]
}

Environment Variables

VariableRequiredDescription
STARKNET_RPC_URLYesStarknet JSON-RPC endpoint
STARKNET_ACCOUNT_ADDRESSYesYour Starknet account address
STARKNET_PRIVATE_KEYYesPrivate key for signing transactions
AVNU_BASE_URLNoavnu API URL (defaults based on network)
AVNU_PAYMASTER_URLNoavnu Paymaster URL for gasfree transactions
AVNU_PAYMASTER_API_KEYNoAPI key for sponsored (fully gasless) transactions
ERC8004_IDENTITY_REGISTRY_ADDRESSNoEnables starknet_register_agent tool
AGENT_ACCOUNT_FACTORY_ADDRESSNoEnables starknet_deploy_agent_account tool

Network Configuration

Mainnet (default):

STARKNET_RPC_URL=https://starknet-mainnet.g.alchemy.com/v2/YOUR_KEY
AVNU_BASE_URL=https://starknet.api.avnu.fi
AVNU_PAYMASTER_URL=https://starknet.paymaster.avnu.fi

Sepolia Testnet:

STARKNET_RPC_URL=https://starknet-sepolia.g.alchemy.com/v2/YOUR_KEY
AVNU_BASE_URL=https://sepolia.api.avnu.fi
AVNU_PAYMASTER_URL=https://sepolia.paymaster.avnu.fi

Gasfree Transactions

The MCP server supports gasfree mode where transaction fees are paid in ERC-20 tokens instead of requiring ETH/STRK for gas.

User-Pays Mode (No API Key)

Without an API key, users pay gas in their chosen token:

"Transfer 10 USDC to 0x123... using gasfree mode"

The server will deduct a small amount of USDC (or specified gasToken) to cover fees.

With AVNU_PAYMASTER_API_KEY, the dApp sponsor pays all gas fees:

"Swap 100 USDC to ETH with gasfree enabled"

The user pays nothing for gas—the API key holder covers the cost.

Verifying the Connection

After configuration, test the connection:

In Claude Desktop/Claude Code:

Check my ETH balance on Starknet

Expected response:

Using starknet_get_balance tool... Your ETH balance is 0.5 ETH (500000000000000000 wei)

In Cursor: Open the AI chat and ask:

What's my STRK balance?

Available Tools

The MCP server exposes 10 core tools plus 4 conditional tools:

ToolDescription
starknet_get_balanceGet single token balance
starknet_get_balancesGet multiple token balances (batch)
starknet_transferTransfer tokens to another address
starknet_swapSwap tokens via avnu aggregator
starknet_get_quoteGet swap quote without executing
starknet_call_contractCall read-only contract function
starknet_invoke_contractExecute state-changing contract function
starknet_estimate_feeEstimate transaction fee
starknet_build_callsBuild unsigned calls for external signing
x402_starknet_sign_payment_requiredSign X-402 payment header
starknet_register_agentRegister ERC-8004 identity (conditional)
starknet_set_agent_metadataSet agent metadata (conditional)
starknet_get_agent_metadataRead agent metadata (conditional)
starknet_deploy_agent_accountDeploy agent account (conditional)

Conditional Tools

The identity and deployment tools require environment variables:

  • starknet_register_agent, starknet_set_agent_metadata, starknet_get_agent_metadata require ERC8004_IDENTITY_REGISTRY_ADDRESS
  • starknet_deploy_agent_account requires AGENT_ACCOUNT_FACTORY_ADDRESS

For complete parameter documentation, see the MCP Tools Reference.

Example Interactions

Troubleshooting

Next Steps