汎用 MCP サーバー テンプレート
簡単にカスタマイズおよび拡張できるように設計された、モジュール式の拡張可能なモデル コンテキスト プロトコル (MCP) サーバー テンプレート。
特徴
モジュラーアーキテクチャ:明確に定義された構造による関心事の明確な分離
小さく、焦点を絞ったファイル:メンテナンス性が向上し、AIが取り込みやすくなります
簡単な拡張ポイント: 新しいツールやサービスを追加するためのシンプルなパターン
包括的なエラー処理: コードベース全体にわたる堅牢なエラー管理
型安全性: 適切な型付けによる完全なTypeScriptサポート
プロジェクト構造
はじめる
前提条件
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 .envAPI キーと設定を使用して
.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プロトコルエラー処理
ライセンス
マサチューセッツ工科大学
This server cannot be installed
AIと組み合わせて使用することで、あらゆるサービス用のサーバーを簡単に作成できるフレームワークです。APIドキュメントをそこにドロップするだけで、MCPの作成を依頼できます。
Related Resources
Related MCP Servers
- AsecurityAlicenseAqualityAn MCP server that generates AI agent tools from Postman collections and requests. This server integrates with the Postman API to convert API endpoints into type-safe code that can be used with various AI frameworks.Last updated -13MIT License
- -securityAlicense-qualityGenerate an MCP server for any OpenAPI documented endpoint.Last updated -303MIT License
- AsecurityAlicenseAqualityA tool that creates MCP (Model Context Protocol) servers from OpenAPI/Swagger specifications, enabling AI assistants to interact with your APIs.Last updated -32025MIT License
- -securityFlicense-qualityAn auto-generated MCP server that enables interaction with the OpenAI API, allowing users to access OpenAI's models and capabilities through the Multi-Agent Conversation Protocol.Last updated -