Original research · first public write-up

One MCP Tool Can Inject Your Database: The MCP Flaw Nobody Has Named

Same bytes, two channels, two trust levels. How schema-valid structuredContent reaches application sinks that the host's text-channel guard never covers. Executed against a real database and a real browser.

Mr-Akuma · November 28, 2026 · authorized research against a self-built target

Every team building on the Model Context Protocol has learned the same lesson: tool output is untrusted. A tool result might carry a prompt injection, so you quarantine it, label it, or run it past a guard before the model sees it. That lesson is right. The problem is that MCP tool results no longer have one output channel. They have two, and the lesson tends to get applied to only one of them.

Since the 2025-06-18 revision of the spec, a tool can return a typed structuredContent object next to the familiar free-text content array. The text gets treated as hostile. The structured object arrives schema-validated, so a host can treat it as data and write its string fields into application sinks: a SQL query, an HTML template, a shell argument, the arguments of the next tool call. Put the same payload in both channels and the text copy is quarantined while the structured copy flows to the sink.

The finding, stated precisely. It is not that MCP tool output is untrusted, nor that schema validation fails to sanitise. Both are established principles. The finding is the trust-boundary asymmetry a host creates when it applies security controls to the textual representation of a tool result but routes the schema-validated structured representation directly into application code. That second data-flow path lets attacker-controlled values reach application sinks without equivalent trust enforcement. As far as my prior-art sweep reaches, this specific combination of MCP channel separation, application-only artifact routing, and downstream sink exploitation is previously undocumented: I could not find it named anywhere, and I believe this is the first write-up to describe it. That is a first-look assessment, not a claim of exhaustive prior-art coverage.

Of the six findings in my MCP/A2A red lab, this is the only one that is both unreported before now and confirmed against real shipping code. In the lab it is N4, "structured-output laundering." This post walks it end to end, and everything claimed as an exploit below was actually executed, against a real SQLite engine and a real headless browser.

A validation stamp that travels with the payload

Structured output is a good feature. Downstream code gets machine-usable data instead of re-parsing prose. The spec tells clients to validate structuredContent against the tool's outputSchema, and it is careful to call that validation "a defense mechanism, not a security boundary." It checks shape, not safety.

Teams implement the validation, and it passes on the attack, because shape is all it checks:

# shape validation returns True for a SQL-injection payload
def validate_shape(obj, schema):
    for key in schema["required"]:          # name, note, account_tier: present
        if key not in obj: return False
    for key, spec in schema["properties"].items():
        if spec["type"] == "string" and not isinstance(obj[key], str):
            return False                    # note IS a string, so fine
    return True   # shape valid. says nothing about the value being an exploit.

This is where a feature becomes a vulnerability. "It validated" quietly turns into "it's clean." The text channel is treated as hostile because poisoned tool results are old news. The structured field shows up with a validation stamp, so its strings get concatenated into sinks without the sink-specific hygiene the text channel gets. The attacker simply puts the payload in the channel that is trusted because it validated.

Schema validation guarantees a value is shaped like a string. It says nothing about whether that string is safe to concatenate into SQL, HTML, or a shell. Treating the first as the second is the entire finding.

Two channels out of one result, going to different places

The host splits a single tools/call result into two channels. The text lands where injection defenses usually sit, in front of the model. The structured object is handed to application code as typed data. When the same payload rides both, the host's one injection control guards the channel everyone already distrusts and never sees the one that came with a schema pass.

tools/call result same payload, both channels content[].text to model + guards quarantined structuredContent schema-valid, to app code SQL + HTML sink the injection control sits on the text branch only

The text quarantine is unchanged in both modes. Only the structured branch reaches a sink, which is what isolates the asymmetry.

The channel split is real shipping code, pinned

To check whether the two channels really diverge in practice, I read the source of langchain-mcp-adapters, the most widely used MCP host adapter. They do. The exact references:

# langchain_mcp_adapters/tools.py @ cc0f2843 (v0.3.2)
# L277-283
artifact: MCPToolArtifact | None = None
if call_tool_result.structuredContent is not None:
    artifact = MCPToolArtifact(
        structured_content=call_tool_result.structuredContent)   # application-only
return tool_content, artifact                                    # tool_content -> model

# L533
response_format="content_and_artifact"

Under LangChain's content_and_artifact contract, a ToolMessage's content is returned to the model and its artifact is retained for application code and not sent to the model. So the structured copy bypasses the model-facing path by construction, which is exactly where a text-channel guard would sit.

Scope of this evidence. The adapter is not itself vulnerable. It faithfully routes two channels, which is correct behaviour. What the pinned source establishes is the routing: the structured copy reaches application code without passing through the model-facing path. Whether that value then hits an unsafe sink is a property of the consuming application, classified honestly below.

The architecture, end to end

Here is the whole path in one picture: three trust zones, the fork inside the host, and the two destinations. Follow the green lane and the red lane. The green lane (text) hits the prompt-injection guard and stops at the model. The red lane (structured) is validated for shape, wrapped as an application artifact, and crosses into application code and then into real sinks. The guard sits on the green lane only, so the red lane reaches the database and the browser with no equivalent check.

