MCP服务器技能
一个使用TypeScript和Bun构建的模型上下文协议(MCP)服务器,提供了列表和阅读技能的工具。服务器使用面向对象的架构,并通过依赖注入来提高可维护性和可测试性。
特性
- list_skills:列出所有可用技能
- read_skill:通过ID读取特定技能
建筑
该项目遵循面向对象的设计和依赖注入:
ISkillRepository:定义技能数据访问合同的界面SkillRepository:技能库的具体实施ListSkillsTool:列出技能的工具处理程序ReadSkillTool:用于阅读特定技能的工具处理程序McpServer:编排工具和处理MCP协议的主服务器类
先决条件
- 包子 安装在您的系统上
安装
bun install发展
在开发模式下运行服务器:
bun run dev建筑
将服务器构建为已编译的Bun工件:
bun run build这将在 dist/ 目录。
运行编译后的服务器
构建后,运行编译后的服务器:
bun run start与MCP客户端一起使用
服务器通过stdin/stdout进行通信,可以在MCP客户端设置中进行配置。配置示例:
{
"mcpServers": {
"skills-server": {
"command": "bun",
"args": ["/path/to/local-mcp-test/dist/index.js"]
}
}
}项目结构
src/
├── interfaces/
│ └── ISkillRepository.ts # Repository interface
├── repositories/
│ └── SkillRepository.ts # Repository implementation
├── tools/
│ ├── ListSkillsTool.ts # List skills tool handler
│ └── ReadSkillTool.ts # Read skill tool handler
├── server/
│ └── McpServer.ts # Main MCP server class
└── index.ts # Entry point扩展服务器
要添加新技能或更改数据源,请执行以下操作:
- 实现一个符合以下要求的新存储库类
ISkillRepository - 将其注入
McpServer构造器inindex.ts - 服务器将自动使用新的实现
许可证
麻省理工学院
