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 即时测试仪

一个简单的 MCP 服务器,允许代理使用不同的提供商测试 LLM 提示。

特征

  • 使用 OpenAI 和 Anthropic 模型进行测试提示
  • 配置系统提示、用户提示和其他参数
  • 获取格式化的响应或错误消息
  • 通过 .env 文件支持轻松设置环境

安装

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

API 密钥设置

服务器需要您所使用的提供商的 API 密钥。您可以通过两种方式设置这些密钥:

选项 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. 列表提供者

检索可用的 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 (字符串):操作模式(“开始”、“继续”、“获取”、“列出”或“关闭”)
  • 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 追踪

服务器支持使用 Langfuse 来跟踪和观察 LLM 调用。以下设置是可选的:

  • LANGFUSE_SECRET_KEY - 您的 Langfuse 密钥
  • LANGFUSE_PUBLIC_KEY - 您的 Langfuse 公钥
  • LANGFUSE_HOST - 您的 Langfuse 实例的 URL

如果您不想使用 Langfuse 跟踪,只需将这些设置留空。

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

MCP 服务器允许代理测试和比较跨 OpenAI 和 Anthropic 模型的 LLM 提示,支持单一测试、并排比较和多轮对话。

  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