模型上下文协议服务器

用于创建和部署MCP服务器的核心组件,提供快速设置、SSE支持和Express集成。

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

使用说明

@制剂/mcp

用于为Genius Dashboard创建MCP服务器的核心MCP(模型上下文协议)服务器组件。此包提供了一个可重用的服务器实现,可以轻松创建和部署MCP服务器。

安装

npm install @geniusagents/mcp

用法

1.定义您的MCP功能

创建实现 McpFunction 界面。每个函数代表一个可由MCP客户端调用的工具。

import { McpFunction } from '@geniusagents/mcp';
import { z } from 'zod';

export class AddMcp implements McpFunction {
  name = 'add';
  description = 'Adds two numbers';
  
  // Zod schema for validation and type inference
  zschema = {
    a: z.number().describe('The first number'),
    b: z.number().describe('The second number')
  };

  // JSON Schema for the MCP protocol (can be derived from zod or defined manually)
  inputschema = {
    type: "object",
    properties: {
      a: { type: "number", description: "The first number" },
      b: { type: "number", description: "The second number" }
    },
    required: ["a", "b"]
  };

  async handleExecution(args: any) {
    const { a, b } = args;
    return {
      content: [
        {
          type: "text",
          text: `The sum is ${a + b}`
        }
      ]
    };
  }
}

2.创建并运行服务器

立即 GeniusMcpServer 使用您的功能并启动它。

import { GeniusMcpServer, ApiKeyManager } from '@geniusagents/mcp';
import { AddMcp } from './AddMcp'; // Assuming AddMcp is in the same directory

// Initialize the ApiKeyManager with the MCP Name for the Genius Dashboard
ApiKeyManager.initialize({
    mcpName: "AddMcpServer",
    dashboardUrl: process.env.DASHBOARD_URL || "https://dashboard.geniusagents.nl/api/mcp"
});

// Initialize the GeniusMcpServer
const server = new GeniusMcpServer(
  'Add MCP Server',       // Server name
  3000,                   // Port
  [new AddMcp()]          // List of functions
);

server.run().catch(console.error);

特性

  • 轻松设置:使用最少的样板快速启动MCP服务器。
  • SSE支持:内置服务器发送事件传输,用于实时通信。
  • 快速集成:基于Express.js构建。
  • 类型安全:用TypeScript编写,具有完整的类型定义。

许可证

ISC