Skip to main content

Evals System Architecture

The Evals system in MCPJam Inspector is a comprehensive testing framework designed to evaluate MCP (Model Context Protocol) server implementations. This guide provides a deep dive into the architecture, data flows, and key components to help you contribute effectively.

Overview

The Evals system allows developers to:
  • Run automated tests against MCP servers to validate tool implementations
  • Generate test cases using AI based on available server tools
  • Track results in real-time with detailed metrics and analytics
  • Compare expected vs actual behavior using agentic LLM loops

Key Features

  • Multi-step wizard UI for test configuration
  • Support for multiple LLM providers (OpenAI, Anthropic, DeepSeek, Ollama)
  • Real-time result tracking via MCPJamBackend
  • AI-powered test case generation
  • Agentic execution with up to 20 conversation turns
  • Token usage and performance metrics

Architecture Overview

The Evals system is composed of three main layers:

System Components

1. Client Layer (UI)

EvalRunner Component (client/src/components/evals/eval-runner.tsx)

The primary UI for configuring and launching evaluation runs. Architecture: 4-Step Wizard Step Details:
  1. Select Servers: Choose from connected MCP servers
    • Filters: Only shows connected servers
    • Validation: At least one server required
  2. Choose Model: Select LLM provider and model
    • Providers: OpenAI, Anthropic, DeepSeek, Ollama, MCPJam
    • Credential check: Validates API keys via hasToken()
  3. Define Tests: Create or generate test cases
    • Manual entry: Title, query, expected tool calls, number of runs
    • AI generation: Click “Generate Tests” to create 6 test cases (2 easy, 2 medium, 2 hard)
  4. Review & Run: Confirm and execute
    • Displays summary of configuration
    • POST to /api/mcp/evals/run

Results Components (client/src/components/evals/*)

Real-time display of evaluation results. Component Hierarchy:
Data Flow:

2. Server Layer (API)

Evals Routes (server/routes/mcp/evals.ts)

HTTP API endpoints for eval execution and test generation.
Endpoint: POST /api/mcp/evals/run
Request Schema:
Processing Flow: Key Functions:
  • resolveServerIdsOrThrow(): Case-insensitive server ID matching
  • runEvalSuiteWithAiSdk(): Executes eval suite in background using AI SDK
Endpoint: POST /api/mcp/evals/generate-tests
Request Schema:
Processing Flow:

Test Generation Agent (server/services/eval-agent.ts)

Generates test cases using backend LLM. Algorithm:
  1. Groups tools by server ID
  2. Creates system prompt with MCP agent instructions
  3. Creates user prompt with tool definitions and requirements
  4. Calls backend LLM (meta-llama/llama-3.3-70b-instruct)
  5. Parses JSON response
  6. Returns 6 test cases (2 easy, 2 medium, 2 hard)
LLM Prompt Structure:

3. CLI Layer (Execution Engine)

Runner (evals-cli/src/evals/runner.ts)

The core orchestrator that executes evaluation tests. Entry Points:
  1. runEvalsWithApiKey(): CLI mode with API key authentication
  2. runEvalsWithAuth(): UI mode with Convex authentication
Execution Flow: Agentic Loop (Local Models): Key Features:
  • Max 20 conversation turns to prevent infinite loops
  • Token usage tracking (prompt + completion)
  • Duration measurement
  • Tool call recording

Evaluator (evals-cli/src/evals/evaluator.ts)

Compares expected vs actual tool calls to determine pass/fail status. Logic:
Pass Criteria:
  • ✅ All expected tools must be called
  • ⚠️ Additional unexpected tools are allowed (marked but don’t fail)

RunRecorder (evals-cli/src/db/tests.ts)

Database interface for persisting evaluation results. Two Modes:
  1. API Key Mode (createRunRecorder): Uses CLI-based database client
  2. Auth Mode (createRunRecorderWithAuth): Uses Convex HTTP client
Methods:
Database Flow:

Data Models

Database Schema

TypeScript Interfaces


Integration Points

LLM Providers

The system supports multiple execution paths based on the selected model: Provider Configuration:
AI SDK Integration: The system now uses Vercel’s AI SDK (ai package) for LLM interactions:
  • generateText(): Single-step text generation with tool calling
  • createLlmModel(): Helper to create provider-specific model instances
  • Automatic tool call extraction and evaluation
  • Built-in token usage tracking

MCP Server Integration

Connection Workflow: Transport Support:
  1. STDIO: Command execution with stdin/stdout
  2. HTTP/SSE: Server-Sent Events
  3. Streamable HTTP: Custom streaming protocol

MCPJam Backend

Database Actions:

Contributing Guide

Adding a New LLM Provider

  1. Add AI SDK provider package:
  1. Update model creation in server/utils/chat-helpers.ts:
  1. Add to UI model list in shared/types.ts:

Adding a New MCP Transport

  1. Update MCPClientManager in sdk/ to support the new transport type:
  1. Implement transport connection logic in MCPClientManager:
  1. Ensure tool execution works with the new transport in getToolsForAiSdk()

Debugging Evals

Enable verbose logging:
Inspect MCP client:

Testing Changes

Test via UI:
  1. Start development server: npm run dev
  2. Navigate to “Run evals” tab
  3. Configure and execute test
  4. Check browser console for errors
  5. View results in “Eval results” tab
  6. Monitor server logs for execution details
Test server-side execution:

Common Issues

Issue: Test cases are not created
  • Check Convex auth token validity
  • Verify CONVEX_URL and CONVEX_HTTP_URL environment variables
  • Inspect browser network tab for failed requests
Issue: Tools are not being called
  • Verify server connection status in ClientManager
  • Check tool definitions in listTools() response
  • Ensure tool names match exactly (case-sensitive)
Issue: Backend LLM fails
  • Confirm /streaming endpoint is accessible
  • Check Convex auth token in request headers
  • Verify model ID format (@mcpjam/...)

Performance Considerations

Optimization Strategies

  1. Parallel Execution: Run multiple test cases concurrently
  2. Tool Batching: Execute independent tools in parallel
  3. Database Batching: Batch iteration updates
  4. Caching: Cache tool definitions between iterations

Metrics

Key performance indicators:
  • Average iteration duration: Time from start to finish
  • Token usage per iteration: Prompt + completion tokens
  • Tool execution time: Time spent in MCP calls
  • Database write time: Time to persist results
  • LLM response time: Time for each model call
Monitor these in the UI via helpers.ts aggregation functions.

Security Considerations

API Key Management

  • Never commit API keys to version control
  • Store keys in localStorage (client) or environment variables (CLI)
  • Use Convex auth tokens for backend models (no API key exposure)

Input Validation

All inputs are validated with Zod schemas:

Error Handling

  • Never expose internal errors to the client
  • Sanitize error messages before logging
  • Catch all exceptions in async functions
  • Validate all external inputs (LLM responses, tool results)

Future Enhancements

Potential areas for contribution:
  1. Parallel Test Execution: Run multiple test cases simultaneously
  2. Custom Evaluators: Support for user-defined pass/fail criteria
  3. Retry Logic: Automatic retry on transient failures
  4. Result Comparison: Compare results across different models
  5. Historical Analysis: Trend analysis of eval performance over time
  6. Export Results: Download results as CSV/JSON
  7. Shareable Suites: Share test configurations with team members
  8. Scheduling: Run evals on a schedule (cron-like)

Glossary


Resources


Questions?

If you have questions or need help contributing:
  1. Check the GitHub Issues
  2. Join our Discord community
  3. Read the main Contributing Guide