generic-mcp-server

by v4lheru
Verified

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

Integrations

  • Enables configuration through environment variables loaded from .env files, supporting easy management of API keys and other configuration settings needed by the MCP server.

  • Serves as the runtime environment for the MCP server, with support for Node.js 18 or higher, enabling server-side JavaScript execution and API integrations.

  • Provides full TypeScript support with proper typing throughout the codebase, enabling type safety for tool definitions, service implementations, and handler functions.

Plantilla genérica de servidor MCP

Una plantilla de servidor de Protocolo de Contexto de Modelo (MCP) modular y extensible, diseñada para una fácil personalización y extensión.

Características

  • Arquitectura modular : clara separación de preocupaciones con una estructura bien definida
  • Archivos pequeños y enfocados : mejor capacidad de mantenimiento y más fácil de ingerir para la IA
  • Puntos de extensión fáciles : patrones simples para agregar nuevas herramientas y servicios
  • Manejo integral de errores : gestión robusta de errores en todo el código base
  • Seguridad de tipos : compatibilidad total con TypeScript con tipificación adecuada

Estructura del proyecto

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

Empezando

Prerrequisitos

  • Node.js 18 o superior
  • npm o hilo

Instalación

  1. Clonar este repositorio:
    git clone https://github.com/v4lheru/generic-mcp-template.git cd generic-mcp-template
  2. Instalar dependencias:
    npm install
  3. Cree un archivo .env basado en .env.example :
    cp .env.example .env
  4. Edite el archivo .env con sus claves API y configuración.

Construyendo y funcionando

  1. Construir el proyecto:
    npm run build
  2. Ejecutar el servidor:
    npm start

Ampliación de la plantilla

Agregar un nuevo servicio

  1. Cree un nuevo archivo de servicio en 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... }
  2. Agregue cualquier tipo necesario en src/types/ .

Agregar nuevas herramientas

  1. Define tus herramientas en un nuevo archivo o amplía el existente en 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 } } ];
  2. Implemente controladores para sus herramientas:
    // 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 } }; }
  3. Registre sus herramientas y controladores en src/index.ts .

Configuración

La plantilla utiliza un sistema de configuración centralizado en src/config.ts . La configuración se puede realizar mediante:

  • Variables de entorno
  • Argumentos de la línea de comandos (con --env KEY=VALUE )
  • Valores predeterminados en el código

Manejo de errores

La plantilla incluye un manejo integral de errores:

  • Manejo de errores a nivel de servicio con soporte de limitación de velocidad
  • Manejo de errores a nivel de herramienta con mensajes de error adecuados
  • Manejo de errores del protocolo MCP

Licencia

Instituto Tecnológico de Massachusetts (MIT)

-
security - not tested
A
license - permissive license
-
quality - not tested

Un framework para usar con IA y crear fácilmente un servidor para cualquier servicio. Simplemente inserta la documentación de la API y solicita la creación del MCP.

  1. Features
    1. Project Structure
      1. Getting Started
        1. Prerequisites
        2. Installation
        3. Building and Running
      2. Extending the Template
        1. Adding a New Service
        2. Adding New Tools
      3. Configuration
        1. Error Handling
          1. License
            ID: 0vtdinwieq