HUB
Sign inSign up

olkowa/design-pattern-mcp

By olkowa

•Updated 6 days ago

An MCP server that provides design-pattern selection expertise to AI coding agents.

Image
Machine learning & AI
0

636

olkowa/design-pattern-mcp repository overview

⁠Design-Pattern MCP server

An MCP server that provides design-pattern selection expertise to AI coding agents. Analyzes a free-text system description, retrieves from 486 built-in patterns (each with generic + 13 language bindings), generates a concrete design with participants/interactions/implementation steps, and evaluates it against eight quality axes.

⁠What is this?

This Docker image contains a complete MCP (Model Context Protocol) server that brings design-pattern expertise to your AI coding agents. Given a description string plus optional language / paradigm / focus hints, it:

  • Analyzes the problem into decision parts and recommends pattern categories
  • Retrieves matching patterns via fused dense (TEI) + BM25 retrieval with cross-encoder reranking
  • Generates a concrete design with primary + supporting patterns, participants, interactions, implementation steps, and language-bound code sketches
  • Evaluates the design against quality attributes (testability, extensibility, maintainability, simplicity, performance, reliability, security, scalability)

⁠Key Features

  • 486 Built-in Patterns: Observer, circuit-breaker, process-manager, retry, builder, saga participants, and more — each with generic + 13 language bindings (C, C++, C#, Go, Java, JavaScript, Kotlin, Python, Ruby, Rust, Scala, Swift, TypeScript; 6,804 per-language files)
  • Full Design Pipeline: Analyze → Weights ∥ Retrieval → Generate → Evaluate → Bounded refine (LOOP_MAX_TRIES attempts, default 2)
  • Ch2 Style Seam: a CPU-only style-head sidecar (TF-IDF + calibrated linear head) answers the style decision when confident, else the pipeline falls back to the LLM style
  • Quality Attribute Scoring: Eight design-level axes plus an overall 0–100 score with early-stop threshold (default 50)
  • Dual Transport Support: Stdio for local agents, StreamableHTTP for remote deployments
  • Extensible: Pattern records are joined JSON files under pattern/; alias-aware loader with startup enum-drift guard
┌───────────────────────────────────────────────────────────────────┐
│  OpenCode / Claude Code / VS Code / any MCP client                │
│        ────────── HTTP ──────────► :8822/mcp (A) or :8812/mcp (B) │
│                                                                   │
│        ┌──────────────────────────────┐                           │
│        │     design-pattern-mcp       │                           │
│        └───────────────┬──────────────┘                           │
│                        │                                          │
│    ┌───────────────────┼────────────────────┐                     │
│    │ design-pattern-   │ design-pattern-    │ ← shared infra in   │
│    │ tei-embed :8080   │ tei-rerank :8080   │   Path B, own copies│
│    │      (TEI)        │      (TEI)         │   in Path A         │
│    └───────────────────┴────────────────────┘                     │
│    ┌────────────────────────────────────────┐                     │
│    │ design-pattern-style-head :8800 (CPU)  │ ← ships in both     │
│    └────────────────────────────────────────┘                     │
└───────────────────────────────────────────────────────────────────┘

⁠Architecture

This image is the MCP server only. Retrieval needs two more images from this project:

plus the CPU style head: design-pattern-style-head⁠.

All four images share one version tag (the MCP release, from pyproject.toml). Only the -gpu TEI pair is published — it needs an NVIDIA GPU with sm_61 minimum (sm_60 and below unsupported; sm_61 is the only hardware tested). CPU-only hosts build the -cpu pair locally (make docker-build-tei-cpu); it serves the same models, so the dense cache is shared across lanes.

They connect via Docker DNS using the hostnames design-pattern-tei-embed and design-pattern-tei-rerank on a shared Docker network (Path B joins the shared pattern-tei-infra⁠ stack instead, hostnames pattern-tei-embed / pattern-tei-rerank). Published server images bake in the dense embedding cache, so first start is fast; a locally built cache-less image embeds the whole catalog at first start (~5 min via the GPU sidecar vs ~19 min via the CPU sidecar — full-catalog cache build only).

⁠Tools at a Glance

ToolDescription
select_design_patternsFull pipeline (analyze → weights ∥ retrieval → generate → evaluate → refine). 2–10 min
analyze_designRequirements analysis only: decision-part decomposition, category recommendations (~1 min)
generate_designGenerate a design from explicitly named patterns or a prior analyze_design payload (~1 min)
evaluate_designScore an existing design JSON against the eight quality axes (~30 s)
submit_design_jobStart background job, get job_id immediately — for clients with short timeouts
get_design_statusPoll job status; returns full DesignResult when completed
cancel_designCancel a running job (best-effort, takes effect at next stage boundary)
list_design_patternsList all 486 patterns; filter by category and/or language
get_design_patternGet full JSON for a specific pattern (alias-aware)

Example call:

Call select_design_patterns with:
  description: "IoT ingestion path: Kafka consumer (10k events/sec) → JSON parse → Redis geo-enrich → InfluxDB + S3 sink. At-least-once, backpressure."
  language: "python"

⁠Prompts (Slash Commands)

PromptArgsWhat it does
/select_design_patterns_workflowdescription*, language, architecture_style, paradigm, focusGuided end-to-end selection workflow
/explore_pattern_catalogcategoryLive catalog discovery
/evaluate_my_designdescription*Compare the catalog's selection against an existing design
/compare_pattern_candidatesdecision*, candidates*Two or three named patterns side-by-side (one selection run per candidate)

* = required

Tool-only clients (no native prompts/list) reach the same four workflows via the generated list_prompts / 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 with baked dense cache, TEI ≈ 14 GB)
  • An NVIDIA GPU (sm_61 minimum) for the default -gpu TEI pair; CPU-only hosts build the -cpu pair locally instead (make docker-build-tei-cpu)
  • 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, MiniMax, DeepSeek, Ollama, vLLM, OpenRouter, …)
  • Images are linux/amd64 only; on arm64 build locally with make docker-build-base
  • GHCR mirrors exist but are not anonymously pullable — use Docker Hub

