Skip to main content
Glama
Design Patterns MCP Server

Design Patterns MCP Server

by apolosan

设计模式 MCP 服务器

版本 许可证:MIT 测试状态 模式 为以下构建 TypeScript

一个智能 MCP(模型上下文协议)服务器,使用混合搜索(语义 + 关键词 + 图增强)提供设计模式推荐。通过自然语言界面访问 710 种设计模式,涵盖 90 多个类别,采用先进的混合 RAG 架构。

快速开始

# Clone and setup
git clone https://github.com/apolosan/design_patterns_mcp.git
cd design_patterns_mcp

# Install dependencies and build (using bun)
bun install
bun run db:setup

# Or using npm (if bun is not installed)
npm install --ignore-scripts
npx tsc
node dist/cli/migrate.js
node dist/cli/seed.js
node dist/cli/generate-embeddings.js
node dist/cli/setup-relationships.js

在您的 MCP 客户端(Claude Desktop、Cursor 等)中进行配置,即可通过自然语言查询开始发现模式。

Related MCP server: Acemcp

工具与构建卫生

  • 使用 Bun 作为本仓库的规范包管理器(仅 bun install)。锁文件为 bun.lock。

  • 切勿将 .git 目录复制到 dist/data 中(或将其打包进 dist/)。该路径必须保持为纯数据目录,以避免产生数 GB 级的镜像和元数据泄漏。

功能特性

功能

描述

混合搜索引擎

结合语义、关键词(BM25)和图增强的混合 RAG 检索

710 种模式

涵盖 90 多个类别的综合模式目录,包括功能开关 / 功能切换,用于渐进式交付和实验

MCP 集成

与 Claude、Cursor 及其他 MCP 客户端无缝集成

多级缓存

L1 内存缓存 + L3 SQLite 缓存,命中率 95% 以上

事件总线系统

通过发布/订阅实现解耦的服务通信

遥测与健康检查

实时性能指标与系统监控

SOLID 架构

遵循最佳实践的干净、可维护代码库

生产就绪

77 个测试文件中的 654 个测试用例,100% 通过率(0 失败,0 跳过)

可用模式类别

类别

数量

示例

经典 GoF 模式

34

工厂、建造者、观察者、策略、命令

架构模式

56

MVC、整洁架构、六边形架构、DDD、功能开关

微服务与云

39

断路器、Saga 事务、服务网格

数据工程

54

仓库模式、CQRS、事件溯源

AI/ML 与 MLOps

46

RAG、微调、模型压缩

React 模式

27

Hooks、服务端组件、性能优化

区块链与 Web3

115

DeFi、NFT、智能合约、MEV

并发与响应式

45

生产者-消费者、Actor 模型

安全

21

OAuth、RBAC、零信任

函数式编程

26

单子、函子、高阶函数

架构

src/
├── adapters/              # External service adapters (LLM, embeddings)
├── cli/                   # CLI commands (migrate, seed, embeddings, setup-relationships)
├── core/                  # DI Container, configuration builder
├── db/                    # Database migrations
├── events/                # Event bus system
├── handlers/              # MCP request handlers (hybrid search, recommendations)
├── health/                # Health check services
├── repositories/          # Data access layer
├── search/                # Hybrid search engine
├── services/              # Business services (cache, telemetry, pattern service)
├── strategies/            # Strategy pattern implementations
├── types/                 # TypeScript type definitions
└── mcp-server.ts          # MCP server entry point

data/
├── patterns/              # 710 JSON pattern definitions (see `feature-flag.json`)
└── design-patterns.db     # SQLite database with 710 patterns and embeddings

用法

查找模式

通过您的 MCP 客户端使用自然语言提问:

"I need to create complex objects with many optional configurations"
→ Builder, Abstract Factory, Factory Method

"How to handle service failures gracefully in distributed systems?"
→ Circuit Breaker, Bulkhead, Retry, Fallback

"What pattern helps with state-dependent behavior in React?"
→ State Machine, Observer, useReducer

"How to implement secure authentication and authorization?"
→ OAuth 2.0, RBAC, JWT, Zero Trust

MCP 工具

工具

描述

find_patterns

使用问题描述进行混合搜索查找模式

