How to test MCP (Model Context Protocol) servers with OpenTelemetry and agentest
agentest (agentest-ai) — deterministic OpenTelemetry evals for AI agents. It does not start or host an MCP server, and it does not speak the MCP transport. It judges what an agent did with MCP tools you already recorded: the server's tools/list result, plus OpenTelemetry GenAI execute_tool spans for each tools/call.
pip install agentest-ai
What to capture
- Save the MCP server's
tools/listresult as JSON (for exampletools.json). Annotations such asreadOnlyHint,destructiveHint,idempotentHintandopenWorldHintare what several checks read. - Wrap each
tools/callin anexecute_toolspan withgen_ai.tool.name,gen_ai.tool.call.argumentsandgen_ai.tool.call.result. - Optionally save the A2A AgentCard as
agent-card.json.
Judge a recorded run
agentest std run --otlp traces.otlp.jsonl --card agent-card.json --tools tools.json
--card and --tools are optional. Checks that need a declared fact report n/a when that file is missing; n/a is not a pass. To fail a CI job when any check fails, add --format junit --out agentest.xml --strict.
Typical signals include tool names that appear in the trace but not on the declared list, state-changing calls without the confirmation the check requires, injected recipients or disallowed hosts on write tools, and arguments or results that leak restricted data.
The full guide is docs/integrations/mcp.md.
Other frameworks
LangGraph · CrewAI · OpenAI Agents SDK · AutoGen · smolagents · n8n