⁠Long-running Tools & Timeouts

select_design_patterns runs a multi-stage LLM pipeline that takes minutes per call (2–10 min) — the generator LLM processes fused retrieval candidates plus per-part quality weights and emits a large strictly-structured JSON document; the design loop repeats generate → evaluate up to LOOP_MAX_TRIES times.

⁠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_design_job + get_design_status + cancel_design. Returns a job_id immediately; poll every 10–30 s. Jobs persist in SQLite (JOBS_DB) and survive server restarts.

  3. Direct HTTP client — make client-analyze / make client-design / make client-async bypass the MCP SDK entirely with no idle timeout (override the target with CLIENT_URL).

⁠Quick start

Two paths (full runbook: INSTALL.md⁠). Pick exactly one — they use fixed distinct host ports (8822 vs 8812), so both stacks can run concurrently.

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

# A1. Resolve the release version and pull. All four images (MCP, TEI pair,
#     style head) carry the same version tag.
VERSION=$(grep -m 1 '^version' pyproject.toml | sed -E 's/.*"([^"]+)".*/\1/')
docker pull "olkowa/design-pattern-mcp:${VERSION}"
docker pull "olkowa/pattern-tei-embed-gpu:${VERSION}"
docker pull "olkowa/pattern-tei-rerank-gpu:${VERSION}"
docker pull "olkowa/design-pattern-style-head:${VERSION}"
# If a pull 404s (tag not published), list tags and use latest:
#   curl -fsS 'https://hub.docker.com/v2/repositories/olkowa/design-pattern-mcp/tags'

# A2. Write the env file next to the compose file
cat > docker/.env <<EOF
MCP_IMAGE=olkowa/design-pattern-mcp:${VERSION}
TEI_IMAGE=olkowa/pattern-tei-embed-gpu:${VERSION}
TEI_RERANK_IMAGE=olkowa/pattern-tei-rerank-gpu:${VERSION}
STYLE_HEAD_IMAGE=olkowa/design-pattern-style-head:${VERSION}
OPENCODE_API_KEY=sk-REPLACE-ME
EOF

