The Dynatrace MCP server lets a coding assistant query production observability data while it reads your repository. That detail changes the nature of an investigation: the assistant no longer guesses where the slowness is from the source code alone; it sees it in the traces, metrics and detected problems, then works back to the lines involved.
Without that link, a developer juggles two worlds. On one side, the editor, where an assistant suggests plausible refactorings; on the other, the observability console, where the facts are. Translating between the two is done by hand, often under the pressure of an incident.
This article offers a repeatable five-step method for going from symptom to fix with an assistant connected to the Dynatrace MCP server and, above all, for checking that the fix actually had the expected effect.
What the Dynatrace MCP server brings to a coding assistant
An MCP server exposes tools that a model can call (the principle is explained in our Model Context Protocol guide). The Dynatrace one gives access to platform context: open problems, entities and their relationships, data queryable with DQL in Grail, process and host metrics. The assistant can therefore discover an entity, follow its dependencies and retrieve the relevant measurements without you writing the query yourself.
Dynatrace also publishes skills: ready-made instructions that explain to an agent how to query the platform efficiently, which entity types exist and how to verify a fix. The server opens access; the skills guide the approach.
An important point if you have followed older tutorials: the open source local server (dynatrace-oss/dynatrace-mcp, launched via npx) is now deprecated. Dynatrace recommends the remote MCP server, hosted in your SaaS environment and described in the official Dynatrace MCP server documentation. That is the one we use below.
A typical scenario: latency rising for no obvious reason
Let us take a deliberately ordinary example. An orders API, written in Python, normally responds in 300 ms. Since the last release, the 95th percentile has exceeded 4 seconds on the endpoint that lists a customer’s orders. The code has barely changed: a “delivery address” field was added to the response. Dynatrace has opened a response time degradation problem on the service.
The code review found nothing alarming. This is exactly the kind of situation where an assistant that only sees the code will go round in circles, and where production data makes the difference.
In practice
Step 1 — Connect the assistant to the MCP server
The remote server is reached via a URL, over HTTP transport, with a platform token in the authorisation header. In a host that accepts a JSON configuration, it looks like this (the root key, servers or mcpServers, depends on the host; the exact URL is given in the documentation):
{
"servers": {
"dynatrace-mcp": {
"url": "https://YOUR-ENV.apps.dynatrace.com/platform-reserved/mcp-gateway/v0.1/servers/dynatrace-mcp/mcp",
"headers": {
"Authorization": "Bearer <PLATFORM_TOKEN>"
}
}
}
}
The token must carry the permissions for accessing the MCP gateway (mcp-gateway:servers:invoke and mcp-gateway:servers:read at the time of writing), plus the Grail read permissions needed for the target data, for example storage:spans:read. Create a dedicated, read-only token with an expiry date; the reasons are detailed in our article on securing an MCP server. Once connected, check that the assistant does list the Dynatrace tools before going further.
Step 2 — Start from the symptom, not the hypothesis
Phrase the first question based on what you observe, without steering the assistant towards a supposed cause:
Which Dynatrace problem is open on the api-commandes service?
Since when, and which endpoints are most affected?
Let the assistant identify the entity, the problem and the time window. Ask it to quote the period and the figures it relies on.
Step 3 — Drill down to the expensive calls
Next, ask what makes up the response time: database calls, outgoing calls, CPU time. To check the answer, nothing stops you from running an equivalent query yourself in a Notebook. For example, to count the SQL queries issued by the service:
fetch spans, from: now() - 2h
| filter service.name == "api-commandes"
| filter isNotNull(db.query.text)
| summarize appels = count(), duree_moy = avg(duration), by: { db.query.text }
| sort appels desc
| limit 10
Adapt the exact field name (db.query.text or db.statement depending on the instrumentation) to your data. In our scenario the result is clear-cut: the same SELECT query on the addresses table runs dozens of times per call to the endpoint.
Step 4 — Link the measurement to the code
This is where the coding assistant really comes into its own: it has both the observed SQL query and the repository. Ask it to find the place that issues it. It identifies a loop that loads each order’s address one by one, the classic “N+1” problem:
# Before: one query per order
for commande in commandes:
commande.adresse = db.fetch_one(
"SELECT * FROM adresses WHERE id = %s", (commande.adresse_id,)
)
# After: a single query for all orders
ids = [c.adresse_id for c in commandes]
adresses = db.fetch_all("SELECT * FROM adresses WHERE id = ANY(%s)", (ids,))
par_id = {a.id: a for a in adresses}
for commande in commandes:
commande.adresse = par_id.get(commande.adresse_id)
Review the fix like any other contribution: the assistant proposes, you approve.
Step 5 — Check the effect after deployment
A fix is only finished when production confirms it. After deployment, ask the MCP server the same question again: number of SQL queries per call, 95th-percentile response time, problem status. If the curve does not move, the cause was elsewhere and the investigation resumes with new data rather than a hunch.
Best practices
- Require every statement from the assistant to come with the period and the measured values.
- Cross-check important conclusions with a DQL query you run yourself.
- Use a personal or team token, read-only, with an expiry date.
- Keep control of any production action: the assistant proposes, a human applies.
- Monitor query and token consumption: a chatty investigation has a cost.
- Keep the useful conversation in the incident ticket for the post-mortem.
Frequently asked questions
Can the Dynatrace MCP server change my production?
Its main use is reading data. The effective permissions depend on the token you give it: grant only read permissions for this kind of use.
Which coding assistant should I use?
Any MCP-compatible host can work. Dynatrace also offers dedicated integrations, such as the plugin for Cursor or a Copilot Studio agent in Teams.
Do I need to know DQL to benefit?
Not to get started: the assistant builds the queries. But being able to read a DQL query helps a lot when checking what it actually queried.
Conclusion
The Dynatrace MCP server does not replace the developer’s judgement: it removes the manual translation between the console and the editor. By starting from the measured symptom, linking the measurement to the code and then checking the result in production, you turn a hunch into a short, controllable fix loop. To complete the approach, trace these exchanges too, as we show in observing MCP agents with OpenTelemetry.
Further reading: From symptom to fix in minutes: AI-assisted development with Dynatrace MCP (Dynatrace blog).
span.observer is an independent community blog, not affiliated with Dynatrace LLC or the projects mentioned. The trademarks mentioned belong to their respective owners. Tools evolve quickly: check commands and options in their official documentation.
1 comment