1 · Untrusted zone · MCP servers ticket store CRM enrichment tool attacker-controlled output trust boundary: server to host 2 · Host tools/call result two channels, same payload content[].text prompt-injection guard model text quarantined, stops here structuredContent (schema-valid) schema check: SHAPE only no sink sanitisation · no injection guard MCPToolArtifact → application code application-only, bypasses the model trust boundary: application code to sink does not reach sinks 3 · Application sinks reached by the structured lane SQL audit store DROP (executescript) · UNION exfil HTML dashboard stored XSS (fired) shell · file path · next tool's args potential, not demonstrated one connected server + one app sink = injection, with no human in the loop

The green lane is guarded and ends at the model. The red lane is only shape-checked and crosses two trust boundaries into real sinks. The host's single injection control sits on the lane the attacker does not use.

The exploit, actually executed

Showing that a payload appears in a constructed SQL string is not proof of injection, and building an HTML string that contains <script> is not proof the script runs. So the lab executes the laundered value against a real engine and reports what the engine did. Engine: Python's standard-library sqlite3, SQLite 3.50.4, in-memory. Browser: headless Chromium via Playwright. Reproduce with python -m attacks.n4_execution_evidence.

SQL: the engine semantics, stated honestly

SQLite matters here, and it is worth being exact, because the realised impact of the same laundered value depends on which execution API the consuming app used. Payload: Robert'); DROP TABLE audit;--.

Host patternAPIWhat actually happened (vuln mode)
A - batch audit writerexecutescript()DROP executed audit table present before, absent after. Destructive injection confirmed.
B - single lookup, same payloadexecute()DROP rejected driver raises OperationalError: near ")": syntax error. The strict single-statement API refuses the multi-statement payload.
B - single lookup, UNION payloadexecute()exfil executed zzz' UNION SELECT secret FROM admin_secrets -- returns the canary admin token.

That middle row is the honest part. Under SQLite's strict execute() API, the destructive multi-statement DROP does not run; the driver rejects it. That rejection is itself proof the value broke out of the string literal, which is a real injection at the syntax level. The destructive DROP is demonstrated against the executescript() pattern (which real batch and migration code does use), and confirmed data exfiltration is demonstrated against the strict execute() pattern with a single-statement UNION. Both are executed outcomes, not constructed strings.

# observed, vuln mode
[A] executescript()  tables_before=['admin_secrets','audit']  tables_after=['admin_secrets']   DROP executed
[B] execute() multi   OperationalError: near ")": syntax error                                  rejected (literal broke out)
[C] execute() union   rows_returned=['LABCANARY-7f3a-admin-token']                               exfil executed
laundered note from structuredContent schema-valid string via executescript() runs a multi-statement script DROP TABLE executed audit table gone via execute() · multi-stmt one statement per call rejected by driver literal broke out (syntax) via execute() · UNION single statement token exfiltrated LABCANARY admin token

Same bytes, three sink behaviours. The strict execute() API refuses the destructive multi-statement payload (middle), which is why the honest claim is DROP via executescript() and exfiltration via a single-statement UNION.

In hardened mode the structured field is bound as a parameter, not concatenated. The DROP never executes, audit stays intact, and the UNION payload returns no secret. Parameterisation closes both.

Stored XSS: executed in a real browser

The lab renders the vuln and hardened HTML in headless Chromium and checks a side effect, not a substring. The canary is harmless: it flips an in-page flag and rewrites one element's text. No cookie theft, no network.

payload: <script>window.__xss_fired=true;
         document.getElementById('sink').textContent='XSS-EXECUTED'</script>

vuln     render in Chromium  -> window.__xss_fired === true,  #sink text = "XSS-EXECUTED"   script fired
hardened html.escape(note)   -> window.__xss_fired undefined, #sink text = "pending"        inert

Demonstrated impact vs potential surface

Keeping these apart is what stops a reviewer from dismissing the whole finding because one claimed impact was overstated.

ImpactStatus
SQL injection - destructive (DROP)Demonstrated executed via executescript(); rejected under strict execute()
SQL injection - data exfiltrationDemonstrated executed via single-statement UNION under execute()
Stored XSSDemonstrated real Chromium execution
Shell / command injectionPotential not demonstrated
Path traversal / file-path injectionPotential not demonstrated
Downstream tool-argument injectionPotential needs downstream reproduction

Who gets hurt: the hosts that "solved" tool injection

The blast radius is every non-LLM sink fed from structuredContent. The cruel part is who is exposed. A team that did the recommended thing and hardened its text-output handling has put its one injection control on the exact channel the attacker avoids. The more disciplined a host is about tool text, the sharper the asymmetry.

Picture a support-desk agent wired to three MCP servers: a ticket store, a CRM, and a third-party enrichment tool a vendor shipped. The agent calls lookup_customer. The enrichment server returns a clean-looking text summary and a schema-valid structuredContent whose note field carries a UNION or a script. The host's prompt-injection guard scrubs the text and never sees the structured copy, which LangChain hands to the app as ToolMessage.artifact. If the app writes that note into a lookup query or a dashboard, the injection fires. Nobody approved anything, and the server responsible was a "read-only" lookup tool.

