MCP指令服务器
TypeScript MCP(模型上下文协议)服务器,用于AI助手发现和访问结构化markdown指令。
概述
MCPInstructionServer使像Claude这样的AI助手能够通过标准化的界面访问基于markdown的指令库。通过将指令组织为markdown文件,您可以:
- 为人工智能提示创建一个集中的知识库
- 维护版本化、结构化的指导文件
- 允许AI助手按需搜索和检索特定指令
- 为人工智能辅助任务建立一致的模式
运作原理
服务器对指定目录(及其子目录)中的markdown文件进行索引,将每个文件视为指令文档。服务器提取每个文档的标题和第一段,以创建可搜索的摘要。
AI助手可以:
- 列出所有可用的说明及其摘要
- 按ID请求具体说明
特性
- 基于文件系统的简单存储:只需标记目录中的文件
- 递归目录扫描:以分层文件夹结构组织指令
- 路径安全:防止遍历目录和访问允许目录外的文件
- 自动摘要提取:从每个文档中提取H1标题和第一段
- 模型上下文协议支持:与实施MCP的AI助手兼容
先决条件
- Node.js 18+(用于ESM支持)
- npm或纱线
- 基本熟悉TypeScript和markdown
安装
# Clone the repository
git clone https://github.com/yourusername/MCPInstructionServer.git
cd MCPInstructionServer
# Install dependencies
npm install
# Build the project
npm run build用法
启动服务器
# Start with path to your instructions directory
npm start -- /path/to/instructions
# Or directly with node
node dist/index.js /path/to/instructions创建指令
指令只是带有 .md 扩展。每个文件应遵循以下结构:
# Instruction Title
Brief description of this instruction's purpose. This first paragraph will be used as the summary when listing instructions.
## Details
Additional sections with more detailed information...
## Examples
Usage examples, code samples, etc.目录结构示例
instructions/
├── api/
│ ├── authentication.md
│ └── rate-limiting.md
├── design/
│ ├── color-system.md
│ └── typography.md
└── general/
├── code-review.md
└── git-workflow.md访问说明
服务器提供两个MCP工具:
1. listInstructions
返回所有可用指令及其ID和摘要的列表。
示例响应:
id: api/authentication
summary: Authentication API - This document outlines the authentication protocol used in our system.
id: design/typography
summary: Typography Guidelines - This guide explains our typographic scale and usage rules.2. readInstruction
获取指令ID并返回相应指令的完整内容。
请求示例: { "id": "api/authentication" }
发展
# Run in development mode with auto-restart
npm run dev -- /path/to/instructions
# Run tests
npm test安全考虑
- 服务器验证所有路径以防止目录遍历攻击
- 只能访问指定指令目录中的文件
- 不提供写入功能,只允许读取
许可证
麻省理工学院
贡献
欢迎投稿!请随时提交拉取请求。
