Markdown转静态MCP服务器工具

md2mcp是一个零配置、零代码的工具,能够将Markdown文件转换为静态MCP服务器,适用于文档、模板、代码片段等预定义内容的快速部署。

  • by Mattias-Linholm
  • JavaScript
  • 本地部署
  • 更新于
在 GitHub 查看 Mattias-Linholm/md2mcp

使用说明

md2mcp

将Markdown转换为 静态 MCP服务器-零配置,零代码。

非常适合: 文档、模板、代码片段、帮助文本、合规规则或您希望Claude访问的任何预定义内容。

快速开始

超快速(无需安装):

npx github:mattiaslinholm/md2mcp serve my-docs.md

创建新项目:

npx github:mattiaslinholm/md2mcp init my-server
cd my-server
npm install
npm run build

对于Claude桌面/代码配置:

{
  "mcpServers": {
    "my-docs": {
      "command": "npx",
      "args": ["github:mattiaslinholm/md2mcp", "serve", "/absolute/path/to/my-docs.md"]
    }
  }
}

完成! 🎉

注: 这创造了 静态 服务器。所有响应都是markdown文件中的预定义文本。对于动态服务器(API调用、计算等),请使用 @模型上下文协议/sdk 直接。

Markdown格式

创建一个markdown文件(任何名称。, spec.md, compliance.md, docs.md):

# Your Server Name

Brief description of your server

---

## tool_name

Description of what this tool does and when to call it

### Response

The text response that will be returned to the AI when this tool is called.

This can be multi-line, include formatting, lists, etc.

Write this as if you're giving instructions to the AI assistant.

---

## another_tool

Another tool description

### Response

Another response with different instructions or content.

要点:

  • # Title -服务器名称(第一个标题)
  • ## tool_name -工具名称(使用下划线,小写)
  • 工具描述-人工智能应在何时调用此工具?
  • ### Response -调用工具时返回的静态文本
  • 将响应作为对AI的指令编写,而不是来自AI的响应

命令

# Development
npx md2mcp serve my-spec.md          # Run server directly (any markdown file)
npx md2mcp start                     # Run with stdio (uses ./spec.md)
npx md2mcp start --http              # Run as HTTP server on port 3005

# Building
npx md2mcp build                     # Build to ./dist (uses ./spec.md)
npx md2mcp build --spec compliance.md --output dist  # Custom spec and output

# Packaging for distribution
npx md2mcp pack                      # Create .mcpb bundle in current directory
npx md2mcp pack --spec compliance.md --output releases  # Custom locations

构建vs打包

  • build -将可运行的服务器文件(index.js、spec.md、package.json)生成到输出目录

    • 在要部署服务器的monorepos/项目中使用
    • 默认输出: ./dist
    • 构建后: cd dist && npm install && node index.js
  • pack -创建一个 .mcpb 用于分发的捆绑文件

    • 将服务器分发给最终用户时使用
    • 将所有内容打包成一个 .mcpb 文件
    • 默认输出:当前目录
    • 用户可以拖放到克劳德桌面

选项

两者 build 和 pack 支持:

  • --spec <file> -指定标记文件(默认值: ./spec.md)
  • --output <dir> -指定输出目录(默认: ./dist 对于构建, . 用于包装)
  • --silent -抑制构建输出(在monorepos/CI管道中有用)

运作原理

  1. 您的markdown将在运行时解析
  2. 工具是动态注册的
  3. 无需编译-纯JavaScript
  4. 单一依赖关系: @modelcontextprotocol/sdk

示例

看 spec.md 对于带有ping工具的工作示例服务器。