Threat model

The point of modelling this is to show it is a new gap, not just another output-handling bug. The control that would stop it already exists in the taxonomy ("treat tool return values as untrusted"). Hosts apply it to the text channel, and this finding lives in the structured one.

ElementDefinition
AttackerMalicious or compromised MCP server
Entry pointMCP tools/call response
Controlled dataStructured output string fields
Required host behaviorApplication consumes the structured artifact and writes it to a sink
Missing protectionSink-specific sanitisation on the structured channel
Security boundaryMCP server to consuming application
ImpactDepends on the downstream sink (see the demonstrated-vs-potential table)

Three attacker scenarios are worth separating, because they are not the same risk. First, a malicious MCP server controlling its own output. Second, a legitimate server that faithfully relays attacker-controlled external data, such as a scraped page or a ticket field, into its structured output; the server is a conduit, not the adversary. Third, a compromised server or supply-chain dependency whose structured output is now attacker-shaped.

STRIDEHow it shows up here
SpoofingA schema pass impersonates safety, so app code treats attacker data as its own.
TamperingThe payload alters the audit store, the DOM, or a downstream tool's arguments.
RepudiationThe sink is often the audit log itself, so forged or destroyed rows undermine the record of what happened.
Info disclosureStored XSS steals session tokens; SQLi reads rows the tool was never scoped to (demonstrated via the UNION exfil).
DoSDestructive SQL or expensive crafted payloads at the sink.
ElevationA read-only lookup server reaches write and execute through tool-argument injection in the app's context.

On the OWASP side, the realized impact is LLM05 (Improper Output Handling). MCP06 already mentions payloads "embedded in structured data fields," and this is the non-LLM-sink case of it. MCP03's mitigation, treat tool return values as untrusted, is exactly the control that ends up on the wrong channel. The categories exist and the mitigation is right. What is missing is enforcement on the second channel.

Severity is conditional, not universal

Because the impact depends on the consuming application, a single "High for everyone" rating would be wrong. Rate it by what the deployment actually does:

SeverityCondition
HighConfirmed unauthenticated or low-privilege path from a structured field to a sensitive SQL/HTML/shell sink.
MediumStructured data reaches application code, but a sink requires additional unsafe application behavior.
InformationalOnly the channel separation exists, with no exploitable sink identified.

The fix

Treat structuredContent as untrusted external input regardless of whether it passed output-schema validation. Schema validation stays on, as a structural integrity check, never as a sanitisation step.

  1. Preserve trust provenance. Mark structured tool results as externally controlled. A schema pass must never promote a value to trusted application data.
  2. Enforce sink-specific protections. SQL: parameterised queries. HTML: context-aware output encoding. Shell: argument arrays with allow-lists, no interpolation. File paths: canonicalise and enforce directory boundaries. Tool arguments: validate against the downstream tool's constraints before forwarding.
  3. Apply equal controls across channels. Give content, structuredContent, and any application-only artifact the same trust policy. Do not assume data is safe because it bypassed the model.
  4. Preserve provenance across handoffs. When structured data is passed between tools, agents, or components, keep its untrusted provenance rather than treating it as internally generated.
  5. Add regression tests. Feed identical malicious values through both output channels and assert neither reaches a sink without the appropriate protection.

Two honest caveats. First, the final step, an application sinking the structured artifact without sanitising it, depends on the application and is not a library guarantee. The routing asymmetry is confirmed in pinned shipping code; a full field exploit still needs a deployed app shown doing the unsafe sink. Second, the split is fragile. A server SDK mismatch (importing fastmcp instead of mcp.server.fastmcp) can fold structuredContent back into the model's text, and some teams re-append it on purpose. The asymmetry holds where the SDKs line up, which is the common case.

Clients already handle the second channel inconsistently. The MCP Inspector silently drops structuredContent when a tool returns both channels, and error results drop it entirely. That inconsistency is the soil this finding grows in.

Prior art, and where the gap is

I also checked a 540-entry LLM threat-coverage atlas mapped to OWASP, MITRE ATLAS and NIST. It has "treat tool outputs as untrusted data" and a 31-entry MCP domain, but no entry for structuredContent or output-schema trust. The generic rule is covered. The structured-channel laundering is not.

Where the evidence stands

The framing is first-of-its-kind: I found no prior work naming the gap between MCP's two output channels, stated as a first-look assessment rather than a priority claim. The routing is confirmed in pinned shipping code: langchain-mcp-adapters 0.3.2 routes the structured copy past the model to application code. The exploits are executed, not asserted from strings: a real DROP TABLE under executescript(), a real token exfiltration under execute(), a real script firing in Chromium, each with its hardened counterpart going inert. The SQLite multi-statement limit is stated honestly rather than glossed. The one link still owed is a deployed application caught sinking the artifact unsanitised. So this is not a proven field 0-day. It is a confirmed, exploitable asymmetry in how real hosts route tool output, with the realised impact scoped to the sink, and it is cheap to close today.