mcp-opcode

mcp-opcode

MCP server for opcode gasless trading API, enabling agents to perform trades, logins, and account operations through a sign-then-submit flow without holding private keys.

Category
访问服务器

README

mcp-opcode

Python SDK for the opcode gasless trading API, and the MCP server built on top of it. It lets an agent, bot or script do what a user does in the opcode app — over plain HTTP, with its own wallet.

Today this repo holds opcode_sdk. The MCP server lands on top of it.

Design

  • Sign-then-submit. The client never holds a private key. Every signed action is two calls: prepare_X(...) returns the exact EIP-712 / EIP-7702 payload(s) to sign, the caller signs them with whatever custody they have, and submit_X(prepared, sig) POSTs the result. OpcodeClient takes no signer.
  • No EVM RPC. Everything needed to build a signature comes off the quote or the session — the authorization nonce and the approve nonce are both carried in the quote descriptor. The SDK never opens a node connection.
  • Trusted values are pinned, not accepted. Chain id, gateway and approve-delegate are checked against client-side constants before anything is signed, so a compromised backend cannot get a signature over an address of its choosing. See TrustedValues.
  • Guards run before the key is touched. A quote that failed the server's safety verdict, is over the effective cap, or no longer has enough of its submit window left is refused at prepare_order() — not after a signature exists.
  • Typed errors. Every wire error kind maps to an exception class chosen for what the caller should do about it, so retry-vs-fatal is a type, not a string match.
  • Sync first. Built on httpx.Client.

Session token rides in the x-opcode-session header, held in memory only.

Install

uv sync

Usage

from opcode_sdk import OpcodeClient, KeystoreSigner, EnvPassword, WalletKind, TrustedValues

client = OpcodeClient("https://app.opcode.fi", chain_id=1)
signer = KeystoreSigner("wallet.json", EnvPassword("OPCODE_KEYSTORE_PASSWORD"))

prep = client.auth.prepare_login(signer.address)
client.auth.submit_login(prep, signer.sign_typed_data(prep.signable))

quote = client.trade.quote(token_in, token_out, amount_in, wallet=WalletKind.embedded)
order = client.trade.prepare_order(quote, trusted=TrustedValues.mainnet())
sigs = {
    k: (signer.sign_authorization(s) if k == "authorization" else signer.sign_typed_data(s))
    for k, s in order.signables.items()
    if s is not None
}
res = client.trade.submit_order(order, sigs)

OpcodeWallet(client, signer) wraps these into one-call flows (login, accept_terms, trade, wait_for_order) and re-logs in automatically on a 401.

Custody

KeystoreSigner reads a standard V3 eth-keystore and is the default. Two things are hooked separately, so you can replace either without the other:

  • PasswordSource — where the password comes from. EnvPassword, FilePassword, PromptPassword, or your own callable.
  • UnlockGate — whether a given signature is allowed to happen at all. AlwaysUnlocked, ConfirmEachSignature, CachedConfirmation, or your own. The gate is handed a SignRequest describing what is about to be signed, and raises UnlockDenied to refuse.

For any other custody (HSM, remote signer, MPC, hardware) implement the Signer protocol — sign_typed_data and sign_authorization — and pass it anywhere a signer is taken. Nothing in the SDK reaches for a key on its own.

An EIP-7702 authorization is called out as its own SignKind: it delegates the EOA's code and is not something a gasless client can undo, so a gate can treat it differently from an ordinary order signature. CachedConfirmation never caches it.

Surfaces

client.auth, .onboarding, .market, .account, .compliance, .explorer, .trade, .feed, .recipients.

Buys, sells and withdrawals all go through the same quote-and-sign path — a withdrawal is a same-token swap to another receiver. Paying an address other than the signer requires that address to be in the recipient book first (client.recipients), and the book's entries are re-verified locally against your own signature rather than trusted as returned.

Membership and terms status are read from GET /api/session; there are no standalone /invite/status, /terms/status or /session_limits endpoints.

tradable_now() answers whether an asset can be traded right now from the catalog entry plus market status. It is a client-side read of side-collapsed data and cannot see a per-side halt; a quote is the only authority.

Tests

uv run pytest

The suite pins the EIP-712 digests, the order meta bit packing, the grant plan, and the tradability gate. It makes no network calls.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选