HUB
Sign inSign up

olkowa/blockchain-pattern-mcp

By olkowa

•Updated 6 days ago

Image
0

192

olkowa/blockchain-pattern-mcp repository overview

⁠Blockchain-Pattern MCP server

An MCP server that provides blockchain design expertise to AI coding agents. Analyzes requirements, selects from 109 built-in patterns, generates concrete blockchain designs with components/API contracts, and evaluates against quality attributes.

⁠What is this?

This Docker image contains a complete MCP (Model Context Protocol) server that brings blockchain design expertise to your AI coding agents. Given a requirements string and a domain, it:

  • Analyzes the problem and selects matching blockchain patterns
  • Generates concrete blockchain designs with components, relationships, API contracts, data models, and event contracts
  • Evaluates designs against quality attributes (security, cost efficiency, scalability, decentralization, composability, liquidity, simplicity, privacy)

⁠Key Features

  • 109 Built-in Patterns: zk-rollup, optimistic-rollup, lock-mint-bridge, concentrated-liquidity, erc4337, flash-loan, timelock, mev-boost, and more
  • Full Design Pipeline: Analyze → Generate → Evaluate → Refine (up to 3 automatic refinement attempts)
  • Quality Attribute Scoring: Rate designs on security, cost efficiency, scalability, decentralization, composability, liquidity, simplicity, and privacy (1-10 scale)
  • Dual Transport Support: Stdio for local agents, StreamableHTTP for remote deployments
  • Extensible: Add custom patterns via JSON files
┌───────────────────────────────────────────────────────────────────┐
│  OpenCode / Claude Code / VS Code / any MCP client                │
│        ────────── HTTP ──────────► :8823/mcp (Path A)             │
│                                 or :8813/mcp (Path B)             │
│                                                                   │
│        ┌──────────────────────────────┐                           │
│        │   blockchain-pattern-mcp     │                           │
│        └───────────────┬──────────────┘                           │
│                        │                                          │
│    ┌───────────────────┼────────────────────┐                     │
│    │ pattern-tei-embed │ pattern-tei-rerank │ ← own copies (A)    │
│    │    :8080 (TEI)    │   :8080 (TEI)      │   or shared infra   │
│    └───────────────────┴────────────────────┘   stack (B)         │
└───────────────────────────────────────────────────────────────────┘

⁠Architecture

This image is the MCP server only. The TEI embedder (Qwen3-Embedding-0.6B) and TEI reranker (gte-reranker-modernbert-base) are separate infrastructure (see pattern-tei-infra project⁠) published as pattern-tei-embed-gpu⁠ and pattern-tei-rerank-gpu⁠.

All three images share the same version tag (latest plus the MCP release, e.g. 1.2.0). Both lanes are published (NVIDIA GPU, sm_61 minimum, CUDA for -gpu; the -cpu pair serves the same models with no GPU needed).

They connect via Docker DNS using the hostnames pattern-tei-embed and pattern-tei-rerank on a shared Docker network.

⁠Tools at a Glance

ToolDescription
analyze_blockchainAnalyse requirements → recommended style, patterns, quality metrics
generate_blockchainGenerate blockchain design from requirements + selected patterns
evaluate_blockchainScore an existing design against quality attributes
design_blockchainFull pipeline (analyse → generate → evaluate → refine, up to 3 attempts). 5–10 min
submit_blockchain_design_jobStart background job, get job_id immediately — for clients with short timeouts
get_blockchain_design_statusPoll job status; returns full design when completed
cancel_blockchain_designCancel a running job (best-effort)
list_blockchain_patternsList all 109 patterns; filter by category and/or domain
get_blockchain_patternGet full JSON for a specific pattern

Example call:

Call design_blockchain with:
  requirements: "Constant-product AMM with TWAP oracle and reentrancy guards"
  domain: "defi-trading"

⁠Prompts (Slash Commands)

