Model Context Protocol (MCP) Server

by infinyte

Integrations

  • Enables environment-based configuration of API keys and server settings through .env file management

  • Supports development mode with automatic server reloading when code changes are detected

  • Provides access to OpenAI models (GPT) and DALL-E image generation through a unified API, supporting chat completions, legacy completions, and tool calling

モデルコンテキストプロトコル(MCP)サーバー

複数の AI モデル プロバイダーに統合された API を提供する、モデル コンテキスト プロトコルのシンプルなサーバー実装。

特徴

  • 複数の AI プロバイダー (Anthropic、OpenAI) 向けの統合 API
  • チャット補完と従来の補完のサポート
  • ツール呼び出しサポート
  • コンテキスト/システムメッセージの処理
  • 環境ベースの構成
  • 永続性と状態管理のためのMongoDBデータベース
  • ツール実行履歴と分析

インストール

# Clone the repository git clone <repository-url> cd testmcp # Install dependencies npm install # Run the interactive setup npm run setup

セットアップ スクリプトは、必要な API キーの構成をガイドします。

  • ANTHROPIC_API_KEY - Claude モデルの場合
  • OPENAI_API_KEY - GPTモデルとDALL-E画像生成用
  • STABILITY_API_KEY - 安定拡散画像生成用
  • GOOGLE_CSE_API_KEYGOOGLE_CSE_ID - ウェブ検索機能用
  • BING_SEARCH_API_KEY - フォールバックウェブ検索用

必要に応じて、 .envファイルを手動で編集することもできます。

MongoDBのセットアップ

MCPサーバーはデータの永続化にMongoDBを使用します。MongoDBの設定にはいくつかのオプションがあります。

オプション 1: 自動セットアップ (推奨)

MongoDB セットアップ スクリプトを実行すると、プロセスがガイドされます。

# Run the MongoDB setup script npm run setup-mongodb

このスクリプトは次のことを行います。

  1. Dockerが利用可能かどうかを確認する
  2. Docker Compose を使用して MongoDB を起動します (利用可能な場合)
  3. .envファイルで接続を設定する
  4. MongoDB接続を確認する

オプション2: 手動Dockerセットアップ

MongoDB を使い始める最も簡単な方法は、付属の Docker Compose 構成を使用することです。

# Start MongoDB and Mongo Express in Docker docker compose up -d # Update your .env file with the connection string echo "MONGODB_URI=mongodb://mcpuser:mcppassword@localhost:27017/mcp-server" >> .env

MongoDBはmongodb://mcpuser:mcppassword@localhost:27017/mcp-serverで利用可能になります。
Mongo Express(Web管理)はhttp://localhost:8081で利用できます。

オプション3: ローカルMongoDBインストール

MongoDB をローカルにインストールする場合:

  1. https://www.mongodb.com/try/download/communityから MongoDB をインストールします。
  2. MongoDBサービスを開始する
  3. .envファイルを次のように更新します。
    MONGODB_URI=mongodb://localhost:27017/mcp-server

オプション4: MongoDB Atlas (クラウド)

実稼働環境での使用には、MongoDB Atlas が推奨されます。

  1. https://www.mongodb.com/cloud/atlasでアカウントを作成します。
  2. 新しいクラスターを作成する
  3. データベースユーザーを設定し、IPアドレスをホワイトリストに登録する
  4. 接続文字列を取得し、 .envファイルを更新します。
    MONGODB_URI=mongodb+srv://<username>:<password>@<cluster>.mongodb.net/mcp-server?retryWrites=true&w=majority

データベース移行

既存のデータを MongoDB に移行するには:

# Run the migration script npm run migrate-mongodb

このスクリプトは次のことを行います。

  1. ツール定義をMongoDBに移行する
  2. 設定(APIキーなど)をMongoDBに移行する
  3. バックアップデータがある場合はインポートする

使用法

サーバーを起動する

