# mcp-tool-output-hygiene-v1

> mcp-tool-output-hygiene-v1: 9 Keryn rules for python, typescript, javascript, go, java, csharp (9 warning).

Source: https://keryn.dev/rules/mcp-tool-output-hygiene-v1/

9 rules · Keryn Software Licence · rules 0.8.0 · [all packs](https://keryn.dev/rules/)

**How to read a rule**

- **Severity**: How bad the finding is if it is real: `error` fails a default gate, `warning` and `info` do not.

- **Confidence**: **P0** exploitable as written; **P1** dangerous in context; **P2** a heuristic or a posture check: confirm by reading the code.

- **False-positive risk**: **low**: an exact API or flag, so hits are almost always real; **medium**: the pattern is legitimate in many programs, so check each hit; **high**: it finds a lead to confirm, so expect benign hits.

- **Edge**: The relationship the finding sits on. **reaches**: content or traffic gets to a thing; **calls**: one thing invokes another; **reads**: one thing reads from another; **writes**: one thing writes to another; **sends**: data leaves for another party; **grants**: authority is given or left unchecked; **depends_on**: something relies on a component it does not verify; **trusts**: one party believes another without evidence. The boundary it crosses, when there is one: **user->prompt** (untrusted input reaching a prompt); **model->code** (model output reaching code, a shell, a query or a page); **secret->outside** (a secret leaving the trusted side); **supply-chain** (code, models or prompts pulled in from outside).

- **Taxonomy chips**: References for readers who work in OWASP LLM 2025, OWASP Agentic, CWE or NIST AI RMF. They say where a rule belongs, not that a framework is satisfied.

## keryn.mcp.py.tool-returns-credential-like-keys

`warning` python mcp, python, fastmcp

An MCP tool returns a dict whose key names a credential (api\_key, password, token, secret, ...) with a non-literal value; everything a tool returns lands in the model context, the client transcript and logs. Drop the field or return a redacted form such as the last four characters.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-200](https://keryn.dev/taxonomies/cwe/#cwe-200-exposure-of-sensitive-information-to-an-unauthorized-actor) [CWE-532](https://keryn.dev/taxonomies/cwe/#cwe-532-insertion-of-sensitive-information-into-log-file) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [ASI03](https://keryn.dev/taxonomies/owasp-agentic/#asi03-identity-and-privilege-abuse)

**Fix:** Do not put credentials in tool results. Return only the data the model needs; if a credential must be confirmed, return a boolean such as configured: true or a masked suffix.

**References:** [https://modelcontextprotocol.io/specification/2025-06-18/server/tools](https://modelcontextprotocol.io/specification/2025-06-18/server/tools) · [https://github.com/modelcontextprotocol/python-sdk](https://github.com/modelcontextprotocol/python-sdk)

## keryn.mcp.ts.tool-returns-credential-like-keys

`warning` typescript, javascript mcp, typescript, nodejs

An MCP tool handler returns an object whose key names a credential (apiKey, password, token, secret, ...) with a non-literal value; tool results flow into the model context, the client transcript and logs. Remove the field or return a masked or boolean form.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-200](https://keryn.dev/taxonomies/cwe/#cwe-200-exposure-of-sensitive-information-to-an-unauthorized-actor) [CWE-532](https://keryn.dev/taxonomies/cwe/#cwe-532-insertion-of-sensitive-information-into-log-file) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [ASI03](https://keryn.dev/taxonomies/owasp-agentic/#asi03-identity-and-privilege-abuse)

**Fix:** Do not put credentials in tool results. Return only the data the model needs; to confirm a credential exists, return a boolean or a masked suffix.

**References:** [https://modelcontextprotocol.io/specification/2025-06-18/server/tools](https://modelcontextprotocol.io/specification/2025-06-18/server/tools) · [https://github.com/modelcontextprotocol/typescript-sdk](https://github.com/modelcontextprotocol/typescript-sdk)

## keryn.mcp.py.tool-returns-fetched-content-unwrapped

`warning` python data-flow rule mcp, python, fastmcp, requests, httpx

An MCP tool returns the body of an outbound HTTP response to the client verbatim; whoever controls that page can plant instructions that the client model reads as tool output (indirect prompt injection). Wrap the content in an explicit untrusted-data delimiter and strip markup before returning it.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [reaches](https://keryn.dev/docs/edges/edge-kinds/#reaches) content or traffic gets to a thing; it crosses the [`user->prompt`](https://keryn.dev/docs/edges/trust-boundaries/#user-to-prompt) boundary (untrusted input reaching a prompt).

[CWE-74](https://keryn.dev/rules/?cwe=CWE-74) [CWE-1427](https://keryn.dev/taxonomies/cwe/#cwe-1427-improper-neutralization-of-input-used-for-llm-prompting) [LLM01](https://keryn.dev/taxonomies/owasp-llm/#llm01-prompt-injection) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling) [ASI01](https://keryn.dev/taxonomies/owasp-agentic/#asi01-agent-goal-hijack)

**Fix:** Treat fetched pages as data: strip HTML, truncate, and wrap the text in a clear untrusted-content envelope (for example &lt;untrusted\_content source=URL&gt;...&lt;/untrusted\_content&gt;) that the client prompt tells the model not to obey. Prefer returning extracted fields over raw bodies.

**References:** [https://modelcontextprotocol.io/specification/2025-06-18/server/tools](https://modelcontextprotocol.io/specification/2025-06-18/server/tools) · [https://github.com/modelcontextprotocol/python-sdk](https://github.com/modelcontextprotocol/python-sdk) · [https://modelcontextprotocol.io/docs/2025-11-25/tutorials/security/security_best_practices](https://modelcontextprotocol.io/docs/2025-11-25/tutorials/security/security_best_practices)

## keryn.mcp.ts.tool-returns-fetched-content-unwrapped

`warning` typescript, javascript data-flow rule mcp, typescript, nodejs

An MCP tool handler returns the body of an outbound HTTP response (fetch or axios) verbatim; whoever controls that page can plant instructions that the client model reads as tool output (indirect prompt injection). Wrap it in an untrusted-data envelope and strip markup first.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **medium**: the pattern is legitimate in many programs, so check each hit.

Edge inspected: [reaches](https://keryn.dev/docs/edges/edge-kinds/#reaches) content or traffic gets to a thing; it crosses the [`user->prompt`](https://keryn.dev/docs/edges/trust-boundaries/#user-to-prompt) boundary (untrusted input reaching a prompt).

[CWE-74](https://keryn.dev/rules/?cwe=CWE-74) [CWE-1427](https://keryn.dev/taxonomies/cwe/#cwe-1427-improper-neutralization-of-input-used-for-llm-prompting) [LLM01](https://keryn.dev/taxonomies/owasp-llm/#llm01-prompt-injection) [LLM05](https://keryn.dev/taxonomies/owasp-llm/#llm05-improper-output-handling) [ASI01](https://keryn.dev/taxonomies/owasp-agentic/#asi01-agent-goal-hijack)

**Fix:** Treat fetched pages as data: strip HTML, truncate, and wrap the text in a clear untrusted-content envelope that the client prompt tells the model not to obey. Prefer returning extracted fields over raw bodies.

**References:** [https://modelcontextprotocol.io/specification/2025-06-18/server/tools](https://modelcontextprotocol.io/specification/2025-06-18/server/tools) · [https://github.com/modelcontextprotocol/typescript-sdk](https://github.com/modelcontextprotocol/typescript-sdk) · [https://modelcontextprotocol.io/docs/2025-11-25/tutorials/security/security_best_practices](https://modelcontextprotocol.io/docs/2025-11-25/tutorials/security/security_best_practices)

## keryn.mcp.py.client-plain-http-transport

`warning` python mcp, python, client

An MCP client transport connects to a non-loopback http:// URL, so tool calls, results and any bearer token cross the network unencrypted and can be read or rewritten in transit. Use https://; keep http only for localhost.

Confidence **P1**: dangerous in context. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [sends](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party; it crosses the [`secret->outside`](https://keryn.dev/docs/edges/trust-boundaries/#secret-to-outside) boundary (a secret leaving the trusted side).

[CWE-319](https://keryn.dev/rules/?cwe=CWE-319) [CWE-300](https://keryn.dev/rules/?cwe=CWE-300) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI07](https://keryn.dev/taxonomies/owasp-agentic/#asi07-insecure-inter-agent-communication) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Point the transport at an https:// endpoint with a valid certificate. Plain http is acceptable only for loopback development servers.

**References:** [https://modelcontextprotocol.io/specification/2025-06-18/basic/transports](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports) · [https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization) · [https://github.com/modelcontextprotocol/python-sdk](https://github.com/modelcontextprotocol/python-sdk) · [https://pypi.org/project/mcp/1.12.0/](https://pypi.org/project/mcp/1.12.0/) · [https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/src/mcp/client/streamable_http.py](https://raw.githubusercontent.com/modelcontextprotocol/python-sdk/main/src/mcp/client/streamable_http.py)

## keryn.mcp.ts.client-plain-http-transport

`warning` typescript, javascript mcp, typescript, nodejs, client

An MCP client transport connects to a non-loopback http:// URL, so tool calls, results and any bearer token cross the network unencrypted and can be read or rewritten in transit. Use https://; keep http only for localhost.

Confidence **P1**: dangerous in context. False-positive risk **low**: an exact API or flag, so hits are almost always real.

Edge inspected: [sends](https://keryn.dev/docs/edges/edge-kinds/#sends) data leaves for another party; it crosses the [`secret->outside`](https://keryn.dev/docs/edges/trust-boundaries/#secret-to-outside) boundary (a secret leaving the trusted side).

[CWE-319](https://keryn.dev/rules/?cwe=CWE-319) [CWE-300](https://keryn.dev/rules/?cwe=CWE-300) [LLM02](https://keryn.dev/taxonomies/owasp-llm/#llm02-sensitive-information-disclosure) [LLM03](https://keryn.dev/taxonomies/owasp-llm/#llm03-supply-chain) [ASI07](https://keryn.dev/taxonomies/owasp-agentic/#asi07-insecure-inter-agent-communication) [ASI04](https://keryn.dev/taxonomies/owasp-agentic/#asi04-agentic-supply-chain-vulnerabilities)

**Fix:** Point the transport at an https:// endpoint with a valid certificate. Plain http is acceptable only for loopback development servers.

**References:** [https://modelcontextprotocol.io/specification/2025-06-18/basic/transports](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports) · [https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization](https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization) · [https://github.com/modelcontextprotocol/typescript-sdk](https://github.com/modelcontextprotocol/typescript-sdk) · [https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/packages/client/src/client/streamableHttp.ts](https://raw.githubusercontent.com/modelcontextprotocol/typescript-sdk/main/packages/client/src/client/streamableHttp.ts)

## keryn.mcp.go.sampling-request-no-approval

`warning` go mcp, go

A Go MCP tool handler asks the client to run a model completion (RequestSampling / CreateMessage) with no approval, consent or policy call anywhere in the same function. Add an explicit gate and token cap before spending the client's model.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **high**: it finds a lead to confirm, so expect benign hits.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-862](https://keryn.dev/taxonomies/cwe/#cwe-862-missing-authorization) [CWE-345](https://keryn.dev/taxonomies/cwe/#cwe-345-insufficient-verification-of-data-authenticity) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [LLM01](https://keryn.dev/taxonomies/owasp-llm/#llm01-prompt-injection) [ASI09](https://keryn.dev/taxonomies/owasp-agentic/#asi09-human-agent-trust-exploitation) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation)

**Fix:** Sampling lets a server spend the client's model and credentials. Gate each request behind an explicit approval or policy check (per-server allow-list, token cap, rate limit) and never build the sampled prompt from untrusted tool input without review.

**References:** [https://modelcontextprotocol.io/specification/2025-06-18/client/sampling](https://modelcontextprotocol.io/specification/2025-06-18/client/sampling) · [https://github.com/mark3labs/mcp-go](https://github.com/mark3labs/mcp-go) · [https://github.com/modelcontextprotocol/go-sdk](https://github.com/modelcontextprotocol/go-sdk) · [https://raw.githubusercontent.com/modelcontextprotocol/go-sdk/main/mcp/server.go](https://raw.githubusercontent.com/modelcontextprotocol/go-sdk/main/mcp/server.go) · [https://raw.githubusercontent.com/mark3labs/mcp-go/main/server/sampling.go](https://raw.githubusercontent.com/mark3labs/mcp-go/main/server/sampling.go)

## keryn.mcp.java.sampling-request-no-approval

`warning` java mcp, java

A Java MCP tool handler calls exchange.createMessage(...) to run a completion on the client with no approval, consent or policy call in the same handler. Add an explicit gate and a token cap before spending the client's model.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **high**: it finds a lead to confirm, so expect benign hits.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-862](https://keryn.dev/taxonomies/cwe/#cwe-862-missing-authorization) [CWE-345](https://keryn.dev/taxonomies/cwe/#cwe-345-insufficient-verification-of-data-authenticity) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [LLM01](https://keryn.dev/taxonomies/owasp-llm/#llm01-prompt-injection) [ASI09](https://keryn.dev/taxonomies/owasp-agentic/#asi09-human-agent-trust-exploitation) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation)

**Fix:** Sampling lets a server spend the client's model and credentials. Gate each request behind an explicit approval or policy check (per-server allow-list, token cap, rate limit) and never build the sampled prompt from untrusted tool input without review.

**References:** [https://modelcontextprotocol.io/specification/2025-06-18/client/sampling](https://modelcontextprotocol.io/specification/2025-06-18/client/sampling) · [https://github.com/modelcontextprotocol/java-sdk](https://github.com/modelcontextprotocol/java-sdk) · [https://raw.githubusercontent.com/modelcontextprotocol/java-sdk/main/mcp-core/src/main/java/io/modelcontextprotocol/server/McpSyncServerExchange.java](https://raw.githubusercontent.com/modelcontextprotocol/java-sdk/main/mcp-core/src/main/java/io/modelcontextprotocol/server/McpSyncServerExchange.java)

## keryn.mcp.csharp.sampling-request-no-approval

`warning` csharp mcp, csharp, dotnet

An [McpServerTool] method asks the client to run a completion (SampleAsync / RequestSamplingAsync) with no approval, consent or policy call in the same method. Add an explicit gate and a token cap before spending the client's model.

Confidence **P2**: a heuristic or a posture check: confirm by reading the code. False-positive risk **high**: it finds a lead to confirm, so expect benign hits.

Edge inspected: [grants](https://keryn.dev/docs/edges/edge-kinds/#grants) authority is given or left unchecked.

[CWE-862](https://keryn.dev/taxonomies/cwe/#cwe-862-missing-authorization) [CWE-345](https://keryn.dev/taxonomies/cwe/#cwe-345-insufficient-verification-of-data-authenticity) [LLM06](https://keryn.dev/taxonomies/owasp-llm/#llm06-excessive-agency) [LLM01](https://keryn.dev/taxonomies/owasp-llm/#llm01-prompt-injection) [ASI09](https://keryn.dev/taxonomies/owasp-agentic/#asi09-human-agent-trust-exploitation) [ASI02](https://keryn.dev/taxonomies/owasp-agentic/#asi02-tool-misuse-and-exploitation)

**Fix:** Sampling lets a server spend the client's model and credentials. Gate each request behind an explicit approval or policy check (per-server allow-list, token cap, rate limit) and never build the sampled prompt from untrusted tool input without review.

**References:** [https://modelcontextprotocol.io/specification/2025-06-18/client/sampling](https://modelcontextprotocol.io/specification/2025-06-18/client/sampling) · [https://github.com/modelcontextprotocol/csharp-sdk](https://github.com/modelcontextprotocol/csharp-sdk) · [https://raw.githubusercontent.com/mark3labs/mcp-go/main/server/sampling.go](https://raw.githubusercontent.com/mark3labs/mcp-go/main/server/sampling.go)
