MCP Tools Reference

This page documents all 14 tools exposed by the Starknet MCP Server (10 core + 4 conditional). Each tool includes its description, parameters, return values, and usage examples.

Tool Invocation

These tools are invoked automatically by your AI assistant. You describe what you want in natural language, and the AI selects the appropriate tool and parameters.

Quick Reference

ToolPurposeWrite?
starknet_get_balanceGet single token balanceNo
starknet_get_balancesGet multiple token balancesNo
starknet_transferTransfer tokensYes
starknet_swapSwap tokens via avnuYes
starknet_get_quoteGet swap quoteNo
starknet_call_contractCall view functionNo
starknet_invoke_contractInvoke contract functionYes
starknet_estimate_feeEstimate transaction feeNo
starknet_build_callsBuild unsigned calls for external signingNo
x402_starknet_sign_payment_requiredSign X-402 paymentNo
starknet_register_agentRegister ERC-8004 identityYes
starknet_set_agent_metadataSet agent metadataYes
starknet_get_agent_metadataRead agent metadataNo
starknet_deploy_agent_accountDeploy agent accountYes

starknet_get_balance

Get the token balance for an address on Starknet. Supports common token symbols (ETH, STRK, USDC, USDT) or any token contract address.

Parameters

ParameterTypeRequiredDescription
tokenstringYesToken symbol (ETH, STRK, USDC, USDT) or contract address
addressstringNoAddress to check. Defaults to the configured account address

Returns

{
  "balance": "1.5",
  "raw": "1500000000000000000",
  "decimals": 18,
  "tokenAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
}
FieldTypeDescription
balancestringHuman-readable balance (e.g., "1.5")
rawstringRaw balance in smallest unit (wei)
decimalsnumberToken decimal places
tokenAddressstringNormalized token contract address

Examples

Error Codes

ErrorCauseRecovery
INVALID_TOKENToken symbol or address not recognizedUse a valid token symbol or contract address
INVALID_ADDRESSAddress format incorrectEnsure address starts with 0x
RPC_ERRORNetwork communication failedCheck RPC URL and network connectivity

starknet_get_balances

Get multiple token balances in a single optimized call. More efficient than calling starknet_get_balance multiple times.

Parameters

ParameterTypeRequiredDescription
tokensstring[]YesArray of token symbols or addresses (max 200)
addressstringNoAddress to check. Defaults to configured account

Returns

{
  "balances": [
    {
      "token": "ETH",
      "balance": "0.5",
      "raw": "500000000000000000",
      "decimals": 18,
      "tokenAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7"
    },
    {
      "token": "STRK",
      "balance": "1234.56",
      "raw": "1234560000000000000000",
      "decimals": 18,
      "tokenAddress": "0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d"
    }
  ],
  "method": "balance_checker"
}
FieldTypeDescription
balancesarrayArray of balance objects
methodstring"balance_checker" (optimized) or "batch_rpc" (fallback)

The server uses a BalanceChecker contract (0x031ce64a666fbf9a2b1b2ca51c2af60d9a76d3b85e5fbfb9d5a8dbd3fedc9716) to fetch multiple balances in a single RPC call. If the contract is unavailable, it falls back to parallel individual RPC calls.

Examples

Error Codes

ErrorCauseRecovery
TOO_MANY_TOKENSMore than 200 tokens requestedSplit into multiple calls
INVALID_TOKENOne or more tokens not recognizedCheck token symbols/addresses

starknet_transfer

Transfer tokens to another address on Starknet. Supports gasfree mode with two options: sponsored (dApp pays gas) or token-based (pay gas in ERC-20).

Parameters

ParameterTypeRequiredDescription
recipientstringYesRecipient address (must start with 0x)
tokenstringYesToken symbol or contract address
amountstringYesAmount in human-readable format (e.g., "1.5")
gasfreebooleanNoEnable gasfree mode (default: false)
gasTokenstringNoToken to pay gas in (only used when gasfree=true without API key)

Gasfree Modes

Sponsored mode: When AVNU_PAYMASTER_API_KEY is set, the dApp pays all gas fees.

Token mode: Without an API key, gas is paid in the specified gasToken (or the token being transferred).

Returns

{
  "success": true,
  "transactionHash": "0x7f3a2bc1...",
  "recipient": "0x04f3e8d17b41...",
  "token": "USDC",
  "amount": "100",
  "gasfree": false
}
FieldTypeDescription
successbooleanWhether the transaction succeeded
transactionHashstringTransaction hash on Starknet
recipientstringRecipient address
tokenstringToken transferred
amountstringAmount transferred
gasfreebooleanWhether gasfree mode was used

