Sanitize untrusted output in fastmcp list and fastmcp call#3409
Sanitize untrusted output in fastmcp list and fastmcp call#3409
fastmcp list and fastmcp call#3409Conversation
🤖 Generated with GPT-5.2-Codex
Test Failure AnalysisSummary: The static analysis ( Root Cause: Two Suggested Solution: Run # Before (too long):
console.print(f" {_sanitize_untrusted_text(tool.description)}")
console.print(f" [cyan]{_sanitize_untrusted_text(str(r.uri))}[/cyan]")
# After (ruff-formatted):
console.print(
f" {_sanitize_untrusted_text(tool.description)}"
)
console.print(
f" [cyan]{_sanitize_untrusted_text(str(r.uri))}[/cyan]"
)Detailed AnalysisFailing check: Log excerpt: Full diff applied by ruff-format: --- a/src/fastmcp/cli/client.py
+++ b/src/fastmcp/cli/client.py
@@ -745,7 +745,9 @@
sig = format_tool_signature(tool)
console.print(f" [cyan]{_sanitize_untrusted_text(sig)}[/cyan]")
if tool.description:
- console.print(f" {_sanitize_untrusted_text(tool.description)}")
+ console.print(
+ f" {_sanitize_untrusted_text(tool.description)}"
+ )
if input_schema:
@@ -759,7 +761,9 @@
if not res:
console.print(" [dim]No resources found.[/dim]")
for r in res:
- console.print(f" [cyan]{_sanitize_untrusted_text(str(r.uri))}[/cyan]")
+ console.print(
+ f" [cyan]{_sanitize_untrusted_text(str(r.uri))}[/cyan]"
+ )Note: The Related Files
|
Motivation
Description
_sanitize_untrusted_textthat usesrich.markup.escapeand encodes non-printable/control characters as visible\xNNsequences while preserving newlines/tabs and printable UTF-8 content.fastmcp listoutput for tools, resources, and prompts.tests/cli/test_client_commands.py.Testing
uv syncsuccessfully to prepare the environment.uv run pytest -n auto, which reported unrelated failures/timeouts outside of the CLI change (13 failed, 1 error) in this environment and are not caused by this patch.uv run pytest tests/cli/test_client_commands.py, which passed (78 passed).uv run ruff checkpassed for the modified files, anduv run prek run --all-filesfailed to initialize hooks due to an external network checkout error (bootstrapping a third-party hook), unrelated to the code changes.Codex Task