PromptArgsWhat it does
/design_blockchain_workflowrequirements*Full analyze → generate → evaluate pipeline
/explore_pattern_catalogdomain, categoryLive catalog discovery
/evaluate_my_blockchainfocusGuide evaluation criteria + prioritisation
/compare_blockchain_stylesstyle_a*, style_b*, requirements*Two designs side-by-side (~2× token cost)

* = required

Tool-only clients (no native prompts/list) reach the same four workflows via the generated list_prompts and get_prompt tools.

⁠Prerequisites

  • A clone of the repo — compose files and config template ship with it (test -f docker/docker-compose.yml)
  • Docker with compose plugin ≥ v2.20 (docker compose version), Docker group membership, ≥ 18 GB free (MCP ≈ 1 GB, TEI ≈ 14 GB)
  • A generator LLM API key — defaults to Muse Spark 1.3 Contributor via the OpenCode Go gateway (OPENCODE_API_KEY); any LiteLLM-compatible provider works (OpenAI, Anthropic, DeepSeek, Ollama, vLLM, OpenRouter, …)
  • GPU lane: NVIDIA GPU with sm_61 minimum + Container Toolkit in CDI mode (/var/run/cdi/nvidia.yaml); otherwise pull the published -cpu TEI pair (see the CPU note under Quick start)
  • Images are linux/amd64 only; on arm64 build locally with make docker-build-all
  • GHCR mirrors exist but are not anonymously pullable — use Docker Hub

⁠Long-running Tools & Timeouts

design_blockchain runs multi-stage LLM pipelines that can take 5–10 minutes — the generator LLM processes large input payloads across 9+ round trips.

⁠The Timeout Problem

MCP clients implement client-side idle timeouts (typically 30–120 s). If no data is received, the client aborts — even though the server is still working correctly.

ClientTimeoutNotes
Claude Desktop (TS-SDK)60 sHardcoded; does not reset on progress
Cursor (TS-SDK)60 sSame as Claude Desktop
Claude Code~300 sHeartbeat every 30 s resets idle timer
OpenCode~300 sHeartbeat every 30 s resets idle timer
Codex CLI~300 sHeartbeat every 30 s resets idle timer
⁠Solutions
  1. Heartbeat defence (default) — The server emits progress notifications every 30 s (TASKS_HEARTBEAT_INTERVAL_SECONDS), resetting idle timers for most HTTP clients. TS-SDK clients do not reset on progress — use the job trio.

  2. Async job trio — For timeout-constrained clients (Claude Desktop, Cursor), use submit_blockchain_design_job + get_blockchain_design_status + cancel_blockchain_design. Returns a job_id immediately; poll every 10–30 s. Jobs persist in SQLite (BLOCKCHAIN_PATTERN_JOBS_DB).

  3. FastMCP client demo — make client-analyze drives the server through the FastMCP client with no client-side idle timeout.

⁠Quick start

Two paths (full runbook: INSTALL.md⁠). Pick exactly one — both can run concurrently (distinct container names and ports).

Path A — Compose stackPath B — systemd stack
Use whenevaluating / developing; no sudopersistent host service, starts at boot
Host port88238813
TEI sidecarsown copies in the compose projectshared pattern-tei-infra stack
Survives rebootnoyes
# 0. Clone (compose files + config template ship with the repo)
git clone https://github.com/olk/blockchain-pattern-mcp.git && cd blockchain-pattern-mcp

# A1. Resolve the release version and pull. All three images share the MCP
#     version tag (verified on the Hub: latest + 1.2.0); fall back to latest
#     when the version tag is not published yet.
VERSION=$(grep -m 1 '^version' pyproject.toml | sed -E 's/.*"([^"]+)".*/\1/')
PULL_TAG="${VERSION}"
for img in olkowa/blockchain-pattern-mcp olkowa/pattern-tei-embed-gpu olkowa/pattern-tei-rerank-gpu; do
  docker pull "${img}:${PULL_TAG}" || PULL_FAILED=1
