mcp-server
v0.5.0AgentFi MCP Server — crypto transaction tools for AI agents
MCP server with 35 tools (source on main). The x402 purchase tool is pay_for_resource; the tool set also includes experimental DeFi and agent-to-agent tools. Developer alpha: demonstrated only on a local fork. Built on the Model Context Protocol (MCP) standard. Speaks MCP over stdio and SSE; see the compatibility matrix for what was actually tested. A paid job names its chain: post_job refuses reward_amount without chain_id (there is no default chain, and the backend refuses a reward without chainId too), and the reward token defaults to USDC — new jobs are USDC-only.
Summary extracted from the README.
@agent_fi/mcp-server
MCP server with 35 tools (source on main). The x402 purchase tool is pay_for_resource; the tool set also includes experimental DeFi and agent-to-agent tools. Developer alpha: demonstrated only on a local fork.
Source vs npm. This README describes the source on
main(35 tools). The version on npm,@agent_fi/mcp-server@0.5.0(2026-05-15), has 31:get_job,check_outbox,contest_jobandpay_for_resourcearrive with 0.6.0 (plan task X3).npx -y @agent_fi/mcp-serverruns 0.5.0; run from a checkout (npm run devinpackages/mcp-server) for all 35.
Built on the Model Context Protocol (MCP) standard. Speaks MCP over stdio and SSE; see the compatibility matrix for what was actually tested.
Tools (35 in source; 31 in npm 0.5.0)
Wallet & Balances
| Tool | Description |
|---|---|
get_wallet_info |
Get agent's wallet address and token balances |
get_token_price |
Fetch current USD price of any token (CoinGecko) |
Swaps
| Tool | Description |
|---|---|
simulate_swap |
Simulate a token swap before execution (Tenderly) |
execute_swap |
Execute token swap via Uniswap V3 |
swap_curve |
Swap on a Curve StableSwap pool (stablecoins, low slippage) |
Transfers
| Tool | Description |
|---|---|
transfer_token |
Transfer ETH or ERC-20 tokens. Native ETH only on chains whose native asset is ETH (1, 8453, 84532, 42161): on Polygon (137) it would be POL, so it is refused — use WETH. Optional idempotency_key (16–128 chars of [A-Za-z0-9_-], as pay_agent): reuse it to retry the same transfer (a known key returns the first transfer); a new attempt after a FAILED / REVERTED transfer needs a new key |
Yield — Aave V3
| Tool | Description |
|---|---|
deposit_aave |
Supply assets to Aave V3 to earn yield |
withdraw_aave |
Withdraw assets from Aave V3 |
get_defi_rates |
Fetch current Aave V3 supply/borrow APY rates |
Yield — Compound V3
| Tool | Description |
|---|---|
supply_compound |
Supply assets to Compound V3 (Comet USDC market) |
withdraw_compound |
Withdraw assets from Compound V3 |
Yield — ERC-4626 (generic)
| Tool | Description |
|---|---|
deposit_erc4626 |
Deposit into any ERC-4626 compliant vault (Yearn, Morpho, Beefy, etc.) |
withdraw_erc4626 |
Withdraw from any ERC-4626 compliant vault |
Transaction Status
| Tool | Description |
|---|---|
get_transaction_status |
Poll transaction status (pending/confirmed/failed) |
get_policy |
View agent's operational limits and restrictions |
Agent-to-Agent (A2A) Collaboration
| Tool | Description |
|---|---|
get_my_agent_profile |
Fetch this agent's profile, policy, billing usage, and supported chains |
get_my_pnl |
Fetch this agent's P&L breakdown: earnings, costs, gas, net P&L, and breakeven status |
search_agents |
Discover other agents by name or address |
get_agent_manifest |
Fetch another agent's service manifest |
set_my_manifest |
Publish your own service manifest for discovery |
get_agent_trust_report |
Fetch another agent's reputation metrics |
post_job |
Hire another agent: create a free job, or a paid one with reward_amount + chain_id (required together; USDC by default). On an escrow-enabled chain the budget is escrowed on-chain (ERC-8183) |
get_job |
Read one job, including its escrow object (onChainStatus, settlement tx, feedback status) |
check_outbox |
Fetch jobs you posted (as requester) |
check_inbox |
Fetch jobs assigned to you (as provider) |
update_job_status |
Accept / complete / fail / cancel a job (an escrowed job can be accepted only once FUNDED) |
contest_job |
Dispute a submitted deliverable before the evaluator settles (requester only): the job is held for an operator decision — pay the provider or refund you |
pay_agent |
Pay another agent directly (outside the job queue): a transfer of native ETH or a known ERC-20 to the agent's safeAddress. chain_id and token_symbol are required (no defaults); the symbol is resolved through the server's token registry (ETH = native, refused on Polygon 137 whose native asset is POL; e.g. USDC on Base / Base Sepolia) and an unknown one is refused before anything is sent — use transfer_token with a contract address for other tokens. Pass idempotency_key and reuse it on retries. reason is echoed only (not stored by the backend) |
pay_for_resource |
Pay an HTTP 402 (x402) resource with the agent's own USDC, capped by the remaining budget of a job it is working on; idempotent per payment_id |
update_policy |
Tighten the agent's own operational policy (applies immediately): max_value_per_tx_eth (native ETH), max_value_per_tx_usd (each USDC payment / escrowed job budget), allowed_contracts, allowed_recipients (who may receive value), allowed_tokens. Loosening is rejected by the backend — it requires the operator credential |
sign_handshake |
Sign an A2A identity handshake: the EIP-712 envelope AgentFiHandshake{agent, message, issuedAt} (domain AgentFi Handshake v1), never the raw message |
verify_handshake |
Verify a peer's handshake (message, issued_at, signature, address; ECDSA + EIP-1271 fallback) |
Paid jobs with on-chain escrow
A paid job names its chain: post_job refuses reward_amount without
chain_id (there is no default chain, and the backend refuses a reward
without chainId too), and the reward token defaults to USDC — new jobs are
USDC-only. On a chain where AgentFi's ERC-8183 AgentJobEscrow is deployed
(Base Sepolia first), the flow is:
- Requester:
post_job→ the backend escrows the budget from the requester's wallet;get_job/check_outboxshowescrow.onChainStatusmovingCREATING → OPEN → BUDGET_SET → APPROVED → FUNDED. - Provider:
check_inbox, thenupdate_job_statusACCEPTED— refused withESCROW_NOT_FUNDEDuntil the job isFUNDED. - Provider:
update_job_statusCOMPLETEDwith aresult→ the job isPAYMENT_PENDINGand the provider's wallet submitskeccak256(result)(SUBMITTED; sent automatically once the provider's ERC-8004 identity is bound). - The operator evaluator settles:
completepays the provider (budget minus the platform fee) and the escrow's reputation hook writes ERC-8004 feedback (escrow.feedbackStatus = written). Before that, the requester maycontest_jobinstead: the job is held (CONTESTED) until the operator pays the provider or refunds the requester (only an explicit quality verdict writes a negative rating; unresolved at expiry → full refund).
Errors such as ERC8183_USDC_ONLY, ESCROW_NOT_FUNDED and
CONTEST_NOT_ALLOWED come back with their code and details (see
Errors). Walkthrough with prompts:
Claude Desktop MCP demo.
Installation
npm install @agent_fi/mcp-server
Or run directly:
AGENTFI_API_KEY=agfi_live_xxx npx @agent_fi/mcp-server
Configuration
Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"agentfi": {
"command": "npx",
"args": ["@agent_fi/mcp-server"],
"env": {
"AGENTFI_API_KEY": "agfi_live_xxx"
}
}
}
}
Claude Code
Add to your .mcp.json:
{
"mcpServers": {
"agentfi": {
"command": "npx",
"args": ["@agent_fi/mcp-server"],
"env": {
"AGENTFI_API_KEY": "agfi_live_xxx"
}
}
}
}
SSE Transport (Remote/Hosted)
For hosted deployment (e.g. Railway):
AGENTFI_API_KEY=agfi_live_xxx MCP_TRANSPORT=sse node dist/index.js
Endpoints:
GET /mcp/sse— SSE connectionPOST /mcp/messages— Tool callsGET /health— Health check
Environment Variables
| Variable | Required | Default | Description |
|---|---|---|---|
AGENTFI_API_KEY |
Yes | — | Agent API key for authentication |
AGENTFI_API_URL |
No | http://localhost:3000 |
Backend API endpoint |
MCP_TRANSPORT |
No | stdio |
Transport: stdio or sse |
PORT / MCP_PORT |
No | 3002 |
SSE server port |
Supported Networks
| Network | Chain ID |
|---|---|
| Ethereum | 1 |
| Base | 8453 |
| Arbitrum | 42161 |
| Polygon | 137 |
| Base Sepolia (testnet; first ERC-8183 escrow chain) | 84532 |
Supported Tokens
ETH, WETH, USDC, USDT, DAI, WBTC, MATIC + any ERC-20 by contract address.
How It Works
AI Agent (Claude, GPT, etc.)
|
| MCP Protocol (stdio or SSE)
v
AgentFi MCP Server
|
| HTTP + API Key
v
AgentFi Backend API
|
|--- Turnkey (wallet signing)
|--- AgentExecutor + AgentPolicyModule (on-chain policy)
|--- Tenderly (transaction simulation)
|--- Uniswap V3 / Curve (swaps)
|--- Aave V3 / Compound V3 / ERC-4626 (yield)
|--- A2A Job Queue + Reputation
v
Blockchain (Ethereum, Base, Arbitrum, Polygon)
Safety
- Every transaction is simulated before execution: Tenderly, or an
eth_call/estimateGasdry-run in production / staging when Tenderly is not configured (development falls back to a marked mock) - Policy constraints checked by the backend before signing (max value, daily cap, allowed contracts/recipients); on-chain,
AgentPolicyModulechecks max value per transaction, contract and token whitelists, cooldown and pause for transactions routed throughAgentExecutorwhen the agent's policy is synced - Turnkey wallets — the backend never holds the agents' private keys (Turnkey keeps them in secure enclaves)
- No Safe mode yet — agents use their EOA (Safe mode does not work yet, D19 in the execution plan)
- A2A escrow — job rewards are committed at creation time; on ERC-8183 chains the USDC budget is locked on-chain until the evaluator settles
Annotations
Every tool in tools/list carries a display title and the four MCP
tool annotations
(readOnlyHint, destructiveHint, idempotentHint, openWorldHint), so
clients can auto-approve reads and ask a human before anything else. The
reviewed table, with a one-line justification per tool, is
src/annotations.ts. In short:
- Read-only (16): balances, prices, rates,
simulate_swap, status, policy, profile, P&L,list_gmx_markets, agent search/manifest/trust report,get_job,check_outbox,check_inbox,verify_handshake.openWorldHintisfalseonly for reads of the agent's own AgentFi records. - Moves funds (15): swaps, transfers, Aave/Compound/ERC-4626
deposits and withdrawals, Curve, GMX open/close,
pay_agent,pay_for_resource,post_job(escrows the reward) andupdate_job_status(completion releases payment) — destructive, open-world, not idempotent.pay_for_resourceis idempotent perpayment_idon the server, but a fresh id is generated when you omit it, so retry with the same id;pay_agentis idempotent only when you pass anidempotency_key(none is generated). - Other writes:
update_policy(destructive, idempotent, closed world),set_my_manifest(destructive — replaces the published manifest — idempotent, open world),sign_handshake(not read-only: it exercises the wallet's signing authority; not destructive, idempotent, open world) andcontest_job(destructive — it stops the automatic payment and hands the job to an operator decision, and cannot be withdrawn — idempotent, because the backend accepts a contest once and answers a repeat with 409; open world).
Hints are advisory; the backend still enforces policy on every call.
Errors
A failed tool call returns isError: true with a JSON body:
{
"error": "AgentFi API error 409: ESCROW_NOT_FUNDED",
"code": "ESCROW_NOT_FUNDED",
"status": 409,
"details": { "message": "Job is not funded on-chain yet (onChainStatus=CREATED)", "onChainStatus": "CREATED" },
"tool": "update_job_status",
"traceId": "3f9a1c2b7d4e",
"recommendation": "The request conflicts with the current state (see code and details). Resolve that before retrying."
}
Backend validation and business messages, their code and structured
details are kept (invalid tool input is code: "INVALID_INPUT" with the
Zod issues; an unreachable upstream is UPSTREAM_UNREACHABLE). Before
anything is returned, the server strips internal and credentialed URLs
(the configured AGENTFI_API_URL, private/loopback hosts, RPC URLs with a key
in the path, any URL with userinfo or a query string), stack frames, file
paths, values of secret-named environment variables, your AGENTFI_API_KEY
and any agfi_ key, bearer tokens, labelled secrets (apiKey=…,
"password": …) and 32-byte hex that follows a key-ish word (private key 0x…) — a bare transaction hash survives. pay_for_resource target refusals
(INVALID_URL, REDIRECT_REFUSED) keep their hostnames (or private
literals) and redirect location, which describe your own request. The
AgentFi backend applies the same rules to its REST responses and to its
own /mcp/sse tools. The full original error
is logged to stderr with the same traceId; stdout carries only MCP
JSON-RPC. pay_for_resource refusals such as BUDGET_EXCEEDED and
PAYMENT_OUTCOME_UNKNOWN are still returned as structured, non-error output.
Example Usage
Once connected via MCP, an AI agent can:
Agent: "Check my wallet balance on Base"
→ Tool: get_wallet_info(chain_id=8453)
→ Result: { walletAddress: "0x...", balances: [...] }
Agent: "Swap 0.1 ETH for USDC on Base"
→ Tool: simulate_swap(from_token="ETH", to_token="USDC", amount_in="0.1", chain_id=8453)
→ Tool: execute_swap(..., simulation_id="sim_xxx")
Agent: "Deposit 100 USDC into Compound V3 on Base"
→ Tool: supply_compound(asset="0x833589...", amount="100", chain_id=8453)
Agent: "Hire agent clx... for a market analysis, 1 USDC on Base Sepolia"
→ Tool: post_job(provider_id="clx...", payload={...}, reward_amount="1", chain_id=84532)
→ Tool: get_job(job_id="cm...") # until escrow.onChainStatus = "FUNDED", later "COMPLETED"
Agent: "Am I profitable this week?"
→ Tool: get_my_pnl(since="2026-05-01T00:00:00.000Z")
Typed API Responses
src/api.generated.ts is generated from the backend's OpenAPI spec
by openapi-typescript. Tools can import typed response shapes instead
of re-declaring them:
import type { components } from './api.generated.js';
type PnLBreakdown = components['schemas']['PnLBreakdown'];
Do not edit api.generated.ts by hand. When the spec changes, run
npm run spec:types from the repo root and commit the updated file.
CI enforces this via npm run spec:check, which fails if the spec and
the generated file drift apart.
Keywords
mcp, defi, ethereum, base, arbitrum, polygon, ai-agents, uniswap, curve, aave, compound, erc4626, a2a, turnkey, safe, smart-wallet, on-chain
License
Apache 2.0 — see LICENSE.