最小MCP服务器设计
- 检索和阅读笔记。
需求
- 创建一个实现模型上下文协议的最小MCP服务器
- 提供检索和阅读标记注释的功能
- 使用提供的注释_MCP作为知识来源
- 尽量减少实施(MVP)
- 使用纯JavaScript(无TypeScript)
技术栈
- 运行时:Node.js
- 框架:Express.js(轻量级web框架)
- 依赖项:
- express(HTTP服务器) - cors(跨源资源共享) - fs(用于阅读笔记的Node.js文件系统) - 路径(路径操作实用程序)
建筑
一个简单的客户端-服务器架构:
+-------------------+ +-------------------+ +-----------------+
| LLM Host | ----> | MCP Server | ----> | File System |
| (Claude/other LLM)| | (Express Server) | | (Notes Storage) |
| | <---- | | <---- | |
+-------------------+ +-------------------+ +-----------------+目录结构
mcp-notes-server/
├── package.json
├── server.js # Main entry point
├── routes/
│ └── mcp-router.js # MCP protocol router
├── tools/
│ └── notes-tool.js # Notes retrieval implementation
└── notes/ # Directory containing your markdown notes
└── ... (your .md files)组件
1.MCP路由器
处理MCP协议请求:
- 发现端点(
/discover):返回可用的工具和功能 - 调用端点(
/invoke):处理工具函数调用
2.笔记工具
实现钞票检索功能:
list_notes:列出可用注释read_note:检索特定注释的内容search_notes:笔记的简单搜索功能
实施计划
- 设置支持CORS的基本Express服务器
- 实现具有发现和调用端点的MCP路由器
- 使用基本文件操作创建笔记工具
- 连接组件并使用LLM主机进行测试
