Est.

Structuring MCP Tool Schemas for Agent Trace Queries

Precise names, purposes, and input constraints keep agents from running wrong trace queries.

· 9 min read · Updated
Cover illustration for “Structuring MCP Tool Schemas for Agent Trace Queries”
Agent Debugging · October 15, 2026 · 9 min read · 2,089 words

The MCP tool schema decides what an agent can retrieve and reason over before any execution begins. A schema that underspecifies a tool's purpose, arguments, or return value produces wrong queries that still execute successfully, which makes schema quality the earliest and most consequential leverage point in a trace query system. The specific field choices, description patterns, and input constraints that make schemas reliable in production are learnable, concrete decisions.

At session start, an agent calls tools/list and the full schema, comprising name, description, and input schema, is injected into the model's context alongside the user's query. The model plans from that context alone: which tool to select, which arguments to supply, how to chain calls. A schema flaw therefore corrupts planning before execution begins. The underlying API can be perfectly healthy and the agent still misbehaves.

The empirical evidence bears this out. The Queen's University study of 856 tools across 103 MCP servers found that the vast majority of tool descriptions contain at least one smell, defined as a systematic underspecification, with more than half failing to state their purpose clearly. In a trace query server with several similar tools, an ambiguous purpose statement means the model will frequently pick the wrong one.

The stakes differ from a REST API or SDK integration in one specific way. With REST or SDK, the developer pre-selects endpoints. With MCP, the agent discovers and decides at runtime from the schema alone. The same agent code can connect to a different MCP server and route correctly because the capability description travels with the server, not the client. That runtime composability is the point, and it makes schema quality load-bearing in a way static API documentation never was.

What "smelly" schemas actually do to an agent querying traces

A poorly specified trace query schema does not produce an error. It produces a plausible-looking but wrong query, which is the harder failure to catch. The query executes, returns results, and the agent proceeds as though the answer were correct. The risk production monitoring platforms are built to catch is that this failure mode leaves no stack trace and no exception behind.

The literature operationalized by the Queen's University study identifies six components a tool description must carry: a purpose statement, parameter descriptions, constraints, preconditions, side effects, and a return value description. A trace query schema missing any of these gives the model partial information to plan on. Each absence compounds differently in the trace query domain.

When the purpose statement is missing, the agent selects the wrong tool from a set of similar trace-related tools. It picks a get_span tool when it should call query_trace_by_failure_type, and the resulting query answers a different question than the one posed. Missing parameter descriptions cause the agent to supply a session ID where a trace ID is required, or to omit a required time-range filter, producing an over-broad or empty result. Missing constraints lead the model to pass a timestamp in the wrong format or query a status field with a value outside the valid enum, causing silent filtering that returns zero results. Missing return value descriptions leave the model unable to interpret output correctly, so it either drops the result or passes it to the wrong downstream step.

The study surfaces a trade-off worth noting. Fuller is not always better. Compact variants that preserve reliability while reducing token overhead are often optimal, which means description design for trace query tools requires deliberate choices about what to include per component, not a blanket instruction to write more.

How to write tool names and purpose statements that guide correct tool selection

Tool name and purpose statement together form the first filter the model applies. If either is ambiguous, the model may select the wrong tool from a set of trace query tools before arguments even matter. Name design for these tools should encode action and object: query_traces_by_failure_type, get_span_by_trace_id, list_recent_agent_errors. Names like trace_tool or get_data communicate nothing the model can use.

A consistent verb vocabulary across the server gives the model a schema-level convention to reason from. Query_ signals multi-result retrieval, get_ signals single-record lookup, list_ signals enumeration. When two tools carry names that overlap in meaning, the model will sometimes pick the wrong one because both could plausibly apply to the same query.

Purpose statements must state what the tool does, for whom, and under what conditions. The statement "Returns trace data" fails this test. "Returns all spans for a single agent trace identified by trace_id, ordered by start time, including tool call inputs and outputs" passes it. Where multiple tools exist, such as one for single-trace lookup and another for cross-trace pattern search, the purpose statements must distinguish them explicitly. The model cannot infer boundaries it has not been told, and the study's finding that more than half of tool descriptions fail to state purpose clearly explains why this produces frequent misselection in servers with several trace-related tools.

Designing input schemas so the model supplies valid, complete arguments

The input schema is both a machine-readable contract and a prompt-like instruction. Each field's name, type, description, and constraint shapes the argument the model will infer and pass. Type-specific field names prevent the model from substituting one identifier type for another. A field named trace_id, not id, makes clear that a session ID, span ID, or user ID will not satisfy the query. When a trace query server has multiple type concepts, such as span type, error type, and failure type, a generic name like type guarantees confusion. Timestamp fields named start_time_utc and end_time_utc encode format expectation in the name itself.

Each argument description should state what value the field accepts, what it controls in the query, and what happens when omitted. For a failure_type field, the description might read: "Filters results to traces where the agent's tool call failed for this reason. Without this, the model either guesses an invalid value, producing zero results silently, or omits the field entirely and over-returns.

JSON Schema's constraint mechanisms map directly onto these failure modes. For ID fields where a wrong format is common, such as trace IDs that follow a UUID pattern, minLength, maxLength, or pattern constraints catch malformed values before they reach the server. Required fields should be marked explicitly rather than left for the model to infer.