Examples

Error Codes

ErrorCauseRecovery
INSUFFICIENT_BALANCENot enough tokens to transferCheck balance and reduce amount
INSUFFICIENT_GASNot enough tokens for gas feesAdd gas token or enable gasfree
INVALID_RECIPIENTRecipient address invalidVerify the address format
TRANSACTION_REVERTEDOn-chain execution failedCheck recipient can receive tokens

Double-check addresses

Token transfers are irreversible. Always verify the recipient address before confirming a transfer.


starknet_swap

Execute a token swap on Starknet using the avnu aggregator for best prices across all DEXes. Supports gasfree mode.

Parameters

ParameterTypeRequiredDescription
sellTokenstringYesToken to sell (symbol or address)
buyTokenstringYesToken to buy (symbol or address)
amountstringYesAmount to sell in human-readable format
slippagenumberNoMax slippage as decimal (0.01 = 1%, default: 0.01)
gasfreebooleanNoEnable gasfree mode (default: false)
gasTokenstringNoToken to pay gas in (gasfree only, defaults to sellToken)

Returns

{
  "success": true,
  "transactionHash": "0x2bc1a7f3...",
  "sellToken": "USDC",
  "buyToken": "ETH",
  "sellAmount": "100",
  "buyAmount": "0.0284",
  "priceImpact": "0.12",
  "gasFeesUsd": "0.05",
  "gasfree": false,
  "routes": [
    {
      "name": "JediSwap",
      "percent": 100
    }
  ]
}
FieldTypeDescription
successbooleanWhether the swap succeeded
transactionHashstringTransaction hash
sellTokenstringToken sold
buyTokenstringToken received
sellAmountstringAmount sold
buyAmountstringAmount received
priceImpactstringPrice impact percentage
gasFeesUsdstringGas fees in USD
gasfreebooleanWhether gasfree mode was used
routesarrayDEX routing information

Examples

Error Codes

ErrorCauseRecovery
NO_ROUTES_FOUNDNo DEX path between tokensTry different token pair or smaller amount
INSUFFICIENT_LIQUIDITYNot enough liquidity for swap sizeReduce swap amount
SLIPPAGE_EXCEEDEDPrice moved beyond slippage toleranceIncrease slippage or retry
INSUFFICIENT_BALANCENot enough sell tokenCheck balance
PRICE_IMPACT_TOO_HIGHSwap would cause significant price impactReduce amount or split into multiple swaps

starknet_get_quote

Get a swap quote without executing the trade. Useful for comparing prices or displaying expected outcomes before confirmation.

Parameters

ParameterTypeRequiredDescription
sellTokenstringYesToken to sell (symbol or address)
buyTokenstringYesToken to buy (symbol or address)
amountstringYesAmount to sell

Returns

{
  "sellToken": "USDC",
  "buyToken": "ETH",
  "sellAmount": "100",
  "buyAmount": "0.0284",
  "priceImpact": "0.12",
  "gasFeesUsd": "0.05",
  "quoteId": "abc123...",
  "routes": [
    {
      "name": "JediSwap",
      "address": "0x...",
      "percent": 60
    },
    {
      "name": "10KSwap",
      "address": "0x...",
      "percent": 40
    }
  ]
}
FieldTypeDescription
sellTokenstringToken being sold
buyTokenstringToken being bought
sellAmountstringInput amount
buyAmountstringExpected output amount
priceImpactstringPrice impact percentage
gasFeesUsdstringEstimated gas fees in USD
quoteIdstringQuote identifier (for reference)
routesarrayDEX routing breakdown

Examples

Error Codes

ErrorCauseRecovery
NO_ROUTES_FOUNDNo DEX path availableTry different tokens
INVALID_TOKENToken not recognizedUse valid symbol or address

starknet_call_contract

Call a read-only (view) function on a Starknet smart contract. Does not create a transaction or cost gas.

Parameters

ParameterTypeRequiredDescription
contractAddressstringYesContract address (0x-prefixed hex)
entrypointstringYesFunction name to call
calldatastring[]NoFunction arguments as strings (default: [], max 256 items)

Input Validation

  • Each calldata item is validated as a 251-bit felt (field element)
  • Decimal values are automatically converted to 0x-prefixed hex
  • Contract addresses are normalized and validated

Returns

{
  "result": ["0x4574686572", "0x455448"],
  "contractAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
  "entrypoint": "name"
}
FieldTypeDescription
resultstring[]Array of return values as hex strings
contractAddressstringContract that was called
entrypointstringFunction that was called

