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:
| Feature | Benefit |
|---|---|
| Account Abstraction | Every account is a smart contract with custom validation logic |
| Session Keys | Temporary keys with spending limits and time bounds |
| Paymaster Support | Gas fees paid in any token, or sponsored entirely |
| Low Fees | Execute complex operations affordably |
| V3 Transactions | Modern 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:
- Node.js 18+ - Download
- A Starknet Account - With private key access
- RPC Endpoint - From Alchemy, Infura, or Blast
- The MCP Server Built - See installation below
Installation
Clone the repository
git clone https://github.com/keep-starknet-strange/starknet-agentic.git
cd starknet-agenticInstall dependencies
pnpm installBuild the MCP server
pnpm buildThe 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 /mcpCursor
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
| Variable | Required | Description |
|---|---|---|
STARKNET_RPC_URL | Yes | Starknet JSON-RPC endpoint |
STARKNET_ACCOUNT_ADDRESS | Yes | Your Starknet account address |
STARKNET_PRIVATE_KEY | Yes | Private key for signing transactions |
AVNU_BASE_URL | No | avnu API URL (defaults based on network) |
AVNU_PAYMASTER_URL | No | avnu Paymaster URL for gasfree transactions |
AVNU_PAYMASTER_API_KEY | No | API key for sponsored (fully gasless) transactions |
ERC8004_IDENTITY_REGISTRY_ADDRESS | No | Enables starknet_register_agent tool |
AGENT_ACCOUNT_FACTORY_ADDRESS | No | Enables 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.fiSepolia 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.fiGasfree 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.
Sponsored Mode (With API Key)
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:
| Tool | Description |
|---|---|
starknet_get_balance | Get single token balance |
starknet_get_balances | Get multiple token balances (batch) |
starknet_transfer | Transfer tokens to another address |
starknet_swap | Swap tokens via avnu aggregator |
starknet_get_quote | Get swap quote without executing |
starknet_call_contract | Call read-only contract function |
starknet_invoke_contract | Execute state-changing contract function |
starknet_estimate_fee | Estimate transaction fee |
starknet_build_calls | Build unsigned calls for external signing |
x402_starknet_sign_payment_required | Sign X-402 payment header |
starknet_register_agent | Register ERC-8004 identity (conditional) |
starknet_set_agent_metadata | Set agent metadata (conditional) |
starknet_get_agent_metadata | Read agent metadata (conditional) |
starknet_deploy_agent_account | Deploy agent account (conditional) |
Conditional Tools
The identity and deployment tools require environment variables:
starknet_register_agent,starknet_set_agent_metadata,starknet_get_agent_metadatarequireERC8004_IDENTITY_REGISTRY_ADDRESSstarknet_deploy_agent_accountrequiresAGENT_ACCOUNT_FACTORY_ADDRESS
For complete parameter documentation, see the MCP Tools Reference.
Example Interactions
Troubleshooting
Next Steps
- MCP Tools Reference - Complete tool documentation
- DeFi Operations - Swaps, liquidity, yield strategies
- Agent Identity - Register your agent on-chain with ERC-8004