模型上下文协议服务器

一个模块化的MCP(模型上下文协议)HTTP服务器,使LLM客户端能够通过统一API与多个服务交互。

  • by BirgitPohl
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 BirgitPohl/mcp-example

使用说明

MCP-模型上下文协议服务器

一种模块化MCP(模型上下文协议)HTTP服务器,使LLM客户端能够通过统一的API与多个服务交互。

快速开始

# 1. Clone and install
git clone <repository-url>
cd mcp-poc
npm install

# 2. Build and run
npm run dev

# Or just run (if already built)
npm start

服务器将于启动http://localhost:3000

用法

检查服务器运行状况

curl http://localhost:3000/health
{
  "status": "healthy",
  "server": "mcp-server",
  "transport": "http-sse",
  "features": ["sms"],
  "tools": 1
}

从您的应用程序连接

import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";

// Connect to MCP server
const client = new Client(
  { name: "my-app", version: "1.0.0" },
  { capabilities: {} }
);

await client.connect(
  new SSEClientTransport(new URL("http://localhost:3000/sse"))
);

// List available tools
const { tools } = await client.listTools();
console.log(tools); // [{ name: "send_employee_notification", ... }]

// Call a tool
const result = await client.callTool({
  name: "send_employee_notification",
  arguments: {
    customerName: "Maria Schmidt",
    employeeName: "John",
    employeeMobileNumber: "+491234567890"
  }
});

贡献

添加新功能

模块化架构使添加新功能变得容易:

  1. 创建要素文件: src/servers/main/features/[name]/feature.ts
import type { MCPFeature } from "../registry.js";

export const myFeature: MCPFeature = {
  name: "my-feature",
  tools: [
    {
      name: "my_tool",
      description: "What this tool does",
      inputSchema: { /* JSON Schema */ }
    }
  ],
  toolHandlers: [
    {
      name: "my_tool",
      handler: async (args) => {
        // Your implementation
        return { content: [{ type: "text", text: "Result" }] };
      }
    }
  ],
  initialize: async () => {
    // Setup code
  }
};
  1. 在服务器中注册: src/servers/main/index.ts
import { myFeature } from "./features/my-feature/feature.js";

function registerFeatures() {
  featureRegistry.register(smsFeature);
  featureRegistry.register(myFeature); // Add here
}
  1. 重建并重新启动:
npm run dev

您的新工具现在可以通过MCP服务器获得!

文档

📚 全部文件 -完整的指南和参考

发展

# Start development env
npm run dev

# Watch mode
npm run dev:watch

# Build
npm run build

# Run with debug logging
DEBUG=true npm run dev

许可证

麻省理工学院-参见 许可证 详细信息文件