Agent Integration
Legend Prime gives AI agents native access to DeFi operations — check portfolios, earn yield, swap tokens, transfer assets, and execute transactions — all through a local MCP server, remote MCP server, or CLI.The Agent Journey
Step by step
- Sign up at prime.legend.xyz — create your Prime Account via Google SSO
- Connect the local MCP server (
claude mcp add legend -- legend-cli mcp serve), then runlegend-cli loginto authenticate - Create an account using the
create_accounttool with keygen — it generates a P256 signing key (stored in Secure Enclave on macOS) and creates a sub-account with that key - Use tools — the agent calls MCP tools to read portfolios, create plans, and execute transactions
- Execute in one shot —
plan_and_executecreates, signs, and executes a plan in a single tool call. The key never leaves your machine.
Three Integration Paths
Local MCP Server (recommended for agents)
Thelegend-cli mcp serve command runs a local MCP server via stdio. It exposes the same tools as the remote server, plus local-only tools for signing and one-shot execution. This is the recommended path for agents that need to execute transactions.
| What you get | How it works |
|---|---|
| All tools including signing | plan_and_execute creates, signs, and executes in one call |
| No separate CLI step | Agent never needs to shell out to Bash for signing |
| P256 keys in Secure Enclave | Keys never leave your hardware |
Remote MCP Server (for read-only or shared access)
The remote MCP server athttps://prime-api.legend.xyz/mcp exposes tools that agents call natively. Works with Claude Code, Cursor, OpenAI Responses API, and any MCP-compatible host. Best for read-only operations or when a shared team server is preferred.
| What you get | How it works |
|---|---|
| Native tools in the agent’s palette | get_portfolio, create_earn_plan, list_accounts, etc. |
| Structured JSON in/out | No HTTP, no curl, no parsing |
| OAuth or query key auth | Authenticate once, tools just work |
The remote MCP server does not have access to your local P256 key. To execute plans via the remote server, the agent must separately invoke the CLI via Bash to sign digests. The local MCP server eliminates this extra step.
CLI (for signing + scripting)
Thelegend-cli binary handles key management, signing, and direct API access. Useful for scripting, CI/CD pipelines, and manual operations.
Authentication
| Method | Best for | How |
|---|---|---|
| OAuth (Google SSO) | CLI, Local MCP | legend-cli login — opens browser, saves JWT to profile |
| OAuth (browser flow) | Remote MCP with Claude Code, Cursor | claude mcp add -> /mcp -> Authenticate in browser |
| Query Key | Programmatic agents, CI/CD | Authorization: Bearer qk_... or legend-cli config set query-key qk_... |
Non-Custodial Design
Legend never holds signing keys. The security model:- Reading (portfolios, activities, reference data) — requires only API auth (query key or OAuth JWT)
- Planning (create earn/swap/transfer plans) — same, just API auth. Plans are free previews.
- Executing (moving funds) — requires a cryptographic signature from the account’s P256 key. The agent signs locally via the local MCP server or CLI. Legend verifies the signature but never has access to the key.
MCP Setup
Connect in 2 minutes
MCP Tools
Complete tool reference
CLI Reference
Full CLI command reference
Claude Code Guide
Full walkthrough
OpenAI / OpenClaw
OpenAI Responses API setup