No control characters in metadata
Control characters other than tab, line feed and carriage return have no place in tool metadata and can hide or reorder text in logs and terminals, so remove them.
Check sec-control-chars · Poisoning and hidden text · default severity: attention · rubric 2.1.0
What fails
Control characters other than tab, line feed and carriage return have no place in tool metadata and can hide or reorder text in logs and terminals.
The rule
Treat the entire tool schema as a potential injection surface — not just the description field.
Source: OWASP MCP Security Cheat Sheet
How to fix it
Remove the characters. "Copy fixed tool list" strips them.
- Strip U+0000 to U+0008, U+000B, U+000C, U+000E to U+001F and U+007F to U+009F.
- Keep tabs and line breaks only where they help readability.
- Add a CI test.
A CI test that fails when the pattern comes back, run against the saved tools/list answer:
TypeScript (node:test)
// tools-list.test.mjs: run `node --test` after saving the answer with
// npx @modelcontextprotocol/inspector --cli <server> --method tools/list > tools.json
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { test } from 'node:test';
const answer = JSON.parse(readFileSync('tools.json', 'utf8'));
const tools = answer.tools ?? answer.result?.tools ?? answer;
// Every string and every key in a tool, with its path.
function* strings(value, path) {
if (typeof value === 'string') yield [path, value];
else if (value && typeof value === 'object')
for (const [k, v] of Object.entries(value)) {
yield [`${path}.${k} (key)`, k];
yield* strings(v, `${path}.${k}`);
}
}
const PATTERN = /[\u0000-\u0008\u000B\u000C\u000E-\u001F\u007F-\u009F]/u;
test('no control characters', () => {
const hits = [];
for (const tool of tools) for (const [path, text] of strings(tool, tool.name)) if (PATTERN.test(text)) hits.push(path);
assert.deepEqual(hits, [], 'control characters in tool metadata');
});Python (pytest)
# test_tools_list.py: run `pytest` after saving the answer with
# npx @modelcontextprotocol/inspector --cli <server> --method tools/list > tools.json
import json
import re
with open("tools.json", encoding="utf-8") as f:
answer = json.load(f)
tools = answer.get("tools") or answer.get("result", {}).get("tools") if isinstance(answer, dict) else answer
def strings(value, path):
"""Every string and every key in a tool, with its path."""
if isinstance(value, str):
yield path, value
elif isinstance(value, dict):
for k, v in value.items():
yield f"{path}.{k} (key)", k
yield from strings(v, f"{path}.{k}")
elif isinstance(value, list):
for i, v in enumerate(value):
yield from strings(v, f"{path}.{i}")
PATTERN = re.compile(r"[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x9F]")
def test_no_control_characters():
hits = [path for tool in tools for path, text in strings(tool, tool["name"]) if PATTERN.search(text)]
assert hits == [], "control characters in tool metadata"Questions
How can a control character hide text?
Terminal escape sequences (starting with ESC, U+001B) can conceal, recolour or erase text when a log or a CLI client prints the description.
Are newlines allowed in descriptions?
Yes. Tab, line feed and carriage return are not flagged.
Related checks
- No zero-width or other invisible characters
- No bidirectional override characters
- No invisible Unicode tag or variation-selector characters
- All checks in Tool poisoning and hidden text
How this check is graded
It counts toward: Poisoning and hidden text. See the rubric.
Last verified against OWASP MCP Security Cheat Sheet on 2026-11-18. The rule above is quoted in the source’s own words. This page as Markdown.
Check your tool list: paste your tools/list, nothing is sent anywhere