Result-shaping parameters belong in the schema because the model needs them to paginate without repeated bad guesses. Tools that can return large result sets should expose limit, offset, and a sort_by field, with defaults and maximums stated in the field description: "Maximum 100. Defaults to 20 if omitted." The Queen's University finding on partial goal completion improvement from augmented descriptions supports this approach: specification at the field level is what lets the model complete a query correctly on the first attempt rather than iterating toward it.

When a model selects the wrong trace query tool because the purpose statement was ambiguous, the failure appears in production as a missed issue or a query against the wrong failure type. Traditional error monitoring misses this misbehavior entirely, but trace-level observability can detect it by comparing the agent's actual tool selections against what its instructions required it to do. Lemma performs this comparison, auditing every trace against what the agent was supposed to do.

Where trace context belongs — and why it must not pollute tool arguments

Adding telemetry fields directly to tool input parameters is a common design mistake. Observability metadata travels elsewhere. The correct channel already exists. Per the MCP specification, the _meta field of the tools/call request carries who made the call, which model, under which trace, alongside traceparent. Keeping this metadata out of the inputSchema preserves clean, reusable tool definitions while maintaining full attribution.

The Google Cloud Toolbox pattern demonstrates what this separation enables. None of these attributes appear in the tool's inputSchema. The four client-supplied attributes are populated from the MCP request's params._meta field, and Toolbox SDKs that support this meta field populate client attributes, including client.name and client.version, automatically.

The result is a single end-to-end trace connecting the tools/call on the client to the MCP server to the SQL statement in database logs, all correlated under one traceparent. A DBA or engineer can click from an agent prompt to the exact query plan it caused without joining logs by timestamp or adding custom middleware. The practical test for schema cleanliness follows directly: if a field in inputSchema does not change what the tool queries or returns, it belongs in _meta.

Structuring return value descriptions so the model correctly interprets trace query output

The return value description is the most commonly omitted section of a schema, and its absence shifts a critical burden onto the model. A schema that specifies inputs precisely but leaves output structure undescribed forces the model to infer what the result means, which produces inconsistent downstream behavior even when the query succeeds. The model must know whether the response is a list of spans, a summary object, or a paginated envelope.

The semantics of key fields matter in trace query output. Whether status: "completed" means the agent succeeded or merely that the tool call finished, regardless of whether the agent's intent was fulfilled, changes how the model reasons about the result. The same holds for empty results: the description must distinguish no matching traces from a query that was not executed. Partial results require the same clarity so the model knows to paginate rather than treat a truncated set as complete. Missing return descriptions create an observability gap. Without a clear return value contract, the pipeline cannot detect that discrepancy.

The practical technique is to treat the return value description as a miniature data dictionary, one sentence per top-level field stating its type, its meaning, and any values requiring special handling. This is the compact, deliberate specification the Queen's University study points toward: enough detail to let the model interpret output correctly without bloating the schema into a documentation site. Lemma performs this audit to surface when schema-guided planning went wrong silently.

Keeping tool scope narrow so trace queries do not become a security exposure

A trace query MCP server with an overly broad schema exposes internal system structure even when the server is read-only. Tool names, parameter names, and resource paths function as reconnaissance for an attacker. A tools/list response alone can reveal internal service names, data model field names, environment identifiers, and the existence of systems the organization has not disclosed. The schema itself becomes a recon artifact before any tool is called.

Scope discipline operates at the schema level. The inputSchema of each tool should be audited against the underlying data store permissions, asking whether the query the tool can construct reaches more data than the schema implies. Read tools should be separated from write or mutation tools, and not co-located on the same server unless the permission model explicitly distinguishes them.

The compounding risk of overprivilege is specific to trace data. Traces often contain full tool call inputs and outputs, which can include credentials, user PII, or internal configuration passed as arguments. A trace query tool with no field-level filtering exposes all of that to any agent that can call it. Schema design is what governs this attack surface, which makes narrow tool scope not a separate security concern but a direct consequence of the same decisions that determine what an agent can query.

Testing schema quality before agents reach production

Schema validity is a precondition for trace query reliability, and it is testable before deployment. This makes it one of the few failure modes in agentic systems that engineering discipline can eliminate at the source. The first two are what CI catches before production.

Tool selection accuracy is a discrete, automatable check. Return value interpretation tests whether the model's downstream behavior changes correctly when the response is empty, partial, or paginated. All three cases should be tested explicitly.

Completeness checks address a failure mode that arises in production MCP systems: the model claims a tool call the server never received. A completeness check correlates model-side intent against server-side receipts and flags the gap. These hallucinations are invisible to schema validation, because the schema was never invoked, which is why they fall outside the CI boundary.

What CI cannot catch, production monitoring must. It groups recurring failures into actionable issues without requiring engineers to predefine every failure mode. Schema testing catches what can be anticipated. The post-deployment audit exists because poorly specified trace query schemas produce plausible-looking but wrong queries that execute successfully, with no error and no exception, just incorrect reasoning.

Sources

  1. Model Context Protocol (MCP) Tool Descriptions Are Smelly! Towards Improving AI Agent Efficiency with Augmented MCP Tool Descriptions
  2. MCP Servers: The New Shadow IT for AI in 2026
Filed underAgent Debugging

More in Agent Debugging