# Interactive startup (checks for API keys) npm start # Development mode with auto-reload npm run dev # Quick start (skips environment checks) npm run quick-start # Start server with PM2 process manager npm run pm2:start # Start server with PM2 in production mode npm run pm2:start:prod

サーバーはhttp://localhost:3000 (または .env で指定したポート) で実行されます。

起動オプション
  1. 標準スタートnpm start ):
    • APIキーが設定されているかどうかを確認します
    • キーが見つからない場合はセットアップを要求します
    • 初めての方におすすめ
  2. 開発モード( npm run dev ):
    • コード変更時に自動リロードするために nodemon を使用します
    • 環境チェックは引き続き実行します
    • 開発に最適
  3. クイックスタート( npm run quick-start ):
    • すべての環境チェックをバイパスします
    • すぐにサーバーを起動します
    • 設定が正しいことがわかっている場合に便利です
  4. PM2 プロダクションモード( npm run pm2:start:prod ):
    • PM2プロセスマネージャを使用してサーバーを実行します
    • サーバーがクラッシュした場合は自動的に再起動します
    • 実稼働環境に最適化
    • 環境チェックをバイパスする

PM2プロセスマネージャの使用

このサーバーは、Node.jsアプリケーション向けのプロダクションプロセスマネージャーであるPM2で実行できます。PM2は次のような機能を提供します。

  • プロセス管理(クラッシュ時の再起動)
  • ログ管理
  • パフォーマンス監視
  • 負荷分散(複数インスタンスの場合)
PM2コマンド
# Start the server with PM2 npm run pm2:start # Start in production mode npm run pm2:start:prod # View logs npm run pm2:logs # Monitor performance npm run pm2:monit # Restart the server npm run pm2:restart # Stop the server npm run pm2:stop # Remove the server from PM2 npm run pm2:delete

PM2の設定はecosystem.config.jsに保存されています。このファイルを編集することで、以下の変更を加えることができます。

  • プロセス名
  • 環境変数
  • メモリ制限
  • 展開構成
  • インスタンス数(負荷分散用)

APIエンドポイント

POST /mcp/:provider

統合された API を通じて AI モデルにリクエストを送信します。

URL パラメータ:

  • provider : 使用する AI プロバイダー ( anthropicまたはopenai )

リクエスト本文:

{ "messages": [ { "role": "user", "content": "Your prompt here" } ], "model": "claude-3-opus-20240229", // Optional, provider-specific model name "tools": [...], // Optional, tools for function calling "context": "System message or context" // Optional }

または (レガシー形式):

{ "prompt": "Your prompt here", "model": "claude-3-opus-20240229", // Optional "context": "System message or context" // Optional }

**レスポンス:**プロバイダーの API からの生のレスポンスを返します。

GET /tools/available

利用可能なすべてのツールの包括的なリストと詳細情報を取得します。

クエリパラメータ:

  • format - レスポンス形式: json (デフォルト)、 yamltable 、またはhtml
  • category - ツールをカテゴリ別にフィルタリングする(オプション)
  • enabled - 有効ステータスでフィルタリング: true (デフォルト) またはfalse
  • search - ツールを名前、説明、タグで検索します
  • provider - プロバイダー別にツールをフィルタリングします(例: openaigoogle
  • limit - 返されるツールの最大数(ページ区切り用)
  • offset - ページ区切りのオフセット(デフォルト: 0)

応答(JSON 形式):

{ "success": true, "count": 10, "metadata": { "categories": ["web", "image", "utility"], "providers": ["openai", "anthropic", "internal"], "totalCount": 24, "offset": 0, "limit": 10 }, "tools": [ { "name": "web_search", "description": "Search the web for information", "category": "web", "version": "1.0.0", "provider": "google", "enabled": true, "parameters": { "query": { "type": "string", "description": "The search query", "required": true }, "limit": { "type": "number", "description": "Maximum number of results", "required": false, "default": 5 } }, "usage": { "endpoint": "/tools/web/search", "method": "POST", "parameters": { /* same as above */ } }, "metadata": { "createdAt": "2023-10-15T12:00:00Z", "updatedAt": "2024-04-20T09:30:00Z", "usageCount": 1245 } } // ... more tools ] }
GET /health

サーバーが実行中の場合、ステータス 200 を返すヘルス チェック エンドポイント。

データ管理

データベースのバックアップ

データベースのバックアップを作成および管理できます。

# Create a full backup npm run backup-mongodb # Create a backup with execution history npm run backup-mongodb -- --with-executions # List existing backups npm run backup-mongodb -- --list
データベース接続のテスト

MongoDB の設定を確認するには:

# Run the database test script npm run test-mongodb

クライアントの例

コマンドラインクライアント

テストクライアントはsrc/client.jsに含まれています。実行するには、以下のコマンドを実行します。

node src/client.js
ウェブクライアント

サーバーが稼働中の場合、 http://localhost:3000でシンプルなウェブインターフェースが利用できます。これを使用して、ブラウザから直接 API をテストできます。

利用可能なツール

MCP サーバーは、ユーザーと AI エージェントが利用可能なすべてのツールをプログラムで一覧表示できるようにするツール検出エンドポイントを提供します。

ツールの発見

GET /tools/available - 利用可能なすべてのツールを詳細情報とともに一覧表示します。

  • 複数の形式をサポート: JSON、YAML、HTML、ASCII テーブル
  • カテゴリ、プロバイダー、検索用語によるフィルタリングを提供します
  • 各ツールの詳細なメタデータと使用例が含まれています

使用例:

# Get all tools in JSON format curl http://localhost:3000/tools/available # Get tools in a specific category curl http://localhost:3000/tools/available?category=web # Search for image-related tools curl http://localhost:3000/tools/available?search=image # Get a formatted HTML page of all tools curl http://localhost:3000/tools/available?format=html > tools.html

ウェブ検索ツール

サーバーには、Web 検索および取得ツールが組み込まれています。

  1. ウェブ検索( /tools/web/search )
    • 特定のクエリに関する情報をウェブで検索する
    • パラメータ: query (必須)、 limit (オプション)
    • 必要条件: GOOGLE_CSE_API_KEYおよびGOOGLE_CSE_ID環境変数
    • Google 検索が失敗した場合はBING_SEARCH_API_KEYにフォールバックします
  2. Webコンテンツ( /tools/web/content )
    • 特定のURLからコンテンツを取得して抽出する
    • パラメータ: url (必須)、 useCache (オプション)
  3. Web バッチ( /tools/web/batch )
    • 複数のURLからコンテンツを並列に取得する
    • パラメータ: urls (必須配列)、 useCache (オプション)

画像生成ツール

サーバーには、画像生成、編集、バリエーション ツールも含まれています。

  1. イメージの生成( /tools/image/generate )
    • テキストプロンプトに基づいて画像を生成する
    • パラメータ:
      • prompt (必須): 画像の詳細な説明
      • provider (オプション): openaiまたはstability (デフォルトはopenai
      • options (オプション): プロバイダー固有のオプション
  2. 画像編集( /tools/image/edit )
    • テキストプロンプトで既存の画像を編集する
    • パラメータ:
      • imagePath (必須): 編集する画像へのパス
      • prompt (必須): 行う編集の説明
      • maskPath (オプション): マスク画像へのパス
  3. 画像バリエーションを作成する( /tools/image/variation )
    • 既存の画像のバリエーションを作成する
    • パラメータ:
      • imagePath (必須): バリエーションを作成するための画像へのパス

**注:**これらのツールを使用するには、 .envファイルに API キーを設定する必要があります。

  • OpenAI画像の場合: OPENAI_API_KEY
  • 安定性AIイメージの場合: STABILITY_API_KEY
  • ウェブ検索の場合: GOOGLE_CSE_API_KEYGOOGLE_CSE_ID

AIモデルとのツール統合

MCPサーバーは、AIモデルによるツールの呼び出しと実行を自動的に処理します。モデルがツールの使用を決定すると、サーバーは次の処理を実行します。

  1. 指定されたパラメータを使用して要求されたツールを実行します
  2. ツールの応答をモデルに返します
  3. モデルはツールの応答を最終的な答えに組み込むことができる。
AIモデルのためのツール検出

AIモデルは/tools/availableエンドポイントを使用して、利用可能なツールとその使用方法を検出できます。これは特に以下の場合に便利です。

  • 実行中の動的なツール検出
  • AIエージェントの自己文書化
  • AIシステムが利用可能な機能に適応できるようにする

AI モデルのシステム プロンプトの例:

You have access to external tools through the MCP server. Before using any tools, you should check what tools are available by calling: GET /tools/available This will return a list of all available tools with their parameters and usage instructions. You can then use these tools by following the provided usage patterns.

ツールの使用例

ツールの使用方法を示すサンプル コードについては、 /examplesディレクトリを参照してください。

新しいプロバイダーまたはツールの追加

新しいAIプロバイダーの追加

新しい AI プロバイダーを追加するには:

  1. プロバイダーのSDKをプロジェクトに追加する
  2. server.jsに新しいハンドラー関数を作成する
  3. メインルートハンドラに新しいケースを追加する

新しいツールの追加

サーバーに新しいツールを追加するには:

  1. /src/toolsディレクトリに新しいツール実装を作成する
  2. ツール定義をtool-definitions.jsに追加する
  3. server.jsのツール実行関数を更新します
  4. ツールを直接使用するための新しい API エンドポイントを追加する (必要な場合)

ライセンス

ISC

-
security - not tested
F
license - not found
-
quality - not tested

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

一貫したインターフェースを通じて Anthropic や OpenAI などの複数の AI モデル プロバイダーとのやり取りを可能にし、チャットの補完、ツールの呼び出し、コンテキスト処理をサポートする統合 API サーバーです。

  1. 特徴
    1. インストール
      1. MongoDBのセットアップ
        1. オプション 1: 自動セットアップ (推奨)
        2. オプション2: 手動Dockerセットアップ
        3. オプション3: ローカルMongoDBインストール
        4. オプション4: MongoDB Atlas (クラウド)
      2. データベース移行
        1. 使用法
          1. サーバーを起動する
          2. PM2プロセスマネージャの使用
          3. APIエンドポイント
          4. データ管理
          5. クライアントの例
        2. 利用可能なツール
          1. ツールの発見
          2. ウェブ検索ツール
          3. 画像生成ツール
          4. AIモデルとのツール統合
          5. ツールの使用例
        3. 新しいプロバイダーまたはツールの追加
          1. 新しいAIプロバイダーの追加
          2. 新しいツールの追加
        4. ライセンス

          Related MCP Servers

          • -
            security
            A
            license
            -
            quality
            This server facilitates the invocation of AI models from providers like Anthropic, OpenAI, and Groq, enabling users to manage and configure large language model interactions seamlessly.
            Last updated -
            4
            Python
            MIT License
          • -
            security
            -
            license
            -
            quality
            An open standard server implementation that enables AI assistants to directly access APIs and services through Model Context Protocol, built using Cloudflare Workers for scalability.
            Last updated -
            TypeScript
          • -
            security
            F
            license
            -
            quality
            A modern AI service proxy that enables interaction with multiple AI providers (Anthropic Claude, OpenAI) through a unified API, deployed globally using Cloudflare Workers.
            Last updated -
            13
            TypeScript
          • A
            security
            F
            license
            A
            quality
            A Model Context Protocol server that enables AI assistants to interact with the Omi API for retrieving and creating conversations and memories for users.
            Last updated -
            4
            TypeScript

          View all related MCP servers

          ID: x9ucq0kwqj