crypto-insight-mcp

crypto-insight-mcp

MCP server for accessing crypto market data (prices, portfolio analytics) from CoinGecko and performing RAG-based search over internal documents with responsible-AI guardrails.

Category
访问服务器

README

crypto-insight-mcp

CI License: MIT Python 3.10+

An MCP server that gives AI agents governed access to crypto market data and a company knowledge base — live prices and portfolio analytics from CoinGecko, plus RAG-based semantic search over internal documents (regulation, AML/KYC, custody, listing policy), with responsible-AI guardrails at every boundary.

Why this project

Connecting an LLM to a financial domain is easy to do badly: unvalidated tool inputs, upstream stack traces leaking into model context, retrieved documents silently rewritten into confident "advice". This project demonstrates the architecture I consider correct for the problem:

  • One domain, two transports. All business logic lives in a pure service layer. An MCP server (stdio) exposes it to AI agents; a FastAPI gateway exposes the same functions to humans and systems. Neither transport contains logic, so behaviour and guardrails cannot drift between them.
  • Guardrails as a first-class module. Input validation with LLM-actionable error messages, outbound rate limiting, mandatory not-financial-advice disclaimers on every analytical response, structured {"error": ...} payloads instead of exceptions crossing the protocol boundary.
  • Retrieval, not server-side synthesis. The RAG tool returns chunks with sources; the calling LLM does the reasoning. This division of labour is recorded in ADR-0003.
  • Runs anywhere, no keys. CoinGecko free tier, embedded Chroma, local ONNX embeddings with a deterministic offline fallback. pytest passes with no network at all (ADR-0002).

MCP tools

Tool Arguments Returns
get_price symbols: list[str], vs_currency="usd" Spot price + 24h change per symbol
get_market_history symbol: str, days=30, vs_currency="usd" Daily price points + min/max/change stats
analyze_portfolio holdings: dict[symbol, amount], vs_currency="usd" Total value, per-position allocation %, HHI concentration index, warnings
search_knowledge query: str, k=4 Top-k knowledge-base chunks with source and score

Every analytical response includes a disclaimer field; every invalid input produces {"error": "<what was wrong and what is acceptable>"} rather than a crash.

Architecture

flowchart LR
    subgraph Agents
        claude["Claude Desktop / MCP client"]
    end
    subgraph Humans["Humans & systems"]
        rest["REST clients"]
    end

    claude -- "MCP (stdio)" --> srv["server.py\nFastMCP · 4 tools"]
    rest -- "HTTP" --> api["api.py\nFastAPI gateway"]

    srv --> svc["services.py\ndomain logic"]
    api --> svc
    svc --> guard["guardrails.py\nvalidation · rate limit · disclaimer"]
    svc --> mkt["market/client.py\nTTL cache · token bucket"]
    svc --> kb["rag/search.py\nKnowledgeBase"]
    mkt -- "HTTPS" --> cg["CoinGecko free API"]
    kb --> chroma[("Chroma embedded\n.chroma/")]
    docs["knowledge_base/*.md"] -- "rag/ingest.py" --> chroma

More detail in docs/architecture.md and the ADRs.

Quickstart

Requires Python ≥ 3.10.

git clone https://github.com/IgorAbramov/crypto-insight-mcp.git
cd crypto-insight-mcp
pip install -e ".[dev]"

# Build the knowledge-base index (embedded Chroma, local embeddings).
python -m crypto_insight_mcp.rag.ingest

# Run the offline test suite.
pytest

Connect to Claude Desktop

Add to claude_desktop_config.json (Settings → Developer → Edit Config):

{
  "mcpServers": {
    "crypto-insight": {
      "command": "crypto-insight-mcp",
      "env": {
        "CIM_CHROMA_DIR": "/absolute/path/to/crypto-insight-mcp/.chroma"
      }
    }
  }
}

