Skip to main content
Agents use your MCP server to complete tasks in your product, and they can fail in ways your server doesn’t report. Unclear tool descriptions, missing capabilities, and confusing responses can cause agents to make the wrong calls, attempt workarounds, or misinterpret results. These problems can leave tasks unfinished or lead to incorrect answers. Without a record of each call, it’s hard to tell what went wrong. Tracing your MCP server with Braintrust gives you that record: what each agent requested and what your tools returned. Braintrust’s agent, Loop, can then periodically analyze your traces and spot recurring problems. These findings appear in Braintrust as Patterns, with supporting traces and suggested next steps to help you fix the problems and improve your product.
A Pattern finding from synthetic MCP traffic showing ignored environment filters, affected calls, a suggested fix, and supporting trace evidence.

On the Patterns page, a finding identifies MCP queries returning unexpected staging data. Orange evidence highlights connect the finding to trace values and explain why they matter.

This guide shows you how to:

Trace MCP calls

MCP tracing records each call’s arguments, result, timing, and errors. It gives you a record of the interaction on your server, even when the agent’s conversation is unavailable.
1

Set up Braintrust

First, create a Braintrust account and a project for your MCP server. The project holds the traces you’ll investigate. You can also use an existing project.Next, install the Braintrust SDK for your server’s language:
To let the SDK send traces to your account, create a Braintrust API key and set it in the environment that launches your server:
2

Instrument your server

To send traces to your project, initialize a logger and enable auto-instrumentation before starting your server:
First, add a logger to your server’s entry file. Replace "mcp-traces" with the name of your Braintrust project:
Then, start your server with Braintrust’s import hook, which instruments servers built with the official MCP SDK:
Replace server.js with your server’s JavaScript entry file, or its compiled JavaScript output if you use TypeScript.
See the MCP tracing reference for supported libraries, versions, and tracing options.
3

Inspect a tool call

Restart the server and call a tool through your usual MCP client. In your project’s Logs, open the span named tools/call <tool name> and compare input with output.As an illustrative example, imagine your server has a query_requests tool. An agent requests production traffic with filter.environment set to "production", but the tool silently ignores the filter and returns staging data too. The call succeeds, and the agent misses the extra rows. Its trace would show:The trace doesn’t mark the unexpected staging data as an error, despite the production-only request. It preserves the request and response so you or Loop can identify the mismatch.
A traced query requests production traffic and includes agent intent, but its output contains a staging request.

A trace on the Logs page shows an MCP tool returning staging data for a production-only request.

There are two ways to view related MCP calls together:
  • Highlight related calls on the Logs page: For Streamable HTTP servers that use sessions, set Group by to mcp.session.id. Selecting a call highlights other calls from the same session in the table. This doesn’t merge them into one trace.
  • Nest calls in one trace: Have the client send trace context with each call. The server calls then appear as child spans under the client’s parent span in a single trace.
You can now inspect what your server returns for each request. Next, capture additional context to understand more about the tasks and difficulties behind those calls, or continue to Patterns to start investigating.

Capture additional context

This step is optional. Without additional context, you can still use Patterns to find problems in your traces.
In addition to tracing tool calls, you can collect context from the agents using your server. Knowing what they’re trying to accomplish and where they struggle can help you discover problems that may not be apparent in tool responses. You can let agents:
  • Describe their intent when making a tool call.
  • Send feedback about problems they encounter, including those they work around.

Agent intent

To understand the task behind a tool call, allow agents to specify their intent. For example, an agent might specify “Compare production latency before and after a deployment” when requesting performance data. To add an intent parameter to your tool call and verify that Braintrust records it, follow these steps:
1

Add an optional intent field

Extend your tool’s input schema with an optional telemetry.intent field for the agent to fill in:
This example uses the official TypeScript MCP SDK v2 and Zod. requestSchema is your existing Zod object schema and queryRequests is your existing MCP handler.
The wrapper forwards extra, the MCP request context, so your handler keeps access to request metadata, cancellation, and progress notifications. If your handler accepts only args, call queryRequests(args) instead.
Keep your tool’s existing inputs, description, and settings. Agents can omit intent, and your tool’s function continues to receive its existing inputs without telemetry.
2

Verify the recorded intent

An agent’s call can then include:
Call the tool with and without intent. Both calls should work. In the trace for the call with intent, check input.telemetry.intent.

Agent feedback

An optional send_feedback tool lets agents report unexpected results, confusing documentation, or missing capabilities, even when they find a workaround and complete the task. Loop can investigate these reports alongside ordinary tool calls, which can reveal problems agents didn’t notice.
1

