@clawdefi/mcp-server
v0.0.103
Published
Internal MCP-facing gateway service that translates tool-style calls into `clawdefi-core` API requests.
Readme
ClawDeFi MCP Gateway
Internal MCP-facing gateway service that translates tool-style calls into clawdefi-core API requests.
Current Mode
- Runs as an internal HTTP gateway for tool calls.
- Keeps MCP auth token checks (
x-mcp-token) at gateway boundary. - Uses service token (
x-service-token) when callingclawdefi-core. - Derives a stable internal
x-agent-idserver-side from caller IP for core rate-limit isolation. x-agent-idis never accepted from MCP clients directly.- Emits per-tool analytics events to core internal ingestion API.
- Exposes health and readiness endpoints for orchestration.
Available Tool Endpoints
Implemented:
POST /tools/get_protocol_profilePOST /tools/list_protocolsPOST /tools/query_chain_registryPOST /tools/evaluate_riskPOST /tools/get_action_specPOST /tools/get_integration_endpointPOST /tools/build_unwind_planPOST /tools/list_providers_by_categoryPOST /tools/simulate_transactionPOST /tools/create_wallet(supports signer import flows;walletAddress=auto|generate|generated|newcreates a key-backed wallet inside signer boundary; plugin boundary rejects rawprivateKeyinputs and only forwards sanitized payloads)POST /tools/list_walletsPOST /tools/rotate_wallet_secretPOST /tools/get_policyPOST /tools/update_policyPOST /tools/sign_intentPOST /tools/perps_fetch_open_positions(adapter-backed read path;protocolSlug=avantisimplemented)POST /tools/perps_fetch_pending_orders(adapter-backed read path;protocolSlug=avantisimplemented)POST /tools/perps_fetch_market_state(adapter-backed read path;protocolSlug=avantisimplemented)POST /tools/perps_build_open_order(canonical unsigned intent builder; can auto-hydratetransactionRequestvia core action-spec tx-builder endpoint)POST /tools/perps_build_close_order(canonical unsigned intent builder; can auto-hydratetransactionRequestvia core action-spec tx-builder endpoint)POST /tools/perps_build_cancel_order(canonical unsigned intent builder; can auto-hydratetransactionRequestvia core action-spec tx-builder endpoint)POST /tools/perps_set_risk_orders(canonical unsigned intent builder; can auto-hydratetransactionRequestvia core action-spec tx-builder endpoint)POST /tools/perps_simulate_intent(intent validation + optional risk/market checks; emitssimulationToken)POST /tools/perps_execute_intent(requiressimulationToken; enforces signer-runtime signing path before submit)POST /tools/subscribe_alertsPOST /tools/poll_alert_eventsPOST /tools/close_alert_subscription
MVP Limitations
subscribe_alertsis poll-mode MVP. WebSocket/SSE transport is not shipped yet.build_unwind_planis position-aware only when a matching wallet-scoped position snapshot exists in core.- If no snapshot is available, unwind planning degrades to curated fallback with explicit warnings.
Required Environment
CORE_API_BASE_URLINTERNAL_SERVICE_TOKENMCP_AUTH_TOKENMCP_TRUST_PROXY(0by default; set to trusted proxy CIDRs/hops if MCP is behind a reverse proxy)MCP_ANALYTICS_ENABLED(trueby default; setfalsein integration tests to avoid external analytics noise)MCP_CONTRACT_STRICT(trueby default; strict envelope mode)SIGNER_RUNTIME_BASE_URL(defaulthttp://127.0.0.1:8091)SIGNER_RUNTIME_MODE(httpfor the intended local signer-runtime path;embeddedallowed for local/test)SIGNER_RUNTIME_AUTH_TOKEN(dedicated auth token for MCP -> signer-runtime calls)AVANTIS_CORE_API_BASE_URL(defaulthttps://core.avantisfi.com)AVANTIS_SOCKET_API_URL(defaulthttps://socket-api-pub.avantisfi.com/socket-api/v1/data)AVANTIS_TIMEOUT_MS(default10000)PERPS_SIMULATION_TTL_MS(default300000; required simulate→execute artifact window)PERPS_SIGNED_ONLY_FALLBACK_ENABLED(defaultfalse; production open/close execute is fail-closed withouttransactionRequestunless this explicit override istrue)SIGNER_KEYSTORE_BACKEND(file_encrypteddefault;memoryonly for local/test)SIGNER_MASTER_KEY(32-byte base64/hex master key for encrypted keystore at rest)SIGNER_MASTER_KEY_NEXT(optional next master key used for rotation workflow)SIGNER_KEYSTORE_DIR(encrypted secret file directory)SIGNER_STATE_PATH(persisted signer runtime metadata/policy state)SIGNER_WALLETS_JSON_PATH(default./state/wallets.json; signer-runtime projection file for multi-wallet public metadata)SIGNER_AUDIT_LOG_PATH(default./state/signer-audit.jsonl; durable JSONL audit log for policy updates/sign attempts/keystore events)
Security Notes
- Keep this service private by default.
- Do not expose MCP gateway publicly without additional controls (allowlist, mTLS, WAF).
- Signing is mediated via dedicated signer-runtime service boundary.
- Use a dedicated
SIGNER_RUNTIME_AUTH_TOKEN(do not reuseINTERNAL_SERVICE_TOKEN). - Keep signer seed material in signer-runtime only (
MCP_SIGNER_SEED), not MCP. - Use encrypted keystore backend in non-test deployments (
SIGNER_KEYSTORE_BACKEND=file_encrypted) and rotateSIGNER_MASTER_KEYoperationally. - If deployed behind a proxy, set
MCP_TRUST_PROXYcorrectly or per-client IP-derived rate-limit identity may collapse to proxy IP.
Perps Preflight / Release-Gate Runbook
- Detailed checklist:
docs/perps-preflight-runbook.md - Automated preflight script:
scripts/perps-preflight.sh
Example:
MCP_URL="http://127.0.0.1:8090" \
MCP_TOKEN="${MCP_AUTH_TOKEN}" \
PROTOCOL_SLUG="avantis" \
CHAIN_SLUG="base-mainnet" \
bash scripts/perps-preflight.shThe preflight checks:
- MCP health/readiness
- broadcast chain/rpc availability
- action-spec seed coverage for open/close/cancel/set-risk
- tx-builder hydration on
perps_build_open_order - simulate artifact issuance (
simulationToken)
