feat: add MCP server for AI agent integration#21
feat: add MCP server for AI agent integration#21omarespejel wants to merge 37 commits intokeep-starknet-strange:mainfrom
Conversation
Adds `packages/mcp-server` — a Model Context Protocol server that exposes x SDK wallet operations as MCP tools. Any MCP-compatible client (Claude, Cursor, OpenAI Agents SDK, etc.) can now discover and invoke Starknet operations through a standard protocol. 11 tools: get_balance, transfer, execute, deploy_account, enter_pool, add_to_pool, claim_rewards, exit_pool_intent, exit_pool, get_pool_position, estimate_fee. Security: - x_execute disabled by default (opt-in via --enable-execute) - Per-transfer amount cap (--max-transfer, default 1000) - Batch limits (20 transfers, 10 calls) - All addresses validated via x SDK's fromAddress() - Runtime argument validation with zod schemas - Transaction confirmation timeout (2 min) - Only pre-verified token presets accepted - Stdio transport only (no remote exposure) Tested end-to-end against Sepolia (38/38 checks pass): read-only tools return live data, all validation and security gates verified, error paths return structured MCP responses. Co-authored-by: Cursor <cursoragent@cursor.com>
|
Thanks for the MCP server addition — strong direction overall. A few blocking points before merge for independent npm publishing:
If you want, I can open a follow-up PR that implements these with minimal API churn. |
…n, dep fix - Add --enable-write flag: all state-changing tools disabled by default, read-only tools (balance, pool position, estimate fee) always available - Apply --max-amount cap consistently to transfers AND staking operations (enter_pool, add_to_pool, exit_pool_intent), renamed from --max-transfer - Validate --network flag at startup with clear error for invalid values - Move x SDK to devDependencies: tsup bundles it at build time via noExternal, so consumers don't need it at runtime (avoids installing the wrong 'x' package from npm) - Add runtime defense-in-depth: write tools are blocked even if a client calls them by name directly, bypassing tool listing - Add staking config guard: clear error when staking tools called without STARKNET_STAKING_CONTRACT env var - Update README: security model, CLI args table, config examples, checklist Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
(Edited) This comment was mangled by shell quoting; please ignore. See the corrected reply here: #21 (comment) |
|
Addressed all 4 blockers in commit ffd113d:
Can you re-review when you get a chance? |
|
Thanks for the MCP server work — a few concrete suggestions:
Optional tests:
|
This reverts commit 98d8741.
|
Why this mattersCurrent order:
Unknown tool names are not in Suggested fix
Minimal patch directionconst schema = schemas[name as keyof typeof schemas];
if (!schema) {
throw new Error(`Unknown tool: ${name}`);
}
await runRateLimitChecks(name);Regression test idea |
|
Thanks @0xLucqs! corrected that and run a harder testnet test Testnet validation update (Sepolia): I ran a full MCP E2E matrix on Sepolia against this branch using:
Write-paths confirmed working:
Read/validation paths also passed:
State-dependent expected rejections were observed correctly:
So the MCP flow is working in practice on testnet (not only unit/integration gates), including sponsored tx and staking operations |
|
Reviewed against current PR head I found two issues that look real and reproducible:
I intentionally excluded earlier notes that were less certain. |
|
Thanks @0xLucqs ! Applied the feedback and added additional tests and improvements |
Summary
Adds
packages/mcp-server— a Model Context Protocol server that exposes x SDK wallet operations as MCP tools. Any MCP-compatible client (Claude, Cursor, OpenAI Agents SDK, etc.) can now discover and invoke Starknet operations through a standard protocol.This follows the pattern established by Stripe, Coinbase, and Alchemy: the SDK owner ships and maintains the MCP server rather than having agent frameworks wrap the SDK externally.
Tools (11 total)
x_get_balancex_transferx_executex_deploy_accountx_enter_poolx_add_to_poolx_claim_rewardsx_exit_pool_intentx_exit_poolx_get_pool_positionx_estimate_feeSecurity model
x_executedisabled by default — opt-in via--enable-executeflag--max-transfer(default: 1000 tokens)fromAddress()tx.wait()to prevent hangsTesting
End-to-end tested against Sepolia testnet — 38/38 checks pass:
tsc --noEmit)Quick start
Files
packages/mcp-server/src/index.ts— server implementation (879 lines)packages/mcp-server/README.md— docs, security model, examplespackages/mcp-server/package.json— deps:@modelcontextprotocol/sdk,zodpackages/mcp-server/tsup.config.ts— build config (bundles x SDK)packages/mcp-server/tsconfig.json— TypeScript configRelated
Test plan
npm run buildsucceedstsc --noEmit— zero type errorsinitializehandshake returns correct server infotools/listreturns 10 tools (11 with--enable-execute)x_get_balancereturns live balance from Sepolia RPCx_executeblocked without--enable-executeSTARKNET_STAKING_CONTRACTValidation errorMade with Cursor