If crypto-insight-mcp is not on Claude Desktop's PATH, use the absolute path to the script (which crypto-insight-mcp) or "command": "python", "args": ["-m", "crypto_insight_mcp.server"] with the right interpreter. Restart Claude Desktop; then try:

What are BTC and ETH trading at? Then check what our listing policy says about delisting notice periods.

Run the REST gateway

uvicorn crypto_insight_mcp.api:app --reload
# http://127.0.0.1:8000/docs           — OpenAPI UI
# GET  /health
# GET  /prices?symbols=BTC,ETH&vs=usd
# POST /portfolio/analyze              {"holdings": {"BTC": 0.5, "ETH": 10}}
# GET  /knowledge/search?q=custody%20segregation&k=4

Or with Docker:

docker compose up --build api   # ingests on start, serves on :8000

Run the agent demo (human-in-the-loop)

# Offline scripted mode — no LLM, no keys (needs internet for CoinGecko):
python agent_demo/demo.py "0.5 BTC, 10 ETH, 5000 USDT"

# Real tool-use loop through the Anthropic API:
pip install -e ".[agent]"
export ANTHROPIC_API_KEY=...   # see .env.example
python agent_demo/demo.py "0.5 BTC, 10 ETH, 5000 USDT" --llm

The demo walks the agent workflow — prices → portfolio analysis → knowledge-base grounding → draft risk note — and then stops for human approval before "executing" the proposed action (execution is simulated; nothing is ever traded or sent).

Responsible AI & guardrails

  • Input validation at every tool boundary — symbols, query text, day ranges and holdings are validated and normalised; violations return messages that tell the LLM what was wrong and what acceptable values look like, so the agent can self-correct instead of retry-looping.
  • Rate limiting — a thread-safe token bucket in front of CoinGecko keeps a misbehaving agent from hammering a third-party API.
  • Mandatory disclaimers — every analytical payload carries "Informational market data / document retrieval only. This is NOT financial, investment, legal or tax advice." The server's MCP instructions direct clients to surface it.
  • No stack traces in model context — upstream failures map to short, safe MarketDataError messages; tool handlers convert all handled errors to structured {"error": ...} payloads, so the server never crashes on bad input.
  • Human-in-the-loop — the agent demo requires explicit approval before any consequential action; the default answer is "no".
  • Retrieved chunks, not synthesized answers — search_knowledge returns sourced chunks and leaves synthesis to the client LLM (ADR-0003).

Testing

The suite runs fully offline: CoinGecko is mocked with httpx.MockTransport, embeddings use a deterministic hash fallback, Chroma lives in per-test temp directories, and the MCP surface is exercised in-process (mcp.list_tools() / mcp.call_tool()).

pytest        # 64 tests, ~1.5 s
ruff check .  # lint

CI (GitHub Actions) runs lint + tests on every push and pull request with no secrets configured — by design.

Project layout

src/crypto_insight_mcp/
├── server.py        # MCP transport (FastMCP, stdio)
├── api.py           # REST transport (FastAPI)
├── services.py      # domain logic shared by both
├── guardrails.py    # validation, rate limiting, disclaimers
├── market/client.py # CoinGecko client: TTL cache, rate limit
└── rag/             # embeddings (ONNX + offline fallback), ingest, search
knowledge_base/      # sample corpus: MiCA, AML/KYC, custody, listing policy
agent_demo/demo.py   # human-in-the-loop agent scenario (offline + --llm)
docs/                # architecture.md + ADRs
tests/               # offline test suite

Roadmap

  • Pinecone/managed vector-store adapter behind the existing LangChain interface (the embedded-Chroma trade-off is documented in ADR-0002).
  • Kubernetes manifests for the REST gateway.
  • Retrieval evaluation harness (golden questions → recall/precision on the knowledge base) to make RAG quality measurable, not anecdotal.
  • Symbol resolution fallback via CoinGecko /search for long-tail assets.

Author

Igors Abramovs — github.com/IgorAbramov

MIT License — see LICENSE.

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选