← Blog

How to test an MCP server when the bug is in the tool description

An agent sees only your tool names, descriptions and schema, so test your MCP server through a real agent.

Rogerio ChavesRogerio Chaves · · Agents
How to test an MCP server when the bug is in the tool description

A common way to test an MCP (Model Context Protocol) server is unit tests on each tool function, plus the MCP Inspector to call a tool by hand. We did both on a small support desk server with three tools, find_ticket, update_ticket and open_ticket, and all five unit tests passed. Then we connected it to an agent and ran a test where a simulated customer opens with:

hey, ticket 4848 still isn't fixed and now our whole team is locked out. can you make it urgent?

The agent called find_ticket with "4848", but our ticket IDs look like ACME-4848, so the server answered {"found": false}. The agent told her it couldn't find the ticket, and in two runs it went on and opened a duplicate urgent one.

Nothing was wrong with the code: the model had read "Find a support ticket." and ticket_id: str, and it guessed.

Short answer: MCP server testing needs a real agent, because the agent doesn't read your code. It reads the tool names, descriptions and input schema your server sends. Let a simulated user talk to that agent, check every tool call and its arguments, and trace the same calls in production.

Why unit tests pass while the agent gets it wrong

A unit test calls find_ticket("ACME-4848") and checks the result. It can't tell you whether an agent will ever send ACME-4848, because the agent picks the tool and writes the arguments from what your server lists in tools/list. Our first version listed find_ticket as "Find a support ticket." and update_ticket as "Update a support ticket.", each with a bare ticket_id string.

Nothing in there says an ID starts with ACME-, or that update_ticket is the one to use when the customer already has a ticket. The MCP spec calls a tool description a "hint" to the model, and for the agent that hint is all it knows about your tools.

The MCP Inspector (npx @modelcontextprotocol/inspector) lists your tools and lets you call one by hand, which tells you the server runs. In the Inspector you pick the tool and type the arguments yourself, though, and that's the exact step the agent got wrong.

Drive a real agent with a simulated user

Our agent under test was a plain tool-calling loop on an OpenAI model. It starts the server over stdio with the official MCP Python software development kit (SDK), asks for the tools and hands them to the model as they come, so it knows nothing about tickets that the server didn't tell it.

A coding agent is an even better agent under test when your users reach your server from Claude Code. Scenario, our open-source library for testing agents with simulated users, has a Claude Code adapter in TypeScript that runs the real claude -p. That's how we test our own skills at LangWatch, the platform we build for testing and monitoring agents, with real Claude Code and the LangWatch MCP server set up (how we test agent skills with Scenario).

The test itself is a Scenario test under pytest, and the agent plugs in through a small adapter class. The scenario describes a customer whose whole team is locked out of single sign-on (SSO) and who only remembers the number from the email subject, and the simulated user plays her. A check function reads the tool calls after the agent's turns, and a judge reads the conversation. This is the test, trimmed a little:

class SupportAgent(scenario.AgentAdapter):
    async def call(self, input: scenario.AgentInput) -> scenario.AgentReturnTypes:
        return await support_agent(input.messages)  # our MCP tool-calling loop

def check_urgent_on_existing_ticket(state: scenario.ScenarioState):
    assert not state.has_tool_call("open_ticket"), "Opened a duplicate ticket"
    updates = state.tool_calls("update_ticket").inputs
    assert all(u["ticket_id"] == "ACME-4848" for u in updates)
    priorities = [u["priority"] for u in updates if u.get("priority")]
    assert priorities and priorities[-1] == "urgent", "Ticket not left at urgent"

@pytest.mark.agent_test
async def test_customer_escalates_ticket_by_number():
    result = await scenario.run(
        name="Customer escalates an open ticket by its number",
        description="Emma's whole team is locked out of SSO. She only remembers 4848 from the email subject.",
        agents=[
            SupportAgent(),
            scenario.UserSimulatorAgent(),
            scenario.JudgeAgent(criteria=[
                "The agent updates Emma's existing ticket instead of opening a new one",
            ]),
        ],
        script=[
            scenario.user("hey, ticket 4848 still isn't fixed and now our whole team is locked out. can you make it urgent?"),
            scenario.agent(), scenario.user(), scenario.agent(),
            check_urgent_on_existing_ticket,
            scenario.judge(),
        ],
    )
    assert result.success, result.reasoning

The judge's criteria are plain sentences, like "The agent updates Emma's existing ticket instead of opening a new one". You can run it like any other test, with uv run pytest -s tests/test_mcp_ticket.py. It failed every time against the first version of the server:

A failing Scenario run against the first version of the MCP server: the agent looks up ticket "4848", gets found false, opens a duplicate urgent ticket, and the check stops the test

With LANGWATCH_API_KEY set, each run also shows up in LangWatch under Agent Testing > Results, with the conversation and a View trace link on every turn. The screenshot below is from our docs and shows a different agent, a returns agent:

A failed scenario run in LangWatch: the criteria count, the conversation with the simulated user, and a View trace link on the turn

Fix the tool descriptions, then run the test again