Examples

Error Codes

ErrorCauseRecovery
ENTRYPOINT_NOT_FOUNDFunction doesn't existCheck function name spelling
INVALID_CALLDATAWrong number or type of argumentsVerify function signature
CALLDATA_TOO_LARGEMore than 256 calldata itemsSplit into multiple calls
INVALID_FELTCalldata value exceeds 251 bitsUse smaller values or split uint256
CONTRACT_NOT_FOUNDNo contract at addressVerify contract address

starknet_invoke_contract

Execute a state-changing function on a Starknet smart contract. Creates a transaction that modifies blockchain state.

Parameters

ParameterTypeRequiredDescription
contractAddressstringYesContract address (0x-prefixed hex)
entrypointstringYesFunction name to call
calldatastring[]NoFunction arguments as strings (default: [], max 256 items)
gasfreebooleanNoEnable gasfree mode (default: false)
gasTokenstringNoToken to pay gas in (gasfree only)

Input Validation

  • Each calldata item is validated as a 251-bit felt (field element)
  • Decimal values are automatically converted to 0x-prefixed hex
  • Contract addresses are normalized and validated

Returns

{
  "success": true,
  "transactionHash": "0x3a7c1b2d...",
  "contractAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
  "entrypoint": "approve",
  "gasfree": false
}
FieldTypeDescription
successbooleanWhether the transaction succeeded
transactionHashstringTransaction hash
contractAddressstringContract that was invoked
entrypointstringFunction that was called
gasfreebooleanWhether gasfree mode was used

Examples

Error Codes

ErrorCauseRecovery
TRANSACTION_REVERTEDContract execution failedCheck function requirements
INSUFFICIENT_GASNot enough for gas feesAdd gas tokens or use gasfree
ENTRYPOINT_NOT_FOUNDFunction doesn't existVerify function name
INVALID_CALLDATAWrong argumentsCheck function signature

State Changes

Unlike starknet_call_contract, this tool modifies blockchain state. Ensure you understand what the function does before invoking.


starknet_estimate_fee

Estimate the transaction fee for a contract call before executing it.

Parameters

ParameterTypeRequiredDescription
contractAddressstringYesContract address
entrypointstringYesFunction name
calldatastring[]NoFunction arguments (default: [])

Returns

{
  "overallFee": "0.000042",
  "resourceBounds": {
    "l1_gas": {
      "max_amount": "0x1a4",
      "max_price_per_unit": "0x5af3107a4000"
    },
    "l2_gas": {
      "max_amount": "0x0",
      "max_price_per_unit": "0x0"
    }
  },
  "unit": "STRK"
}
FieldTypeDescription
overallFeestringEstimated fee in human-readable format
resourceBoundsobjectL1 and L2 gas bounds
unitstringFee currency (STRK for V3 transactions)

Examples

Error Codes

ErrorCauseRecovery
ESTIMATION_FAILEDTransaction would failCheck function and calldata
INVALID_CALLDATAWrong argumentsVerify function signature

starknet_build_calls

Build unsigned Starknet calls without executing them. Returns validated Call[] objects compatible with starknet.js and external signers like Cartridge Controller, hardware wallets, or multisig contracts.

Parameters

ParameterTypeRequiredDescription
callsobject[]YesArray of call objects (max 256 calls)

Each call object has:

FieldTypeRequiredDescription
contractAddressstringYesContract address (0x-prefixed hex)
entrypointstringYesFunction name to call
calldatastring[]NoFunction arguments as strings (default: [])

No Execution

This tool performs validation only — it does not execute transactions or require gas. Use it to build calls for external signing workflows.

Returns

{
  "calls": [
    {
      "contractAddress": "0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7",
      "entrypoint": "transfer",
      "calldata": ["0x04f3e8d17b41...", "0x5f5e100", "0x0"]
    }
  ],
  "count": 1,
  "validated": true
}
FieldTypeDescription
callsarrayValidated Call[] objects ready for signing
countnumberNumber of calls in the batch
validatedbooleanWhether all calls passed validation

Examples

Error Codes

ErrorCauseRecovery
EMPTY_CALLSEmpty calls array providedProvide at least one call
TOO_MANY_CALLSMore than 256 callsSplit into multiple batches
INVALID_ADDRESSContract address format invalidUse 0x-prefixed hex address
INVALID_ENTRYPOINTEntrypoint name emptyProvide a valid function name
INVALID_FELTCalldata value exceeds 251 bitsUse smaller values or split uint256

x402_starknet_sign_payment_required