# A3. Start. TEI sidecars cold-start model weights; first start takes ~2 min.
#     (Published server images bake in the dense embedding cache; a locally
#     built cache-less image instead embeds the whole catalog at first start,
#     ~5 min via the GPU sidecar vs ~19 min via the CPU sidecar.)
docker compose --env-file docker/.env -f docker/docker-compose.yml up -d

# A4. Wait until all three report "healthy" (poll if still "starting").
docker inspect -f '{{.Name}} {{.State.Health.Status}}' \
  design-pattern-tei-embed-dev design-pattern-tei-rerank-dev design-pattern-mcp-dev

# A5. Probe the MCP endpoint — must print 200.
#     (GET /health is 404 by design; the JSON-RPC initialize POST is the probe.
#      The MCP image has no curl binary; probe from the host.)
curl -s -o /dev/null -w '%{http_code}\n' -X POST "http://localhost:8822/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:8822/mcp. Config is the repo file config/config.json (mounted at /app/config); restart the server container after editing.

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

Standalone stack: Path A starts its own TEI sidecar copies. If you already run the shared pattern-tei-infra stack, you can alternatively drop the two sidecar services and point EMBEDDER_BASE_URL / RERANKER_BASE_URL at the existing sidecars instead (or start with --profile offline for deterministic lexical-only retrieval with no sidecars).

CPU-only hosts: build the -cpu TEI pair (make docker-build-tei-cpu) and append -f docker/docker-compose.cpu.yml to the compose commands above (or run make docker-up-cpu) — same models, shared dense cache.

⁠Bringing your own LLM

The default stack uses Muse Spark 1.3 Contributor via the OpenCode Go gateway (GENERATOR_PROVIDER=opencode-go, 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=design-pattern-mcp sent as x-opencode-session). 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}
Provider.env / compose additions
Muse Spark (default, OpenCode gateway)GENERATOR_PROVIDER=opencode-go · GENERATOR_MODEL=openai/muse-spark-1.3-contributor · GENERATOR_BASE_URL=https://opencode.ai/zen/go/v1 · GENERATOR_SESSION_ID=design-pattern-mcp · key via OPENCODE_API_KEY
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-...
MiniMaxGENERATOR_PROVIDER=minimax · GENERATOR_MODEL=minimax/MiniMax-M2.7 · GENERATOR_BASE_URL=https://api.minimax.io/v1 · GENERATOR_API_KEY=...
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 provider prefix lives in the model string (LiteLLM convention) while GENERATOR_PROVIDER labels error messages.

  • Provider list, model names, and the exact <provider>/<model> syntax: LiteLLM Providers documentation⁠
  • Custom/OpenAI-compatible endpoints (proxies, vLLM, Ollama, …): set GENERATOR_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 timeout_seconds map to the corresponding LiteLLM parameters

⁠Sidecar configuration

The MCP server reaches the sidecars by Docker DNS — these match the defaults, so no URL overrides are required in the standard stacks (Path B uses the pattern-tei-* hostnames of the shared infra stack):

VariableDefault (Path A)Description
EMBEDDER_BASE_URLhttp://design-pattern-tei-embed:8080TEI embedder URL (dev compose uses the /v1 OpenAI-compatible route)
RERANKER_BASE_URLhttp://design-pattern-tei-rerank:8080TEI reranker URL (POST /rerank directly, no /v1)
DECISIONS_STYLE_BASE_URLhttp://design-pattern-style-head:8800/v1Style-head URL (Ch2 seam; CPU sidecar)

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. Keep RETRIEVAL_MAX_CONCURRENT_PARTS=1 (shipped default) — one full-text rerank request already saturates the CPU sidecar's token buffer (HTTP 429 otherwise).