done
if [ "${PULL_FAILED:-0}" = 1 ]; then PULL_TAG="latest"
  for img in olkowa/blockchain-pattern-mcp olkowa/pattern-tei-embed-gpu olkowa/pattern-tei-rerank-gpu; do
    docker pull "${img}:${PULL_TAG}" || { echo "no Hub tag; build locally: make docker-build-all"; exit 1; }
  done
fi

# A2. Write the env file next to the compose file (export your real key first —
#     placeholders deploy a stack whose design calls fail with 401).
: "${OPENCODE_API_KEY:?export OPENCODE_API_KEY='sk-...' before running A2}"
cat > docker/.env <<EOF
MCP_IMAGE=olkowa/blockchain-pattern-mcp:${PULL_TAG}
TEI_IMAGE=olkowa/pattern-tei-embed-gpu:${PULL_TAG}
TEI_RERANK_IMAGE=olkowa/pattern-tei-rerank-gpu:${PULL_TAG}
OPENCODE_API_KEY=${OPENCODE_API_KEY}
MCP_HOST_PORT=8823
EOF
chmod 600 docker/.env

# A3. Sanity check: interpolation resolved (expect 3 image: lines).
docker compose --env-file docker/.env -f docker/docker-compose.yml config | grep 'image:'

# A4. Start. TEI sidecars cold-start model weights; first start takes ~2 min.
#     --wait gates on all three healthchecks instead of a blind sleep.
docker compose --env-file docker/.env -f docker/docker-compose.yml up -d --wait --wait-timeout 300

# A5. Confirm all three report "healthy".
docker inspect -f '{{.Name}} {{.State.Health.Status}}' \
  blockchain-pattern-tei-embed-dev blockchain-pattern-tei-rerank-dev blockchain-pattern-mcp-dev

# A6. Probe the MCP endpoint — must print 200.
#     (GET /health is 404 by design; the JSON-RPC initialize POST is the probe.)
curl -s -o /dev/null -w '%{http_code}\n' -X POST "http://localhost:8823/mcp" \
  -H 'Content-Type: application/json' \
  -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"probe","version":"0.0.0"}},"id":1}'

The server starts on streamable-http at http://localhost:8823/mcp. Config is the repo file config/config.json (mounted at /app/config); validate with python3 -m json.tool config/config.json, then restart blockchain-pattern-mcp after editing.

Path B (systemd, :8813, shared TEI infra, sudo required) and uninstall steps: see INSTALL.md⁠ Path B.

CPU-only hosts: pull the published -cpu pair (olkowa/pattern-tei-embed-cpu / olkowa/pattern-tei-rerank-cpu, same tag), set TEI_IMAGE_CPU / TEI_RERANK_IMAGE_CPU in docker/.env, and merge -f docker/docker-compose.cpu.yml into the A3/A4 commands. Same models, shared embedding-index cache.

Standalone stack: Path A starts its own TEI sidecar copies under distinct -dev container names, so it coexists with the shared pattern-tei-infra stack (different names, different ports).

⁠Bringing your own LLM