Sign a base64-encoded PAYMENT-REQUIRED header containing Starknet typedData. Part of the X-402 payment protocol for AI-to-AI micropayments.

Parameters

ParameterTypeRequiredDescription
paymentRequiredHeaderstringYesBase64-encoded JSON from PAYMENT-REQUIRED HTTP header
rpcUrlstringNoStarknet RPC URL (defaults to env var)
accountAddressstringNoAccount address (defaults to env var)
privateKeystringNoPrivate key (defaults to env var)

Returns

{
  "paymentSignatureHeader": "eyJzaWduYXR1cmUiOiIweDEyMzQ...",
  "payload": {
    "version": "1",
    "network": "starknet-mainnet",
    "amount": "1000000",
    "token": "0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a8",
    "recipient": "0x04f3..."
  }
}
FieldTypeDescription
paymentSignatureHeaderstringBase64-encoded signature for PAYMENT-SIGNATURE header
payloadobjectDecoded payment request details

Examples

Error Codes

ErrorCauseRecovery
INVALID_HEADERMalformed base64 or JSONCheck header encoding
UNSUPPORTED_NETWORKNetwork not StarknetVerify payment request
SIGNATURE_FAILEDSigning operation failedCheck private key

X-402 Protocol

X-402 enables HTTP-based micropayments where servers return 402 Payment Required responses. The client signs and returns a PAYMENT-SIGNATURE header to authorize payment.


starknet_register_agent

Register a new ERC-8004 agent identity in the IdentityRegistry. This is a conditional tool that only appears when ERC8004_IDENTITY_REGISTRY_ADDRESS is configured.

Conditional Tool

This tool requires the ERC8004_IDENTITY_REGISTRY_ADDRESS environment variable to be set. If not configured, the tool is not exposed.

Parameters

ParameterTypeRequiredDescription
token_uristringNoMetadata URI (IPFS, Arweave, data URI). If omitted, registers without metadata
gasfreebooleanNoEnable sponsored gasfree mode (default: false)

Returns

{
  "success": true,
  "transactionHash": "0x7f3a2bc1...",
  "identityRegistryAddress": "0x05e4f6a7b8c9d0...",
  "agentId": "42"
}
FieldTypeDescription
successbooleanWhether the registration succeeded
transactionHashstringTransaction hash
identityRegistryAddressstringIdentityRegistry address used
agentIdstringERC-8004 agent ID (identity NFT token ID)

Examples

Error Codes

ErrorCauseRecovery
REGISTRY_NOT_CONFIGUREDERC8004_IDENTITY_REGISTRY_ADDRESS not setConfigure the environment variable
REGISTRATION_FAILEDRegistry transaction revertedCheck deployer has sufficient funds
EVENT_NOT_FOUNDRegistered event missingCheck transaction on explorer

starknet_set_agent_metadata

Set on-chain metadata for an ERC-8004 agent identity. This is a conditional tool that only appears when ERC8004_IDENTITY_REGISTRY_ADDRESS is configured.

Conditional Tool

This tool requires the ERC8004_IDENTITY_REGISTRY_ADDRESS environment variable to be set. If not configured, the tool is not exposed.

Parameters

ParameterTypeRequiredDescription
agent_idstringYesAgent ID (u256 as decimal or hex string)
keystringYesMetadata key (non-empty string)
valuestringYesMetadata value (any string)
gasfreebooleanNoEnable sponsored gasfree mode (default: false)

Standard Metadata Keys

The ERC-8004 spec defines these standard keys:

  • agentName - Human-readable agent name
  • agentType - Agent type/category
  • version - Agent version string
  • model - AI model identifier
  • status - Operational status
  • framework - Agent framework used
  • capabilities - JSON array of capabilities
  • a2aEndpoint - Agent-to-Agent protocol endpoint
  • moltbookId - MoltBook identifier

The key agentWallet is reserved and cannot be set via this tool.

Returns

{
  "success": true,
  "transactionHash": "0x7f3a2bc1...",
  "identityRegistryAddress": "0x05e4f6a7b8c9d0...",
  "agentId": "42",
  "key": "agentName",
  "value": "Trading Bot Alpha"
}
FieldTypeDescription
successbooleanWhether the transaction succeeded
transactionHashstringTransaction hash
identityRegistryAddressstringIdentityRegistry address used
agentIdstringAgent ID that was updated
keystringMetadata key that was set
valuestringValue that was stored

Examples

Error Codes