The Ch2 style seam is on by default in Path B and opt-in in Path A (DECISIONS_STYLE_ENABLED=true in the env file); if the sidecar is unreachable the seam degrades to the LLM style. Confidence floor: DECISIONS_STYLE_CONFIDENCE_FLOOR=0.6.

Upgrading from an older release? The DESIGN_PATTERN_ env prefix was removed — strip it from every key (DESIGN_PATTERN_GENERATOR_API_KEY → GENERATOR_API_KEY, …) and reinstall config/config.json in the same step.

Full env var reference: GitHub README → Configuration⁠

⁠Connect your agent

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

⁠OpenCode

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

{
  "$schema": "https://opencode.ai/config.json",
  "mcp": {
    "design-patterns": {
      "type": "remote",
      "url": "http://localhost:8822/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": {
    "design-patterns": {
      "url": "http://localhost:8822/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/design-pattern-mcp.git && cd design-pattern-mcp
make install

# Add to your agent
claude mcp add design-patterns \
  -e GENERATOR_PROVIDER=opencode-go \
  -e GENERATOR_MODEL=openai/muse-spark-1.3-contributor \
  -e GENERATOR_BASE_URL=https://opencode.ai/zen/go/v1 \
  -e GENERATOR_API_KEY=sk-... \
  -e GENERATOR_SESSION_ID=design-pattern-mcp \
  -- design-pattern-mcp --transport stdio

Stdio mode needs the TEI endpoints reachable (defaults http://design-pattern-tei-embed:8080 and the reranker URL from config/config.json) — either run the compose stack's sidecars or set EMBEDDER_BASE_URL / RERANKER_BASE_URL to your own. For a no-network smoke run, start with --offline (deterministic lexical-only retrieval instead of TEI).

Full client docs: GitHub README → Connect Your Agent⁠

⁠Try it

Ask your agent (or use the Inspector):

Build the cache-miss path of a geolocation enricher: look up keys in Redis, fall back to an external geo API on miss, protect the fallback with a circuit breaker and retry. Python.

This should call select_design_patterns with:

  • description: "cache-aside enrichment with Redis fallback, circuit-breaker + retry on the miss path"
  • language: "python"

Expect a circuit-breaker + retry design with participants, implementation_steps, and a Python code_sketch bound to the catalog variant. Sibling workflow: run the architecture-pattern-mcp⁠ server first for the system shape (pipe-and-filter ETL: Kafka source → parser filter → enricher → InfluxDB/S3 sinks), then bring each component's internals here.

⁠Operations

# Update images (re-resolve VERSION first, then pull + restart)
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

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

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

On Linux with a shared host, restrict your env file:

chmod 600 docker/.env

⁠Troubleshooting

SymptomFix
GET /health returns 404Expected — FastMCP streamable-http exposes no GET /health. Probe POST /mcp (Quick start A5).
401 Unauthorized from LLM, or every LLM call returns ERR_009Check the API key in docker/.env; verify the key is active and the GENERATOR_* provider block matches it. An env file from an older release still uses the removed DESIGN_PATTERN_ prefix — strip it from every key.
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 design-pattern-tei-embed resolves on the compose network
MCP unhealthy for many minutes; logs show dense-cache re-embedCache-less image embeds the whole catalog at first start (~5 min via GPU, ~19 min via CPU) — wait, or rebuild with make docker-build (bakes the cache)
Reranker HTTP 429 "Model is overloaded"One full-text rerank request saturates the CPU sidecar's token buffer — keep RETRIEVAL_MAX_CONCURRENT_PARTS=1 (shipped default)
Tool calls rejected for ~60 s after 3 transport failuresCircuit breaker open (GENERATOR_CIRCUIT_BREAKER_* knobs) — check the provider key/endpoint, then wait out the cooldown
Image pull fails for ${VERSION}Tag not published; list tags at https://hub.docker.com/v2/repositories/olkowa/design-pattern-mcp/tags and use latest
Tag summary
Recent tags
Content type
Image
Digest
sha256:5202235a8…
Size
283.8 MB
Last updated
6 days ago
docker pull olkowa/design-pattern-mcp:latest