Nest Llm Argent
MCP 的出现带来了极大的灵活性,其最大的优势在于通过开发的 MCP Server,可以支持对接到不同的客户端。这种高度可扩展性促使我们深入思考:如何将 MCP Server 无缝集成到现有的 Web 服务中?我的解决方案是设计一个适配层,既能保持 MCP Server 包的完整性,又能方便地接入到各种场景中。因此,诞生了这个项目。最终希望提供大模型的调用包装接口,及 MCP 的相关配置请求接口。
简介
Nest-LLM-Aigent 是一个适配层,旨在将 MCP Server 无缝集成到 Web 服务中,同时保持其完整性和可移植性。它提供大模型的调用包装接口以及 MCP 的相关配置请求接口,特别适合 BS(浏览器-服务器)架构。
主要功能
- 适配 BS 架构,实现对 MCP 功能的调用
- 保持 MCP Server 的高度可移植性
- 提供标准化的 API 接口
API 接口
功能 | HTTP 方法 | 路径 | 描述 |
---|---|---|---|
获取所有工具 | POST | /api/mcp/tools | 获取所有工具列表 |
调用 MCP 工具 | POST | /api/mcp/tools/call | 调用 MCP 工具 |
获取资源列表 | POST | /api/mcp/resources | 获取所有资源 |
获取所有提示 | POST | /api/mcp/prompts | 获取所有提示 |
获取所有工具、资源、提示词 | POST | /api/mcp/all | 返回格式:{tools:[],resources:[],prompts:[]} |
快速部署
1. 使用私有 NPM 包安装
npm install @your-org/mcp-server
2. 创建配置文件
创建 mcp.config.json
文件:
{
"mcpServers": {
"server1": {
"name": "example-server",
"args": ["server.js"],
"path": "./servers/server1/"
}
},
"mcpClient": {
"name": "mcp-client",
"version": "1.0.0"
}
}
3. 集成到项目
// 引入并初始化
const { MCPAdapter } = require('@your-org/nest-llm-aigent');
const adapter = new MCPAdapter('./mcp.config.json');
// 启动服务
adapter.start();
调用示例
// 获取所有 MCP 资源
fetch('/api/mcp/all', {
method: 'POST',
headers: { 'Content-Type': 'application/json' }
})
.then(res => res.json())
.then(data => console.log(data));
// 调用工具
fetch('/api/mcp/tools/call', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({
toolName: 'example-tool',
params: { /* 参数 */ }
})
})
.then(res => res.json())
.then(result => console.log(result));
通过以上步骤,您可以快速集成并使用 Nest-LLM-Aigent 适配层,实现 MCP 功能在 Web 服务中的无缝应用。