Below is a pragmatic, end-to-end recipe you can adapt for evaluating LLM agents that (a) can call external tools/functions and (b) exchange data through the Model-Context Protocol (MCP) or any comparable “tool-calling” wrapper (OpenAI functions, Anthropic “actions”, LangChain’s tool schema, etc.).
- Clarify what “good” looks like
| Metric family | Why it matters | Typical measurement |
|---|
| Task success / correctness | Core utility | Exact-match, F1, ROUGE, or rubric score of the final answer returned by the agent |
| Valid-tool-call rate | Robustness | % of calls whose name & args match the tool’s JSON schema |
| Tool-use efficiency | Latency / $$ | (Actual calls − Optimal calls) / Optimal calls; total latency or token cost |
| Recovery from errors | Resilience | % of runs where the agent corrects a bad call without user help |
| Hallucination / safety | Trust | % of factual hallucinations, policy violations, or toxic content in the final answer |
Tip: Decide which metric is the “gate” metric (usually success rate); others can be “health” metrics you track but don’t necessarily block deployment on.
- Create benchmark tasks that truly require the tools
• “Unit” tasks – isolate one tool
– Calculator: “What’s 17 × 29 × 3?”
– Weather API: “Will it rain in Paris tomorrow?”
• “Integration” tasks – multiple tools + reasoning
– “Find me a 3-hour flight on Friday that lands before sunset in the destination city. Then tell me if I need an umbrella.” (Search → Flight API → Weather API → Reason)
• “Edge-case” tasks – adversarial or ambiguous input
– Provide malformed JSON in the question, ask agent to recover
– Ask for restricted info to trigger policy checks
Recommendation: 30–50 well-curated tasks already catch most regressions; add more as you discover blind spots.
- Build an evaluation harness around MCP
Below is a minimal Python pseudocode sketch. Swap in your favorite framework (pytest, LangSmith, OpenAI Evals, Trulens, etc.).
from mcp import AgentRunner # your wrapper around MCP chat completions
from eval_utils import compare_json # custom matcher for tool calls
def run_case(case):
agent = AgentRunner(tools=[calculator, weather]) # tool registry per MCP
trace = agent.run(case["user"])
return trace
def score_case(case, trace):
# 1. Check final answer
final_pass = rubric_grade(trace.final_answer, case["expected_answer"])
# 2. Check tool calls (order and args)
tool_pass = compare_json(trace.calls, case["expected_calls"])
# 3. Collate metrics
return {
"task_pass": final_pass,
"tool_ok": tool_pass,
"num_calls": len(trace.calls),
"invalid_calls": sum(1 for c in trace.calls if not c.valid)
}
Key implementation details
• The “trace” should record every MCP message: {"role": "tool", "name": ..., "arguments": ...}
• You can stub the real APIs with deterministic mock functions so the test is offline & repeatable.
• Save traces (JSONL) for quick diffing when something regresses.
- Automate evaluation in CI / nightly builds
- Pull current checkpoint (or call the hosted model).
- Run all benchmark cases: produce a metrics JSON.
- Throw the metrics into a dashboard (Weights & Biases, Grafana, BigQuery) and set red/yellow/green thresholds.
- Block merge / deployment if the gate metric drops by > N percentage points.
- Interpret results & iterate
| Scenario | Likely root cause | Next steps |
|---|
| High correctness, but many extra tool calls | Over-retrieval, lack of termination rule | Penalize over-calling in the prompt; give cost feedback |
| Invalid JSON args | Schema too strict, or unclear examples | Add more “few-shot” examples in MCP system prompt |
| Passes unit tasks, fails integration | Weak planning | Provide ReAct or MRKL style chain-of-thought examples; maybe teach the agent to “think step-by-step” |
| Frequent hallucinations | Missing retrieval step or doc grounding | Add search tool; enforce citations; add system rule against unsupported claims |
- Optional: advanced / scaled-up evaluation
• Monte-Carlo “traffic replay”: Feed anonymized real user logs through the candidate agent and compare outputs.
• Self-critique: After each run, let the agent judge its own answer; correlate self-scores with human scores.
• AgentBench / ToolBench style arenas: compete the new agent against a baseline across dozens of tasks; measure Elo.
• Safety probes: Red-team prompts, refusal testing, or policy compliance checks, run through the same harness.
👉 Quick checklist
☑ Define success & secondary metrics
☑ Craft tasks that actually need the tools
☑ Log every MCP message (request + response)
☑ Mock the tools → deterministic, cheap tests
☑ Automate scoring, set thresholds, gate releases
☑ Grow the benchmark as new failure modes appear
Feel free to adapt any part of the pipeline (scoring rubric, trace schema, frameworks). The crucial piece is to treat tool calls as first-class outputs—you verify them just like you verify the final natural-language answer. Once that feedback loop is solid, your LLM agent + MCP tool ecosystem will evolve with far fewer surprises.