MCP API Server

by qingtianyu

190 downloads Not rated yet

About

MCP API Server is an enterprise-level microservice API server that integrates with the Model Context Protocol (MCP). It enables dynamic API tool registration and management, allowing existing RESTful APIs to be exposed as MCP tools. The server is built with TypeScript and…

Explore

- MCP protocol integration with tool and resource support
- Dynamic API tool registration via OpenAPI specification
- Automatic parameter conversion from OpenAPI to MCP input schema
- Security filtering to expose only safe API parameters
- Built-in caching for API specification data
- Error handling for stable tool invocation

Install Node.js 18+, npm 9+, and TypeScript 5.0+. Clone the repository, run npm install, then npm run build. Configure the server by setting the required environment variables (e.g., BASE_URL, CLIENT_ID, CLIENT_SECRET, ALLOWED_APIS) in the mcpServers section of your MCP client configuration. The server automatically discovers and registers API endpoints based on an OpenAPI specification and the ALLOWED_APIS filter list.

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) }] };
}
});
}

Node.js Version
TypeScript

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

✨ 功能特性

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

🚀 快速开始

前置要求

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

安装步骤

```bash
No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.