Cover image
Try Now
2025-04-09

mcp server

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

MCP API Server

Node.js Version TypeScript

企业级微服务API服务端,支持MCP协议扩展。

✨ 功能特性

  • MCP协议集成(支持工具扩展和资源访问)
  • 动态API工具注册
  • TypeScript强类型支持

🚀 快速开始

前置要求

  • Node.js 18+
  • npm 9+
  • TypeScript 5.0+

安装步骤

# 克隆仓库
git clone https://github.com/your-repo/mcp-api-server.git

# 安装依赖
npm install

# 生产环境构建
npm run build

MCP 配置参数

{
  "mcpServers": {
    "api-server": {
      "command": "node",
      "args": [
        "D:/api-server/build/index.js"
      ],
      "env": {
        "BASE_URL": "https://127.0.0.0:8080",
        "CLIENT_ID": "xxx",
        "CLIENT_SECRET": "xxx",
        "USERNAME": "xxx",
        "PASSWORD": "xxx",
        "TENANT_ID": "1",
        "REJECT_UNAUTHORIZED": "false",
        "ALLOWED_APIS": "/admin-api/system/user/page,/admin-api/system/user/create,/admin-api/system/user/update"
      },
      "disabled": false,
      "autoApprove": []
    }
  }
}

配置说明

mcpServers 中配置 ALLOWED_APIS 数组来控制哪些API端点可以作为MCP工具暴露:

alt text

📂 项目结构

mcp-api-server/
├── build/          # 编译输出目录
├── src/            # 源代码
│   ├── config/     # 配置模块
│   ├── modules/    # 业务模块
│   └── tools/      # MCP工具协议
├── package.json
└── tsconfig.json

📡 MCP Tools

动态API工具系统

MCP-Server 实现了基于 OpenAPI 规范的动态工具发现和注册机制,无需手动配置即可自动生成 MCP 工具。

apiEndpoints.ts 功能说明

// 从OpenAPI规范自动获取API端点信息
const openApiData = await fetchOpenApiData();

// 根据配置的允许列表过滤API
const API_ENDPOINTS = Object.entries(openApiData.paths)
    .filter(([path]) => config.ALLOWED_APIS.includes(path))
    .map(([path, methods]) => {
        // 转换为标准工具格式
        return Object.entries(methods).map(([method, details]) => ({
            name: details.operationId,
            description: details.summary,
            inputSchema: details.parameters ? {
                type: 'object',
                properties: Object.fromEntries(details.parameters
                    .filter(isExposableParameter)
                    .map(transformParameterToProperty)
                )
            } : {},
            path: path,
            method: method.toUpperCase()
        }));
    }).flat();

tools/index.ts 工具注册机制

export function registerTools(server: Server) {
  // 注册可用工具列表
  server.setRequestHandler(ListToolsRequestSchema, async () => ({
    tools: tools,
  }));

  // 处理工具调用请求
  server.setRequestHandler(CallToolRequestSchema, async (request) => {
    const endpoint = apiMap[request.params.name];
    
    // 根据HTTP方法类型动态处理请求
    if(endpoint.method === 'GET') {
      const response = await apiClient.get(endpoint.path, { params: request.params.arguments });
      return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }] };
    } else if(endpoint.method === 'POST') {
      const response = await apiClient.post(endpoint.path, request.params.arguments);
      return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }] };
    } else if(endpoint.method === 'PUT') {
      const response = await apiClient.put(endpoint.path, request.params.arguments);
      return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }] };
    }
  });
}

系统优势

  • 自动发现: 通过 OpenAPI 规范自动发现和注册API端点
  • 缓存机制: 实现了API规范数据的缓存,提高性能并处理网络异常
  • 参数转换: 自动将OpenAPI参数定义转换为MCP工具输入模式
  • 安全过滤: 过滤内部参数,只暴露安全的API参数
  • 错误处理: 完善的错误处理机制,确保工具调用稳定性
  • 工具注册: 自动注册可用工具列表,无需手动配置

🤝 贡献指南

  1. Fork项目仓库
  2. 创建特性分支 (git checkout -b feature/your-feature)
  3. 提交修改 (git commit -m 'Add some feature')
  4. 推送分支 (git push origin feature/your-feature)
  5. 创建Pull Request

📄 许可证

MIT License

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Bora Yalcin
  • Evaluator for marketplace product descriptions, checks for relevancy and keyword stuffing.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Callycode Limited
  • A geek-themed horoscope generator blending Bitcoin prices, tech jargon, and astrological whimsy.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Khalid kalib
  • Write professional emails

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Lists Tailwind CSS classes in monospaced font

  • apappascs
  • Discover the most comprehensive and up-to-date collection of MCP servers in the market. This repository serves as a centralized hub, offering an extensive catalog of open-source and proprietary MCP servers, complete with features, documentation links, and contributors.

  • ShrimpingIt
  • Micropython I2C-based manipulation of the MCP series GPIO expander, derived from Adafruit_MCP230xx

  • OffchainLabs
  • Go implementation of Ethereum proof of stake

  • huahuayu
  • A unified API gateway for integrating multiple etherscan-like blockchain explorer APIs with Model Context Protocol (MCP) support for AI assistants.

  • deemkeen
  • control your mbot2 with a power combo: mqtt+mcp+llm

    Reviews

    3 (1)
    Avatar
    user_xui9ygAG
    2025-04-16

    I have been using mcp-server by qingtianyu for several months and it has significantly improved my server management experience. The project is well-documented and the community support is excellent. Highly recommend for anyone looking for a robust and reliable server management tool. Check it out on GitHub!