search_patterns

带过滤条件的关键词或语义搜索

get_pattern_details

获取包含代码示例的完整模式信息

count_patterns

可用模式的统计信息

get_health_status

系统健康与服务状态

安装

前置要求

  • Node.js >= 18.0.0

  • Bun >= 1.0.0(推荐)或 npm >= 8.0.0

使用 Bun 安装

bun install
bun run build
bun run db:setup

使用 npm 安装

package.json 中的 prepare 脚本需要 bun。如果您未安装 bun,请使用 --ignore-scripts 跳过该脚本并手动构建:

npm install --ignore-scripts
npx tsc

# Setup database
node dist/cli/migrate.js
node dist/cli/seed.js
node dist/cli/generate-embeddings.js
node dist/cli/setup-relationships.js

MCP 配置

在您的 MCP 客户端配置中添加(Claude Desktop、Cursor 等):

{
  "mcpServers": {
    "design-patterns": {
      "command": "node",
      "args": ["/absolute/path/to/design-patterns-mcp/dist/mcp-server.js"],
      "env": {
        "LOG_LEVEL": "info",
        "DATABASE_PATH": "/absolute/path/to/design-patterns-mcp/data/design-patterns.db",
        "ENABLE_HYBRID_SEARCH": "true",
        "ENABLE_GRAPH_AUGMENTATION": "true",
        "EMBEDDING_COMPRESSION": "true",
        "ENABLE_FUZZY_LOGIC": "true",
        "ENABLE_TELEMETRY": "true",
        "ENABLE_MULTI_LEVEL_CACHE": "true"
      }
    }
  }
}

重要提示: 请为 args 和 DATABASE_PATH 使用绝对路径。像 Cursor 这样的 MCP 客户端不能可靠地支持 cwd 字段,因此相对路径会相对于用户的主目录解析,而不是项目目录。有关客户端特定的配置示例,请参阅项目快速入门指南。

环境变量

变量

默认值

描述

LOG_LEVEL

info

日志级别(debug、info、warn、error)

DATABASE_PATH

./data/design-patterns.db

SQLite 数据库路径

ENABLE_HYBRID_SEARCH

true

启用混合 RAG 搜索

ENABLE_GRAPH_AUGMENTATION

true

启用模式关系图遍历增强

EMBEDDING_COMPRESSION

true

启用维度缩减

ENABLE_FUZZY_LOGIC

true

启用模糊逻辑结果优化

ENABLE_TELEMETRY

true

启用性能指标收集

ENABLE_MULTI_LEVEL_CACHE

true

启用 L1 + L3 多级缓存

MAX_CONCURRENT_REQUESTS

10

最大并发请求数

CACHE_MAX_SIZE

1000

缓存大小上限

CACHE_TTL

3600000

缓存生存时间(毫秒)

TRANSPORT_MODE

stdio

传输模式(stdio/http)

HTTP_PORT

3000

HTTP 端口(HTTP 模式)

MCP_ENDPOINT

/mcp

MCP 端点路径

HEALTH_CHECK_PATH

/health

健康检查路径

SKIP_DB_SETUP

false

跳过数据库初始化

Docker 部署

快速开始

# Build
docker build -t design-patterns-mcp .

# Run HTTP mode
docker run -p 3000:3000 -e TRANSPORT_MODE=http design-patterns-mcp

# Run stdio mode (default)
docker run design-patterns-mcp

Docker Compose

docker compose up --build -d

环境变量

变量

默认值

描述

TRANSPORT_MODE

stdio

传输模式(stdio/http)

HTTP_PORT

3000

HTTP 端口(HTTP 模式)

MCP_ENDPOINT

/mcp

MCP 端点路径

HEALTH_CHECK_PATH

/health

健康检查路径

DATABASE_PATH

/app/data/design-patterns.db

SQLite 数据库路径

LOG_LEVEL

info

日志级别

SKIP_DB_SETUP

false

跳过数据库初始化

端点(HTTP 模式)

  • GET /health — 健康检查

  • POST /mcp — MCP JSON-RPC 端点

命令

# Development
bun run build        # Compile TypeScript
bun run dev          # Development with hot reload
bun run start        # Build and start production server

