generic-mcp-server
通用 MCP 服务器模板
模块化、可扩展的模型上下文协议 (MCP) 服务器模板,旨在轻松定制和扩展。
特征
模块化架构:通过定义明确的结构明确地分离关注点
小型、专注的文件:更好的可维护性,更容易被人工智能吸收
轻松扩展点:添加新工具和服务的简单模式
全面的错误处理:整个代码库的强大错误管理
类型安全:完全支持 TypeScript 并正确输入
Related MCP server: Swagger MCP
项目结构
generic-mcp-template/
├── src/
│ ├── services/ # Service classes for API interactions
│ │ ├── base-service.ts # Abstract base service with common functionality
│ │ └── example-service.ts # Example service implementation
│ ├── tools/ # MCP tool definitions and handlers
│ │ ├── example-tools.ts # Tool definitions (name, description, schema)
│ │ └── example-tool-handlers.ts # Tool handler implementations
│ ├── types/ # TypeScript type definitions
│ │ └── example-types.ts # Example type definitions
│ ├── config.ts # Configuration management
│ └── index.ts # Main entry point
├── .env.example # Example environment variables
├── package.json # Project dependencies and scripts
├── tsconfig.json # TypeScript configuration
└── README.md # Project documentation入门
先决条件
Node.js 18 或更高版本
npm 或 yarn
安装
克隆此存储库:
git clone https://github.com/v4lheru/generic-mcp-template.git cd generic-mcp-template安装依赖项:
npm install根据
.env.example创建.env文件:cp .env.example .env使用您的 API 密钥和配置编辑
.env文件。
构建和运行
构建项目:
npm run build运行服务器:
npm start
扩展模板
添加新服务
在
src/services/中创建一个新的服务文件:// src/services/my-service.ts import { BaseService } from './base-service.js'; import config from '../config.js'; export class MyService extends BaseService { // Implement your service... }在
src/types/中添加任何必要的类型。
添加新工具
在新文件中定义您的工具或扩展
src/tools/中现有的工具:// src/tools/my-tools.ts export const myTools = [ { name: "my_tool", description: "Description of my tool", inputSchema: { // JSON Schema for the tool's input } } ];为您的工具实现处理程序:
// src/tools/my-tool-handlers.ts import { MyService } from '../services/my-service.js'; export function createMyToolHandlers(myService: MyService) { return { my_tool: async (args: any) => { // Implement your tool handler } }; }在
src/index.ts中注册您的工具和处理程序。
配置
该模板使用src/config.ts中的集中配置系统。可以通过以下方式提供配置:
环境变量
命令行参数(使用
--env KEY=VALUE)代码中的默认值
错误处理
该模板包括全面的错误处理:
具有速率限制支持的服务级错误处理
使用适当的错误消息进行工具级错误处理
MCP 协议错误处理
执照
麻省理工学院
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Tools
Related MCP Servers
- Alicense-qualityDmaintenanceAutomatically converts any OpenAPI specification or Postman Collection into an MCP server, enabling AI assistants like Claude to directly interact with REST APIs without writing any code.Apache 2.0
- Flicense-qualityDmaintenanceAutomatically converts Swagger/OpenAPI specifications into MCP servers, enabling AI agents to interact with any REST API through natural language by exposing endpoints as AI-friendly tools.3
- Alicense-qualityAmaintenanceOne command to turn any codebase into an MCP server. Not just REST APIs. Not just OpenAPI specs.41Apache 2.0
- Alicense-qualityCmaintenanceTurns any OpenAPI specification into a fully working MCP server with a single command, enabling AI agents to call APIs without writing any glue code.8MIT
Related MCP Connectors
MCP server for AI access to Swagger by SmartBear.
Self-hosted MCP gateway: turn any API, database or MCP server into AI connectors — no code.
MCP (Model Context Protocol) server for Appwrite
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/v4lheru/generic-mcp-template'
If you have feedback or need assistance with the MCP directory API, please join our Discord server