LLM integrations MCP tools for diagnostics
MCP tools for diagnostics
The Model Context Protocol connects a model inside an application to servers that give it tools; code mode turns the same tools into an API that the model writes code against, run in a sandbox.
My work
I designed and wrote MCP servers and tools that let agents troubleshoot databases and infrastructure: mostly for metrics, read-only database queries, and logs from Datadog and Coralogix.
How it is built
An example of the mechanism, not my servers themselves: two generalised layouts in one picture, a direct tool call as the specification describes it (top) and code mode as Cloudflare and Anthropic describe it (bottom). What a sandbox can reach is a property of the runtime that runs it.
While the database does not answer
unavailable
- The server returns an ordinary result with isError: true and a text on what happened: a failure of an API is a tool execution error, not an error of the protocol.
- The client should give such an error to the model: on a wrong argument the model can correct itself and try again with other parameters.
- A database that is down is not fixed by other arguments: what the tool would have returned stays unknown, and a conclusion can rest only on what was actually returned. 2
Components
Press a component to read what it does.
Model inside the host
The language model inside a host application. The host decides which tools it sees, and should let a person refuse a call.
MCP client one per server
A connector inside the host: each client talks to exactly one server.
Supervisor holds the keys
The code-mode runtime: gives the model one tool that runs code, runs it in a sandbox, and passes the sandbox’s calls on to the servers.
Sandbox no network
Runs the code the model wrote. Its only way out is through the APIs that stand for the connected servers.
MCP server narrow tools
Gives a few tools shaped like tasks, checks every input, and returns answers of bounded size.
Logs, metrics observability
Where the logs and the metrics are: in my work, logs in Datadog and in Coralogix. The tools read them as they read the database. Coralogix’s own MCP server queries only archive storage: a query for the last ten minutes can come back empty while the logs are there in Frequent Search.
Database read-only role
The system being diagnosed. The server reaches it with an account of its own, limited to what the tools need.
-
A tool call
The model picks a tool from those the server lists, and the host sends the call through the MCP client of that server. The host should let a person refuse a call.
In detail
A host application creates and manages several clients, each with a 1:1 relationship with one server. A server lists its tools with tools/list; a call is a tools/call request with the tool’s name and its arguments. The specification says there should always be a human in the loop with the ability to deny a tool call. 1
2 11 12 Where it breaks In the MCP specification, a tool’s annotations, such as "read-only", are hints: a client must treat them as untrusted unless they come from a trusted server. Text in a tool’s result can act as instructions too: in General Analysis’s July 2025 demonstration on a Supabase project of its own, a support ticket made a developer’s assistant, which ran SQL with service_role privileges that bypass row-level security, read the integration_tokens table and post it into the same ticket, where the customer who filed it could see it. Supabase writes that wrapping query results in warnings and trying LLM classifiers reduced the risk without removing it, and that agents should never be connected directly to production data.
-
The transport
The client talks JSON-RPC to the server: over the standard streams of a local process, or by HTTP posts to one endpoint. In the current revision every request carries everything it needs.
In detail
There are two standard transports: stdio, newline-delimited messages over the standard streams of a subprocess the client launches, and Streamable HTTP, where every message from the client is a new HTTP POST to a single MCP endpoint, and the server answers with JSON or an SSE stream. MCP is a stateless protocol in revision 2026-07-28: every request carries its own protocol version and capabilities. 1
3 4 Where it breaks A local HTTP server must check the Origin header of every connection and should listen on 127.0.0.1 only: otherwise a remote web page could reach it through DNS rebinding.
-
A narrow tool
The server runs a narrow, bounded query under an account of its own and returns what the model can read: a few tools shaped like tasks, not one for every endpoint.
My part I designed and wrote MCP servers and tools through which agents troubleshoot databases and infrastructure: mostly for metrics, for reading from databases (read-only) and for logs from Datadog and Coralogix.
In detail
Servers must validate all tool inputs, implement access controls, rate-limit tool calls and sanitise tool outputs. More tools do not always lead to better outcomes: a tool that merely wraps an API endpoint is a common error. For answers that could use up a lot of context, Anthropic recommends pagination, range selection, filtering or truncation, with sensible defaults. Datadog’s own MCP server works this way: it truncates long answers, most of its tools take max_tokens, and it forwards the caller’s credentials, so it cannot reach beyond what that user or service account can see. Datadog’s write tools stay hidden from all users until an organization administrator turns on MCP Write Access, which is off by default. Coralogix documents that a client gets every tool by default, and also when its toolset header names no toolset the server recognises. 2
5 9 13 14 15 16 17 Where it breaks The database account’s privileges limit what SQL a tool can run. Datadog Security Labs broke the read-only promise of the reference PostgreSQL MCP server, since archived, which wrapped every query in a read-only transaction: a COMMIT inside the query ended it. Their advice, in any case: a database user with restricted privileges. The same write-up adds that least privilege alone does not cover it: because the server took its connections from a shared pool, a session setting changed after that COMMIT, such as statement_timeout, could carry over to later calls on the same connection as long as it was not idle for 10 seconds, the default. ClickHouse’s own MCP server is read-only by default through ClickHouse’s readonly=1 setting, and its README calls its check for destructive statements a best-effort guard against accidents, not a security boundary: that is the ClickHouse user’s grants.
-
Code mode
In code mode the model is given one tool, which runs code, and a typed API generated from the same tools: it writes a program instead of calling the tools one by one.
My part The layer that runs the model’s code: part of it ready-made, part written by me.
In detail
Cloudflare’s Code Mode converts the MCP tools into a TypeScript API and asks the model to write code that calls it; the agent is presented with just one tool, which executes TypeScript code. Anthropic presents the servers as code APIs in a file tree, so that an agent loads only the definitions it needs: in its example the token usage went from 150,000 to 2,000. Cloudflare also applies Code Mode server-side: its MCP server for the whole Cloudflare API exports two tools, search() and execute(), in about 1,000 tokens, where an equivalent server without Code Mode would take 1.17 million. 6
7 10 Where it breaks If the whole typed API is put into the context, its definitions take the place the list of tools used to take.
-
The sandbox
The code runs in a sandbox cut off from the network: its only way out is through the APIs that stand for the connected servers.
In detail
In Cloudflare’s description the sandbox is totally isolated from the internet, and its only access to the outside world is through the TypeScript APIs representing its connected MCP servers. Cloudflare’s DynamicWorkerExecutor has globalOutbound null by default, which blocks outbound network access, and a timeout of 60,000 milliseconds by default. 6
7 8 Where it breaks Running code written by a model needs a secure execution environment with sandboxing, resource limits and monitoring: everything rests on it.
-
Bindings
A call the code makes through the API reaches the runtime that runs the sandbox, and the runtime passes it on to the right MCP server.
In detail
The APIs are backed by RPC calls back to the agent loop, where the Agents SDK dispatches each call to the appropriate MCP server; the sandbox gets only the bindings it is given. 6
8 Where it breaks What the sandbox can reach depends on the runtime: in a home-built one, that boundary has to be built and tested.
-
The result
By default only what the code logs or returns goes back to the model: loops, joins and intermediate data stay where the code ran.
In detail
With code execution, intermediate results stay in the execution environment by default: the agent sees only what the code explicitly logs or returns, and data not meant for the model can pass through without entering its context. 7
8 Where it breaks A run is held to its timeout, but not everywhere: Cloudflare’s executor in a browser frame cannot stop a synchronous loop that blocks the browser’s event loop.
Sources
- MCP 2026-07-28: Architecture
- MCP 2026-07-28: Tools
- MCP 2026-07-28: Transports
- MCP 2026-07-28: Streamable HTTP
- Anthropic: Writing effective tools for agents
- Cloudflare: Code Mode
- Anthropic: Code execution with MCP
- Cloudflare Agents: Code Mode API reference
- Datadog Security Labs: SQL injection in the Postgres MCP server
- Cloudflare: Code Mode MCP
- General Analysis: Supabase MCP can leak your entire SQL database
- Supabase: Defense in Depth for MCP Servers
- ClickHouse: MCP server for ClickHouse
- Datadog: Datadog MCP Server
- Datadog: Access Control for MCP
- Coralogix: MCP server setup
- Coralogix: MCP server limitations
Next story
Code Mode
A way to use MCP servers: their tools become a typed API, the model writes a short program against it, a sandbox runs the program, and by default only its output, its return value and its errors go back to the model.