The default stack uses Muse Spark 1.3 Contributor via the OpenCode Go gateway (GENERATOR_PROVIDER=openai, GENERATOR_MODEL=openai/muse-spark-1.3-contributor, GENERATOR_BASE_URL=https://opencode.ai/zen/go/v1, key from OPENCODE_API_KEY, GENERATOR_SESSION_ID=blockchain-pattern-mcp). To use another LiteLLM provider, edit the GENERATOR_* lines in the compose file and put your key in the env file, then restart:

      - GENERATOR_PROVIDER=openai
      - GENERATOR_MODEL=openai/gpt-4o-mini      # LiteLLM syntax: provider/model
      - GENERATOR_BASE_URL=https://api.openai.com/v1
      - GENERATOR_API_KEY=${OPENAI_API_KEY}
      - GENERATOR_SESSION_ID=                   # gateway-only header; empty = none
Provider.env / compose additions
Muse Spark (default, via OpenCode Go gateway)GENERATOR_PROVIDER=openai · GENERATOR_MODEL=openai/muse-spark-1.3-contributor · GENERATOR_BASE_URL=https://opencode.ai/zen/go/v1 · key via OPENCODE_API_KEY · GENERATOR_SESSION_ID=blockchain-pattern-mcp
OpenAIGENERATOR_PROVIDER=openai · GENERATOR_MODEL=openai/gpt-4o-mini · GENERATOR_BASE_URL=https://api.openai.com/v1 · GENERATOR_API_KEY=sk-...
AnthropicGENERATOR_PROVIDER=anthropic · GENERATOR_MODEL=anthropic/claude-sonnet-4-5 · GENERATOR_API_KEY=sk-ant-...
DeepSeekGENERATOR_PROVIDER=deepseek · GENERATOR_MODEL=deepseek-chat · GENERATOR_BASE_URL=https://api.deepseek.com/v1 · GENERATOR_API_KEY=sk-...
Ollama / vLLM / OpenRouter / any OpenAI-compatibleGENERATOR_BASE_URL=http://host:11434/v1 · GENERATOR_MODEL=... · GENERATOR_API_KEY=...
⁠Generator LLM (LlamaIndex LiteLLM)

The generator LLM is accessed through the LlamaIndex LiteLLM integration (llama-index-llms-litellm⁠). All provider settings therefore follow LiteLLM's model syntax: <provider>/<model> (e.g. openai/gpt-4o-mini, anthropic/claude-sonnet-4-5, openrouter/minimax/minimax-m2).

The server composes the LiteLLM model string as provider + / + model-suffix: if the configured model already contains a provider prefix, that prefix is stripped and replaced by the configured provider:

Config / envExampleResulting LiteLLM model string
provider: "openai", model: "gpt-4o-mini"GENERATOR_PROVIDER=openai, GENERATOR_MODEL=gpt-4o-miniopenai/gpt-4o-mini
provider: "openai", model: "openai/muse-spark-1.3-contributor"GENERATOR_MODEL=openai/muse-spark-1.3-contributoropenai/muse-spark-1.3-contributor
provider: "anthropic", model: "claude-sonnet-4-5"GENERATOR_PROVIDER=anthropic, GENERATOR_MODEL=claude-sonnet-4-5anthropic/claude-sonnet-4-5
provider: "openrouter", model: "minimax/minimax-m2"GENERATOR_PROVIDER=openrouter, GENERATOR_MODEL=minimax/minimax-m2openrouter/minimax/minimax-m2
  • Provider list, model names, and the exact <provider>/<model> syntax: LiteLLM Providers documentation⁠
  • Custom/OpenAI-compatible endpoints (proxies, vLLM, Ollama, …): set GENERATOR_BASE_URL (generator.config.base_url) — it is passed as the LiteLLM api_base
  • GENERATOR_API_KEY is passed as the LiteLLM api_key; temperature, top_p, top_k, and stream map to the corresponding LiteLLM parameters

⁠TEI sidecar configuration

The MCP server reaches the sidecars by Docker DNS (pattern-tei-embed, pattern-tei-rerank) — these match the defaults, so no URL overrides are required in the standard stacks:

VariableDefaultDescription
EMBEDDER_BASE_URLhttp://pattern-tei-embed:8080/v1TEI embedder URL (OpenAI-compatible route)
RERANKER_BASE_URLhttp://pattern-tei-rerank:8080TEI reranker URL (POST /rerank directly, no /v1)

The embedder must be TEI serving the same model — the embedder config has no model field, so openai / ollama / vllm providers cannot address an arbitrary remote model without a code change. The reranker is not a LiteLLM client.

Full env var reference: GitHub README → Configuration⁠

⁠Connect your agent

Point at Path A (:8823) or Path B (:8813) depending on which stack you installed.

⁠OpenCode

Add to ~/.config/opencode/opencode.json:

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "blockchain-pattern": {
      "type": "remote",
      "url": "http://localhost:8823/mcp"
    }
  }
}

