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.

汎用 MCP サーバー テンプレート

簡単にカスタマイズおよび拡張できるように設計された、モジュール式の拡張可能なモデル コンテキスト プロトコル (MCP) サーバー テンプレート。

特徴

  • モジュラーアーキテクチャ:明確に定義された構造による関心事の明確な分離
  • 小さく、焦点を絞ったファイル:メンテナンス性が向上し、AIが取り込みやすくなります
  • 簡単な拡張ポイント: 新しいツールやサービスを追加するためのシンプルなパターン
  • 包括的なエラー処理: コードベース全体にわたる堅牢なエラー管理
  • 型安全性: 適切な型付けによる完全なTypeScriptサポート

プロジェクト構造

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

インストール

  1. このリポジトリをクローンします:
    git clone https://github.com/v4lheru/generic-mcp-template.git cd generic-mcp-template
  2. 依存関係をインストールします:
    npm install
  3. .env.exampleに基づいて.envファイルを作成します。
    cp .env.example .env
  4. API キーと設定を使用して.envファイルを編集します。

構築と実行

  1. プロジェクトをビルドします。
    npm run build
  2. サーバーを実行します。
    npm start

テンプレートの拡張

新しいサービスの追加

  1. 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. 必要なタイプをsrc/types/に追加します。

新しいツールの追加

  1. 新しいファイルでツールを定義するか、 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. ツールのハンドラーを実装します。
    // 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. ツールとハンドラーをsrc/index.tsに登録します。

構成

このテンプレートはsrc/config.ts内の集中設定システムを使用します。設定は以下の方法で行うことができます。

  • 環境変数
  • コマンドライン引数( --env KEY=VALUEを使用)
  • コード内のデフォルト値

エラー処理

テンプレートには包括的なエラー処理が含まれています。

  • レート制限をサポートするサービスレベルのエラー処理
  • 適切なエラーメッセージによるツールレベルのエラー処理
  • MCPプロトコルエラー処理

ライセンス

マサチューセッツ工科大学

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

AIと組み合わせて使用することで、あらゆるサービス用のサーバーを簡単に作成できるフレームワークです。APIドキュメントをそこにドロップするだけで、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