We fixed it in the tool descriptions and schema. We gave the ticket ID a description and a pattern, and rewrote the docstrings to say update_ticket is for a customer who already has a ticket and open_ticket is only for one who doesn't. We also made an unknown ID raise a ToolError with a message the agent can act on. Before, a plain ValueError reached the agent as "Error executing tool update_ticket" and nothing more.

TicketId = Annotated[str, Field(
    description="The ticket ID, like ACME-4848. Customers often give only the number (4848): add the ACME- prefix.",
    pattern=r"^ACME-\d+quot;,
)]

@mcp.tool()
def find_ticket(ticket_id: TicketId) -> dict:
    """Look up one of the customer's existing support tickets by its ID."""

In the next run's log, the agent's first call was find_ticket({"ticket_id": "ACME-4848"}), then update_ticket on the same ID with "priority": "urgent":

The same Scenario test after the description fix: the agent looks up ACME-4848, sets it to urgent with a note, and the test passes

It went from failing every run to passing every run. We also tried the pattern alone, with no description text, and both runs passed, so the schema seems to count as much as the words. The five unit tests passed on every version:

Server versionScenario runsResult
First version: "Find a support ticket." and ticket_id: str4Failed all 4: looked up "4848", opened a duplicate ticket in 2
Description and pattern on ticket_id, docstrings that say when to use each tool8Passed all 8
Pattern on ticket_id, no description text2Passed both

Check the tool calls: was the right tool called, with the right arguments?

One passing run looked fine from the outside. The simulated customer's second message was "thanks, that's urgent enough for now", meaning leave it as it is. The agent then called update_ticket on ACME-4848 with "priority": "normal" and replied "I've added your comment to ACME-4848. The ticket remains urgent."

The judge read that conversation and passed it, and so did the first version of our check, which only asked whether some update had set urgent. But the ticket now said normal. The last line of the check above looks at the last priority the agent sent, and that's the line that catches it.

We tried to fix this one in the description too, with "Only when the customer asks for a different priority. Leave it out to keep the current one." on the priority argument. When we scripted that customer line into the test, it still happened in one run out of seven. That's why the check stays in the suite and runs on every change to the server.

How do I audit MCP tool calls in my organization?

Trace them on the server. Version 2 of the MCP Python SDK already creates an OpenTelemetry (OTel) span for every request, and a tool call shows up as tools/call update_ticket with the tool name in gen_ai.tool.name. As the SDK docs say, "Your server is already traced." For MCP observability you only add an exporter to a backend that takes the OpenTelemetry Protocol (OTLP) over HTTP. Ours sends to LangWatch (OpenTelemetry guide):

provider = TracerProvider(resource=Resource.create({"service.name": "acme-support-mcp"}))
provider.add_span_processor(SimpleSpanProcessor(OTLPSpanExporter(
    endpoint="https://app.langwatch.ai/api/otel/v1/traces",
    headers={"Authorization": f"Bearer {os.environ['LANGWATCH_API_KEY']}"},
)))
trace.set_tracer_provider(provider)

The client passes the trace context with each request, so the server's spans land inside the trace of the agent turn that made the call.

The SDK doesn't put the arguments on the span, though. We added a small decorator that sets them as the span's langwatch.input and langwatch.output. This is the trace of a later run where the agent set the ticket back to normal, as the LangWatch API returns it:

The LangWatch trace of one agent turn: the MCP server's tools/call update_ticket span sits under the agent span, with the input that set the priority to normal

None of this needs Scenario. The exporter lives in the server, so it sends the same tools/call spans, arguments included, for every call your agents make in production.

Get started

Put this into production with LangWatch.

Trace your agents, run evaluations, and turn failures into repeatable tests.

Frequently asked questions

How do I test an MCP server?
Run a real agent against it with a simulated user, and check its tool calls. In a Scenario test under pytest or vitest, a language model plays the user, a check function asserts which tools the agent called and with which arguments, and a judge reads the conversation. Unit tests and the MCP Inspector check your tool code. This checks the names, descriptions and schema the model reads.
How do I audit MCP tool calls in my organization?
Trace them on the MCP server. Version 2 of the MCP Python SDK creates an OpenTelemetry span for every tools/call. Export those spans over OTLP to LangWatch and each call lands in the same trace as the agent turn that made it. Put the arguments and the result on the span too, so the trace shows what the agent sent.
What is an MCP gateway and do I need one?
The MCP spec doesn't define one. It names gateways only as one kind of intermediary, next to load balancers and observability tooling, that can route and inspect requests on the HTTP transport. To audit the calls to your own server you may not need one, because the server's own spans can record every call. If your model calls already go through the LangWatch AI Gateway, its policy rules can refuse requests that name MCP servers you haven't approved.
Is the MCP Inspector enough to test an MCP server?
It's the right first check. The Inspector lists your tools and lets you call one by hand, and its CLI mode exits with code 5 when a tools/call returns isError, which makes a cheap smoke test in continuous integration (CI). It can't tell you whether an agent picks the right tool or sends the right arguments, because in the Inspector you pick them yourself.
Can I use Claude Code as the agent under test?
Yes. The Claude Code adapter in Scenario (TypeScript) runs the real claude -p binary inside a test, so skills, CLAUDE.md and permission prompts behave the way they do for your users. We test our own skills this way, with real Claude Code, the LangWatch MCP server and a simulated user.