ErrorCauseRecovery
REGISTRY_NOT_CONFIGUREDERC8004_IDENTITY_REGISTRY_ADDRESS not setConfigure the environment variable
EMPTY_KEYKey is empty stringProvide a non-empty key
RESERVED_KEYAttempted to set agentWalletUse a different key (agentWallet is system-managed)
NOT_OWNERCaller is not owner/approved for agent_idUse the owner account or get approval
TRANSACTION_REVERTEDContract execution failedCheck agent_id exists and you have permission

starknet_get_agent_metadata

Read on-chain metadata for an ERC-8004 agent identity. This is a read-only operation that does not create a transaction.

Conditional Tool

This tool requires the ERC8004_IDENTITY_REGISTRY_ADDRESS environment variable to be set. If not configured, the tool is not exposed.

Parameters

ParameterTypeRequiredDescription
agent_idstringYesAgent ID (u256 as decimal or hex string)
keystringYesMetadata key to read (non-empty string)

Returns

{
  "agentId": "42",
  "key": "agentName",
  "value": "Trading Bot Alpha",
  "identityRegistryAddress": "0x05e4f6a7b8c9d0..."
}
FieldTypeDescription
agentIdstringAgent ID queried
keystringMetadata key requested
valuestringDecoded value (empty string if not set)
identityRegistryAddressstringIdentityRegistry address used

Examples

Error Codes

ErrorCauseRecovery
REGISTRY_NOT_CONFIGUREDERC8004_IDENTITY_REGISTRY_ADDRESS not setConfigure the environment variable
EMPTY_KEYKey is empty stringProvide a non-empty key
RPC_ERRORNetwork communication failedCheck RPC URL and connectivity

starknet_deploy_agent_account

Deploy a new agent account via the AgentAccountFactory with ERC-8004 identity binding. This is a conditional tool that only appears when AGENT_ACCOUNT_FACTORY_ADDRESS is configured.

Conditional Tool

This tool requires the AGENT_ACCOUNT_FACTORY_ADDRESS environment variable to be set. If not configured, the tool is not exposed.

Parameters

ParameterTypeRequiredDescription
public_keystringYesStark public key (felt, 0x-prefixed, non-zero, max 251 bits)
token_uristringYesToken URI for agent identity metadata (IPFS, Arweave, etc.)
saltstringNoDeploy salt (felt, max 251 bits). Random if omitted for deterministic addresses
gasfreebooleanNoEnable sponsored gasfree mode (default: false)

Input Validation

  • public_key must be a non-zero value within the 251-bit felt range
  • salt must also fit within 251 bits if provided
  • Random salts are securely generated when not specified

Returns

{
  "success": true,
  "transactionHash": "0x7f3a2bc1...",
  "factoryAddress": "0x358301e1c530a6...",
  "publicKey": "0x04a7b3c8d9e1f2...",
  "salt": "0x1234567890abcdef...",
  "deployedAccountAddress": "0x05e4f6a7b8c9d0...",
  "agentId": "42"
}
FieldTypeDescription
successbooleanWhether the deployment succeeded
transactionHashstringTransaction hash
factoryAddressstringAgentAccountFactory address used
publicKeystringPublic key of the deployed account
saltstringSalt used for address derivation
deployedAccountAddressstringAddress of the new agent account
agentIdstringERC-8004 agent ID (identity NFT token ID)

Examples

Error Codes

ErrorCauseRecovery
FACTORY_NOT_CONFIGUREDAGENT_ACCOUNT_FACTORY_ADDRESS not setConfigure the environment variable
INVALID_PUBLIC_KEYPublic key format invalidUse 0x-prefixed hex felt
DEPLOYMENT_FAILEDFactory transaction revertedCheck deployer has sufficient funds
EVENT_NOT_FOUNDAccountDeployed event missingCheck transaction on explorer

Token Addresses

The MCP server recognizes these token symbols:

SymbolAddressDecimals
ETH0x049d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc718
STRK0x04718f5a0fc34cc1af16a1cdee98ffb20c31f5cd61d6ab07201858f4287c938d18
USDC0x053c91253bc9682c04929ca02ed00b3e423f6710d2ee7e0d5ebb06f3ecf368a86
USDT0x068f5c6a61780768455de69077e07e89787839bf8166decfbf92b645209c0fb86

Additional tokens are resolved dynamically via the avnu token list with 24-hour caching.


Error Handling

All tools return structured errors with:

{
  "error": "INSUFFICIENT_BALANCE",
  "message": "Not enough USDC to complete transfer. Required: 100, Available: 50",
  "suggestion": "Check your balance and try a smaller amount"
}
FieldDescription
errorError code for programmatic handling
messageHuman-readable description
suggestionRecovery action when available

Common error patterns are translated to user-friendly messages with actionable guidance.