# Database
bun run db:setup     # Complete database setup
bun run migrate      # Run migrations
bun run seed         # Seed pattern data
bun run generate-embeddings  # Generate semantic embeddings
bun run setup-relationships  # Setup pattern relationships

# Quality
bun run test         # Run all tests
bun run lint         # Check code quality
bun run lint:fix     # Auto-fix linting issues
bun run typecheck    # TypeScript type checking

测试

项目包含 77 个测试文件中的 654 个测试用例,100% 通过率(0 失败,0 跳过):

  • 契约测试:MCP 协议合规性验证

  • 集成测试:针对实时 SQLite 数据库和嵌入向量的组件交互测试

  • 性能测试:搜索和向量化基准测试

  • 单元测试:单个组件测试

# Run all tests
bun run test

# Run specific test suites
bun run test:unit -- --grep "PatternService"
bun run test:integration -- --grep "database"
bun run test:performance -- --timeout 30000

架构模式

本项目实现了其自身所记录的模式:

模式

实现位置

仓库模式

repositories/pattern-repository.ts

服务层

services/pattern-service.ts

对象池

services/statement-pool.ts

依赖注入

core/container.ts

策略模式

strategies/search-strategy.ts

事件总线

events/event-bus.ts

多级缓存

services/multi-level-cache.ts

建造者模式

core/config-builder.ts

向量搜索(运行时诚实说明)

服务器使用 sql.js(SQLite WASM)配合内存余弦相似度对存储的嵌入向量进行计算。原生 sqlite-vec(vec0 虚拟表)在此运行时中不可用。语义搜索适用于当前目录规模(约 710 种模式),但不使用索引化的原生向量表。

仅在您拥有真实提供商集成时才启用 LLM 增强功能——内置的 LLM 桥接提供商在未扩展的情况下返回占位符。

贡献

欢迎贡献!请参阅贡献指南。

  1. Fork 本仓库

  2. 创建功能分支

  3. 遵循 SOLID 原则进行修改

  4. 运行测试和代码检查

  5. 提交拉取请求

发布说明

v0.7.2 — 版本号更新(2026-08-16)

  • 规范版本号从 0.7.1 → 0.7.2 更新,涉及所有活跃的源文件和文档文件。

  • 更新的文件:package.json、src/mcp-server.ts(服务器注册 + 运行时信息)、AGENTS.md、CLAUDE.md(规范标识头)、README.md(徽章、发布说明章节、版本页脚)、CHANGELOG.md(新条目)。docs/IMPROVEMENTS_03.md 和 QUICKSTART.md 中的审计证据引用按状态 #45 保持不变。

  • 修正了过时的版本引用:AGENTS.md 和 CLAUDE.md 头部 (version 0.6.0) → (version 0.7.2)(落后于实际 package.json 7 个次要版本)。

  • 运行时自报告现在通过 Server 构造函数和 /info 端点向 MCP 客户端通告 0.7.2。

  • 无代码级行为变更:纯发布/版本规范化补丁。

  • 测试:完整测试套件保留(未修改任何测试文件),类型检查通过。

v0.7.1 — Lint 与测试稳定性修复(2026-08-16)

  • 测试套件已全面验证:654/654 通过,0 跳过,0 待办(此前为 651/654,存在 3 个预先存在的偶发失败)。

  • 解决了 db:setup 流水线引入的 data/.git 泄漏问题(data-hygiene 测试)。

  • 将两个过时的测试与 BUG-007 契约 对齐:snake_case 的 search_type 会被 validateSearchPatternsArgs 静默忽略,并应用规范的默认 hybrid 策略。

    • tests/unit/input-validation.test.ts

    • tests/unit/mcp-server-search.test.ts

  • 已修正 README.md 版本漂移:尾部块现在反映规范的 0.7.0 → 0.7.1 基线,徽章 + Production Ready + Testing 部分与当前 654 个测试套件保持一致。

  • Lint 基线已恢复:0 个问题,退出码 0(此前为 2 个错误 + 6 个警告)。

    • 移除了 src/mcp/http-transport.ts 中未使用的 HealthStatus 导入。

    • 在 src/health/embedding-coverage-health-check.ts 的同步 check() 上为 require-await 添加了针对性的 eslint-disable(保留了接口一致性)。

    • 重构了 src/handlers/keyword-search-handler.ts 中的 ensureBM25(),使其返回 BM25Scorer,消除了调用点的 4 个非空断言。

    • 将 tests/unit/bm25-scorer.test.ts 中 results.find() 的 2 个非空断言替换为显式的 toBeDefined 守卫。

  • bun run typecheck 通过。