Note: GENERATOR_API_KEY is read from the server's config file / environment, not from opencode's environment.

⁠VS Code (MCP extension)

Add to .vscode/mcp.json:

{
  "servers": {
    "blockchain-pattern": {
      "url": "http://localhost:8823/mcp",
      "type": "http"
    }
  }
}
⁠Claude Code / Codex CLI

Stdio transport — this section is for Claude Code / Codex CLI subprocess mode. It requires a local git clone (one-time setup). If you want HTTP transport (recommended for Docker Hub users), use the Quick start above instead.

# Install (one-time)
git clone https://github.com/olk/blockchain-pattern-mcp.git && cd blockchain-pattern-mcp
make install

# Add to your agent (key must match the provider; example: OpenAI)
claude mcp add blockchain-pattern \
  -e GENERATOR_PROVIDER=openai \
  -e GENERATOR_API_KEY=sk-... \
  -- blockchain-pattern-mcp --transport stdio

For the Muse Spark default over stdio, also pass -e GENERATOR_MODEL=openai/muse-spark-1.3-contributor -e GENERATOR_BASE_URL=https://opencode.ai/zen/go/v1 -e GENERATOR_SESSION_ID=blockchain-pattern-mcp.

Full client docs: GitHub README → Connect Your Agent⁠

⁠Try it

Ask your agent (or use the Inspector):

Design a cross-chain token bridge with fraud proofs, rate-limited mints and a light-client verifier for L2 → L1 withdrawals.

This should call design_blockchain with:

  • requirements: "Cross-chain bridge with fraud proofs, rate-limited mints and a light-client verifier for L2 -> L1 withdrawals"
  • domain: "bridge"
  • style: "lock-mint-bridge"

⁠Operations

# Update images (re-resolve the tag first, then pull + restart)
VERSION=$(grep -m 1 '^version' pyproject.toml | sed -E 's/.*"([^"]+)".*/\1/')
docker compose --env-file docker/.env -f docker/docker-compose.yml pull
docker compose --env-file docker/.env -f docker/docker-compose.yml up -d --wait --wait-timeout 300

# View logs
docker compose --env-file docker/.env -f docker/docker-compose.yml logs -f blockchain-pattern-mcp

# Stop (keep the env file — it holds the API key)
docker compose --env-file docker/.env -f docker/docker-compose.yml down

Host ports default via MCP_HOST_PORT (8823 Path A, 8813 Path B) — override it in the env file, then update your client URL. If a port is already bound, find the owner with ss -ltn | grep ':8823 '.

⁠Troubleshooting

SymptomFix
GET /health returns 404Expected — FastMCP streamable-http exposes no GET /health. Probe POST /mcp (Quick start A6).
401 Unauthorized from LLMCheck OPENCODE_API_KEY in docker/.env; verify the key is active and the GENERATOR_* provider block matches it
TEI connection errors / unhealthy sidecarsTEI cold-starts model weights (~2 min, start_period: 120s) — recheck health after ~2 min; verify sidecar containers are running and pattern-tei-embed resolves on the compose network
Port already in usePorts default via MCP_HOST_PORT (8823/8813); check ss -ltn, stop the owner or override the variable
Image pull fails for ${VERSION}Tag not published — the A1 block already retries with latest; list tags at https://hub.docker.com/v2/repositories/olkowa/blockchain-pattern-mcp/tags
Tag summary
Recent tags
Content type
Image
Digest
sha256:f72a2a1fd…
Size
287.8 MB
Last updated
6 days ago
docker pull olkowa/blockchain-pattern-mcp:latest