Register a feedback tool

Add send_feedback to your instrumented server:
This example uses the official TypeScript MCP SDK v2 and Zod. Add the tool to your existing server instance.
With MCP tracing enabled, Braintrust records each feedback report and its context in the send_feedback call’s input.
2

Verify that feedback reaches Braintrust

Send a test report through your MCP client using the arguments below. The TEST label lets you exclude it from investigations of real usage.
In your project’s Logs, open the tools/call send_feedback span and confirm:
  • input.feedback contains the report.
  • input.context contains the tool name and arguments.
A traced send_feedback test call contains a report that a production query returned staging requests, alongside the tool name and query arguments.

On the Logs page, a send_feedback call records the reported problem, tool name, and query filter.

Find problems with Patterns

Patterns is in public preview and can change before reaching general availability.
Once your MCP server is sending traces to Braintrust, Loop can investigate them for recurring problems and save findings as Patterns, with supporting traces and suggested next steps. For example, in the production-filter scenario above, Loop might find repeated calls that returned staging data despite a production filter. The resulting Pattern would link to those calls so you could inspect the unexpected results and investigate why the filter was ignored.

Run an investigation

The steps below enable Patterns and add an investigation focused on MCP calls.
1

Enable Patterns

Open your project in Braintrust and select Patterns in the sidebar.
  • If Patterns is already enabled, continue to the next step.
  • Otherwise, click Enable Patterns. This creates and starts the default investigation for your project.
See Enable Patterns for setup details.
2

Create an MCP investigation

Go to Loop, click Automations > Create Loop automation, and name it MCP server issues.
3

Describe what to look for

In Instruction, describe what Loop should investigate. Use this prompt as a starting point and adapt it to your needs:
4

Configure the automation

Configure when Loop runs, which traces it investigates, and how it saves findings:
  • Frequency: Choose how often Loop should investigate your MCP calls.
  • Default query range: Choose how far back each investigation should look. For your first run, include a period when your MCP server received tool calls.
  • Write tool permissions: Select new_pattern and update_pattern so Loop can create findings and update existing ones.
Click Create to save the automation.
5

Run the investigation

Open the saved automation and click Run now. Select Past runs and open the new run to follow Loop’s investigation.
A completed Loop investigation of demo MCP calls confirms wrong-environment results in 112 of 132 calls and saves a Pattern with supporting traces.

On the Loop page, the investigation finds MCP queries returning unrequested data and saves a Pattern with supporting traces.

6

Review the results

Loop saves actionable findings as Patterns, with supporting trace evidence, and updates matching Patterns when they already exist. Review and act on these findings to investigate the problems and test improvements to your server.

Review and act on findings

During the run of a Loop automation, Loop investigates your MCP calls and saves findings as Patterns with supporting evidence. You can now review those Patterns, ask follow-up questions, and test changes to your server.
1

Review a finding

When the run finishes, open your project’s Patterns page.
The Patterns list shows a finding named Request queries ignore the environment filter, with its impact and wrong-output category.

The Patterns page lists recurring MCP problems and how often they occur, with each finding linking to supporting evidence.

Open a finding and follow its trace links to compare what agents requested with what your tools returned.
2

Explore the investigation

To see how Loop reached a finding or why it didn’t save one, go to Loop, click Automations, select your automation, open Past runs, and select the run. Read Loop’s summary to see what it investigated.From the run’s thread, you can continue the investigation or share it with others:
  • Click Fork to chat to continue the investigation with Loop. Ask it to explain the evidence or help plan a fix in a separate, editable chat.
  • Click Copy as Markdown to share the investigation with a teammate or give a coding agent context for a fix.
3

Make and test a change

Use the finding’s evidence and suggested fix to decide what to change in your server. For example, in this guide’s scenario, the query tool needs to respect the requested environment.After making the change:
  • Call the tool again through your MCP client, using the input shown in the trace. For example, for the scenario described in this guide, you’d request production data and confirm that no staging rows are returned.
  • Ask an agent to try the task again, then inspect its calls to see whether the change addresses the problem it encountered.
4

Watch for recurrence

As you release new versions of your MCP server, check that the problem doesn’t return:
  • Add an automated test to your MCP server’s test suite that checks the corrected behavior, so future changes don’t bring the problem back.
  • Review later traces and Patterns findings to see whether the problem still occurs in real usage.
  • Optionally, run an eval using representative tool calls and compare experiments to see how their results change between versions of your MCP server.

Next steps

With traces, intent, and feedback in Braintrust, you can keep investigating how agents use your server and use what you learn to improve it.