v0.7.0 — 目录扩展(2026-08-16)

  • 从 docs/01_Agentic_Design_Patterns.md 和 docs/02_Data_Engineering_Design_Patterns.md 添加了 24 个新设计模式:

    • 3 个 Agentic AI:多智能体协作、目标设定与监控、异常处理与恢复。

    • 21 个数据工程:Aligned Fan-In、Unaligned Fan-In、Bin Pack Orderer、Exclusive Choice、FIFO Orderer、Fine-Grained Accessor for Resources、Fine-Grained Accessor for Tables、Fine-Grained Tracker、In-Place Overwriter、Isolated Sequencer、Metadata Decorator、Metadata Enhancer、Offline Observer、Schema Compatibility Enforcer、Schema Migrator、Secretless Connector、Secrets Pointer、Single Runner、Skew Detector、SLA Misses Detector、Vertical Partitioner。

  • 目录从 686 个模式增长到 710 个模式(Agentic AI:3→6,数据工程:4→25)。

  • 完整性检查通过:710 个模式,151 个有效关系。

  • 654/654 个测试通过(100% 通过,0 跳过,0 待办)。

许可证

MIT 许可证 - 详情请参阅 LICENSE。

资源


版本:0.7.2 最后更新:2026 年 8 月 模式:710 个 JSON 定义(亮点:Feature Flag / Feature Toggle) 测试:654 个测试用例 | 100% 通过率(0 失败,0 跳过)

另请参阅: 最新的对抗性质量保证报告(16 个发现:1 个严重,9 个高优先级,6 个次要)。发现涵盖搜索流水线正确性、配置漂移、传输安全性和文档同步。

Available Tools

4 tools
count_patternsB

Get the total number of design patterns in the database

Inputs: includeDetails.

find_patternsC

Find design patterns matching a problem description using semantic search

Inputs: query (required), categories, maxResults, programmingLanguage.

get_pattern_detailsC

Get detailed information about a specific pattern

Inputs: patternId (required).

search_patternsC

Search patterns by keyword or semantic similarity

Inputs: query (required), searchType, limit.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3/5.0

    Scored across 4 tools

    Disambiguation2/5

    Multiple tools have overlapping purposes that could cause confusion. 'find_patterns' and 'search_patterns' both appear to search for patterns, with descriptions that are nearly identical ('semantic search' vs 'keyword or semantic similarity'), making them difficult to distinguish. 'count_patterns' and 'get_pattern_details' are clearer, but the overlap between the two search tools significantly reduces disambiguation.

    Naming Consistency5/5

    All tool names follow a consistent verb_noun pattern with snake_case, such as 'count_patterns', 'find_patterns', 'get_pattern_details', and 'search_patterns'. This uniformity makes the tool set predictable and easy to understand, with no deviations in naming conventions.

    Tool Count3/5

    With only 4 tools, the set feels thin for a server focused on design patterns, which typically involve operations like creating, updating, or categorizing patterns. While basic retrieval functions are covered, the low count may limit functionality for more complex agent tasks, placing it in the borderline range for appropriateness.

    Completeness2/5

    The tool set is severely incomplete for a design patterns domain, as it only supports read operations (counting, searching, and getting details) with no ability to create, update, delete, or manage patterns. This lack of CRUD coverage creates significant gaps that will likely cause agent failures when trying to perform full lifecycle tasks.

    Maintenance

    ActivityNo data
    ResponsivenessOutdated data

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables semantic code search across projects using AI embeddings to find code by meaning rather than just text matching. Provides fast intelligent search, symbol analysis, and code similarity detection with multi-language support.
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      Provides code repository indexing and semantic search capabilities, allowing natural language queries to find relevant code snippets with automatic incremental indexing and multi-language support.
      1
      360
      ISC