MCP Prompt Tester

Integrations

  • Supports loading API keys and configuration from .env files, making it easier to set up and manage credentials for different providers

  • Enables testing prompts with OpenAI models, allowing configuration of system prompts, user prompts, and parameters like temperature and max_tokens

MCPプロンプトテスター

エージェントがさまざまなプロバイダーで LLM プロンプトをテストできるようにするシンプルな MCP サーバー。

特徴

  • OpenAIとAnthropicモデルによるテストプロンプト
  • システムプロンプト、ユーザープロンプト、その他のパラメータを構成する
  • フォーマットされた応答またはエラーメッセージを取得する
  • .env ファイルのサポートによる簡単な環境設定

インストール

# Install with pip pip install -e . # Or with uv uv install -e .

APIキーの設定

サーバーには、使用するプロバイダーのAPIキーが必要です。APIキーは2つの方法で設定できます。

オプション1: 環境変数

次の環境変数を設定します。

  • OPENAI_API_KEY - OpenAI API キー
  • ANTHROPIC_API_KEY - Anthropic APIキー

オプション 2: .env ファイル (推奨)

  1. プロジェクトディレクトリまたはホームディレクトリに.envという名前のファイルを作成します。
  2. 次の形式で API キーを追加します。
OPENAI_API_KEY=your-openai-api-key-here ANTHROPIC_API_KEY=your-anthropic-api-key-here
  1. サーバーはこれらのキーを自動的に検出して読み込みます

便宜上、サンプル テンプレートが.env.exampleとして含まれています。

使用法

stdio (デフォルト) または SSE トランスポートを使用してサーバーを起動します。

# Using stdio transport (default) prompt-tester # Using SSE transport on custom port prompt-tester --transport sse --port 8000

利用可能なツール

サーバーは、MCP 対応エージェントに対して次のツールを公開します。

1. list_providers

利用可能な LLM プロバイダーとそのデフォルト モデルを取得します。

パラメータ:

  • 不要

応答例:

