crypto_mcp
Provides cryptocurrency market data (prices, symbols) and a gated demo trading flow via MCP tools, with safety defaults like dry-run and confirmation gates.
README
crypto_mcp
crypto_mcp is a refactor of crypto_bot into a single MCP-first repository.
Python requirement: >=3.11.
For user-facing capability map, see: docs/CAPABILITIES.MD.
What this project does
- Expose deterministic MCP tools over stdio.
- Keep transport contract stable for LLM clients.
- Separate market data (safe/read-only) from trading (gated).
- Keep exchange adapters replaceable.
Architecture
src/crypto_mcp/mcp_server.py: FastMCP server and tool definitions.src/crypto_mcp/agent.py: NL command router mapping prompts to MCP tools.src/crypto_mcp/config.py: Typed settings loader with sane defaults and clamps.src/crypto_mcp/adapters/binance.py: Binance HTTP adapter abstraction.src/crypto_mcp/main.py: Runnable MCP entrypoint.tests/: MCP contract, core server, and agent unit tests.
Detailed architecture: docs/ARCHITECTURE.MD.
Capabilities quick table
| Area | What it does | Main MCP tools |
|---|---|---|
| Runtime health | Reports service state, limits, mode, exchanges | health |
| Exchange inventory | Lists adapter-backed exchanges | list_exchanges |
| Market data | Fetches ticker prices and symbol lists | get_price, list_exchange_symbols |
| Guarded execution | Submits demo orders with explicit confirmation gate | submit_demo_order, confirm_pending_order |
| NL routing | Maps natural language to MCP tool calls | crypto-mcp-agent |
Design pattern references taken from polymarket_mcp:
- deterministic tool envelope:
{ok, tool, ...} - bounded limits for list/read tools
- safety confirmation flow for trade tools
- split entrypoint (
main.py) from MCP server implementation
Quickstart
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
cp .env.example .env
python -m pytest
crypto-mcp-server
# separate terminal
crypto-mcp-agent
Setup path-style variant:
cd /path/to/crypto_mcp
python -m venv .venv
source .venv/bin/activate
pip install -e ".[dev]"
cp .env.example .env
Alternative module runner:
python -m crypto_mcp.main
crypto-mcp
Safety defaults
DRY_RUN=true
Default path is non-live demo execution.
Run MCP server locally
Stdio server (local MCP clients):
crypto-mcp-server
For MCP Inspector debugging:
npx @modelcontextprotocol/inspector python -m crypto_mcp.main
Do not write print() logs inside stdio server paths. Use logging to stderr.
Available MCP tools:
healthlist_exchangesget_pricelist_exchange_symbolssubmit_demo_orderconfirm_pending_order
Tool response envelope is consistent:
ok: booleantool: tool nameerror+error_categoryon failures- tool-specific payload under
payload
MCP limits are controlled by:
MCP_DEFAULT_LIMITMCP_MAX_LIMITMCP_CONTEXT_MODE(sharedorrequest)
Order safety controls are controlled by:
DRY_RUNREQUIRE_CONFIRMATION_ABOVE_USD
Connect this MCP to clients
Use path placeholders:
path/to/crypto_mcp= repository root.path/to/crypto_mcp/.venv/bin/python= project interpreter.
GitHub Copilot (VS Code Agent Mode)
Add MCP server config in your VS Code MCP settings JSON:
{
"mcpServers": {
"crypto-mcp": {
"command": "python",
"args": ["-m", "crypto_mcp.main"],
"cwd": "path/to/crypto_mcp",
"env": {
"PYTHONPATH": "src"
}
}
}
}
If your environment requires venv binary, use:
{
"command": "path/to/crypto_mcp/.venv/bin/python",
"args": ["-m", "crypto_mcp.main"]
}
Claude Desktop
Edit Claude Desktop MCP config and add:
{
"mcpServers": {
"crypto-mcp": {
"command": "path/to/crypto_mcp/.venv/bin/python",
"args": ["-m", "crypto_mcp.main"],
"cwd": "path/to/crypto_mcp",
"env": {
"PYTHONPATH": "src"
}
}
}
}
Restart Claude Desktop after changes.
OpenCode
OpenCode can run MCP from command config. Add server entry in your OpenCode MCP configuration:
{
"mcpServers": {
"crypto-mcp": {
"command": "path/to/crypto_mcp/.venv/bin/python",
"args": ["-m", "crypto_mcp.main"],
"cwd": "path/to/crypto_mcp",
"env": {
"PYTHONPATH": "src"
}
}
}
}
Then restart OpenCode session and verify tools:
healthlist_exchangesget_pricelist_exchange_symbolssubmit_demo_orderconfirm_pending_order
OpenCode install and usage:
# install OpenCode (example)
npm install -g opencode-ai
# verify installation
opencode --version
# start session in this repository
cd path/to/crypto_mcp
opencode
Inside OpenCode:
- ensure MCP server
crypto-mcpis connected. - run a quick tool check with
health. - ask natural language command examples:
- "get btcusdt price"
- "list 20 symbols"
- "buy 50 btcusdt"
Environment
Copy .env.example to .env and update values.
MCP_DEFAULT_LIMIT,MCP_MAX_LIMITMCP_CONTEXT_MODE(sharedorrequest)DRY_RUN(true/false)EXCHANGES_ENABLED(binancedefault)GEMINI_API_KEY(optional, used by local NL routing layer)BINANCE_API_BASE_URLBINANCE_API_KEY,BINANCE_API_SECRETREQUIRE_CONFIRMATION_ABOVE_USD
For this task, an empty .env file exists and is safe because defaults are clamped.
What this MCP can do
Read-only tools:
health: service status, context mode, limits, enabled exchanges.list_exchanges: list adapter-backed exchanges.get_price: fetch ticker price for symbol/exchange.list_exchange_symbols: bounded symbol list with clamp.
Trading flow tools (safety-gated):
submit_demo_order: validates side/symbol/size and creates pending confirmation above threshold.confirm_pending_order: executes pending order if valid and not expired.
Order confirmation flow:
- Call
submit_demo_order. - If payload has
status=pending_confirmation, captureconfirmation_id. - Call
confirm_pending_order(confirmation_id).
Contract:
- deterministic response envelope:
{ok, tool, payload}on success. - deterministic error envelope:
{ok, tool, error, error_category}on failure. - live trading intentionally disabled: returns
live_trading_not_implementedwhenDRY_RUN=false.
Safety Notes
submit_demo_ordernever executes live orders; withDRY_RUN=falseit returnslive_trading_not_implemented.submit_demo_orderrequires explicit confirmation for large notional.- response shape never raises raw exceptions to MCP caller; errors are categorized.
Tests
python -m pytest
Important notes
- Local MCP stdio transport must keep stdout clean JSON-RPC only.
- This project is starter infrastructure. Not trading advice.
- Add stronger risk modules before real funds.
Known improvement areas (scan summary)
- Add adapter-level symbol tradability validation before order acceptance.
- Replace broad internal exception mapping with sanitized provider error codes.
- Add confirmation-expiry regression tests at MCP wrapper level.
- Add optional HTTP transport runner for remote clients.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。