{ "providers": { "openai": [ { "type": "gpt-4", "name": "gpt-4", "input_cost": 0.03, "output_cost": 0.06, "description": "Most capable GPT-4 model" }, // ... other models ... ], "anthropic": [ // ... models ... ] } }

2. テスト比較

複数のプロンプトを並べて比較し、さまざまなプロバイダー、モデル、パラメータを同時にテストできます。

パラメータ:

  • comparisons (配列): 1 ~ 4 個の比較構成のリスト。各比較構成には次の内容が含まれます。
    • provider (文字列): 使用する LLM プロバイダー ("openai" または "anthropic")
    • model (文字列): モデル名
    • system_prompt (文字列): システムプロンプト(モデルの指示)
    • user_prompt (文字列): ユーザーのメッセージ/プロンプト
    • temperature (数値、オプション): ランダム性を制御する
    • max_tokens (整数、オプション): 生成するトークンの最大数
    • top_p (数値、オプション):核サンプリングによる多様性の制御

使用例:

{ "comparisons": [ { "provider": "openai", "model": "gpt-4", "system_prompt": "You are a helpful assistant.", "user_prompt": "Explain quantum computing in simple terms.", "temperature": 0.7 }, { "provider": "anthropic", "model": "claude-3-opus-20240229", "system_prompt": "You are a helpful assistant.", "user_prompt": "Explain quantum computing in simple terms.", "temperature": 0.7 } ] }

3. マルチターン会話のテスト

LLM プロバイダーとのマルチターン会話を管理し、ステートフル会話の作成と維持を可能にします。

モード:

  • start : 新しい会話を開始します
  • continue : 既存の会話を継続します
  • get : 会話履歴を取得する
  • list : すべてのアクティブな会話を一覧表示します
  • close : 会話を閉じる

パラメータ:

  • mode (文字列): 操作モード ("start"、"continue"、"get"、"list"、または "close")
  • conversation_id (文字列): 会話の一意のID (続行、取得、終了モードで必要)
  • provider (文字列): LLM プロバイダー (開始モードに必須)
  • model (文字列): モデル名(開始モードに必須)
  • system_prompt (文字列): システムプロンプト(開始モードに必須)
  • user_prompt (文字列): ユーザーメッセージ(開始モードと継続モードで使用)
  • temperature (数値、オプション):モデルの温度パラメータ
  • max_tokens (整数、オプション): 生成するトークンの最大数
  • top_p (数値、オプション): Top-pサンプリングパラメータ

使用例(会話を始める):

{ "mode": "start", "provider": "openai", "model": "gpt-4", "system_prompt": "You are a helpful assistant specializing in physics.", "user_prompt": "Can you explain what dark matter is?" }

使用例(会話を続ける):

{ "mode": "continue", "conversation_id": "conv_12345", "user_prompt": "How does that relate to dark energy?" }

エージェントの使用例

MCP クライアントを使用すると、エージェントは次のようなツールを使用できます。

import asyncio import json from mcp.client.session import ClientSession from mcp.client.stdio import StdioServerParameters, stdio_client async def main(): async with stdio_client( StdioServerParameters(command="prompt-tester") ) as (read, write): async with ClientSession(read, write) as session: await session.initialize() # 1. List available providers and models providers_result = await session.call_tool("list_providers", {}) print("Available providers and models:", providers_result) # 2. Run a basic test with a single model and prompt comparison_result = await session.call_tool("test_comparison", { "comparisons": [ { "provider": "openai", "model": "gpt-4", "system_prompt": "You are a helpful assistant.", "user_prompt": "Explain quantum computing in simple terms.", "temperature": 0.7, "max_tokens": 500 } ] }) print("Single model test result:", comparison_result) # 3. Compare multiple prompts/models side by side comparison_result = await session.call_tool("test_comparison", { "comparisons": [ { "provider": "openai", "model": "gpt-4", "system_prompt": "You are a helpful assistant.", "user_prompt": "Explain quantum computing in simple terms.", "temperature": 0.7 }, { "provider": "anthropic", "model": "claude-3-opus-20240229", "system_prompt": "You are a helpful assistant.", "user_prompt": "Explain quantum computing in simple terms.", "temperature": 0.7 } ] }) print("Comparison result:", comparison_result) # 4. Start a multi-turn conversation conversation_start = await session.call_tool("test_multiturn_conversation", { "mode": "start", "provider": "openai", "model": "gpt-4", "system_prompt": "You are a helpful assistant specializing in physics.", "user_prompt": "Can you explain what dark matter is?" }) print("Conversation started:", conversation_start) # Get the conversation ID from the response response_data = json.loads(conversation_start.text) conversation_id = response_data.get("conversation_id") # Continue the conversation if conversation_id: conversation_continue = await session.call_tool("test_multiturn_conversation", { "mode": "continue", "conversation_id": conversation_id, "user_prompt": "How does that relate to dark energy?" }) print("Conversation continued:", conversation_continue) # Get the conversation history conversation_history = await session.call_tool("test_multiturn_conversation", { "mode": "get", "conversation_id": conversation_id }) print("Conversation history:", conversation_history) asyncio.run(main())

MCPエージェント統合

MCP 権限を持つエージェントの場合、統合は簡単です。エージェントが LLM プロンプトをテストする必要がある場合は、次の手順に従ってください。

  1. 検出: エージェントはlist_providersを使用して利用可能なモデルとその機能を検出できます。
  2. シンプルなテスト: 簡単なテストには、単一の構成でtest_comparisonツールを使用します。
  3. 比較:エージェントが異なるプロンプトやモデルを評価する必要がある場合、複数の構成でtest_comparison使用できます。
  4. ステートフルインタラクション: マルチターンの会話の場合、エージェントはtest_multiturn_conversationツールを使用して会話を管理できます。

これにより、エージェントは次のことが可能になります。

  • プロンプトのバリエーションをテストして、最も効果的なフレーズを見つけます
  • 特定のタスクのさまざまなモデルを比較する
  • 複数ターンの会話でコンテキストを維持する
  • 温度やmax_tokensなどのパラメータを最適化する
  • 開発中のトークンの使用状況とコストを追跡する

構成

環境変数を使用して、API キーとオプションのトレース構成を設定できます。

必要なAPIキー

  • OPENAI_API_KEY - OpenAI API キー
  • ANTHROPIC_API_KEY - Anthropic APIキー

オプションのLangfuseトレース

サーバーは、LLM呼び出しのトレースと監視のためにLangfuseをサポートしています。以下の設定はオプションです。

  • LANGFUSE_SECRET_KEY - Langfuse の秘密鍵
  • LANGFUSE_PUBLIC_KEY - Langfuseの公開鍵
  • LANGFUSE_HOST - LangfuseインスタンスのURL

Langfuse トレースを使用しない場合は、これらの設定を空のままにしておきます。

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

エージェントが OpenAI および Anthropic モデル間で LLM プロンプトをテストおよび比較できるようにする MCP サーバー。単一のテスト、並べて比較、および複数ターンの会話をサポートします。

  1. Features
    1. Installation
      1. API Key Setup
        1. Option 1: Environment Variables
        2. Option 2: .env File (Recommended)
      2. Usage
        1. Available Tools
      3. Example Usage for Agents
        1. MCP Agent Integration
          1. Configuration
            1. Required API Keys
            2. Optional Langfuse Tracing
          ID: z099g2zrvn