Conversation
6af0017 to
c6fbfed
Compare
gandhipratik203
left a comment
There was a problem hiding this comment.
Nice fix. This lines up with the reported regression, and the added tests make the strict vs non-strict behavior easy to follow.
Signed-off-by: Gabriel Costa <gabrielcg@proton.me>
- Parameterize non-strict test to verify ALL 7 forbidden patterns pass through (was only testing "> ") - Add test for break behavior: single warning logged even with multiple matching patterns in one description - Move inline `import logging` to top-level imports - Covers issue #3711 Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
The forbidden-pattern list matches "< " (with trailing space), not bare "<". Strings like "<placeholder>" never hit the forbidden-pattern check; they are stripped by sanitize_display_text() as HTML-like content regardless of VALIDATION_STRICT. Replace with "< input" and "cmd | grep" which actually match the gated patterns. Addresses Codex review finding #1. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
…way init Cover the `raw_error = str(root_cause) or type(root_cause).__name__` guard in _initialize_gateway: when an exception's str() is empty, the GatewayConnectionError message now includes the type name instead of a blank suffix. Tests both plain exceptions and ExceptionGroup unwrapping. Addresses Codex review finding #2. Signed-off-by: Mihai Criveti <crivetimihai@gmail.com>
bd476d2
c6fbfed to
bd476d2
Compare
crivetimihai
left a comment
There was a problem hiding this comment.
Approved — fix is correct, consistent, and well-tested.
Review Summary
The core change gates ToolCreate.validate_description's forbidden-pattern check behind settings.validation_strict, matching the existing pattern used by validate_shell_parameter and validate_sql_parameter. When VALIDATION_STRICT=false, forbidden patterns log a warning instead of raising ValueError. This resolves the regression from v0.9.0 → v1.0.0.Beta2 where MCP servers with Markdown-formatted tool descriptions could not register.
Verification
- Unit tests: 13/13 pass (11 schema validator tests + 2 gateway error fallback tests)
- Live integration tests (localhost:8080): 18/18 pass — all 7 forbidden patterns correctly rejected in strict mode, all 7 accepted in non-strict mode, plus regression tests on all core endpoints
Commits added during review
test: improve differential test coverage for validation_strict gating— Parameterized non-strict test across all 7 patterns (was only testing>); added test forbreakbehavior (single warning per description); moved inlineimport loggingto top-levelfix(docs): replace misleading <placeholder> example in validation docs—<placeholder>never matches"< "(trailing space required); it's stripped bysanitize_display_text()as HTML. Replaced with< input/cmd | grepin schemas.py, .env.example, and docstest: add regression tests for empty exception str() fallback in gateway init— Coversraw_error = str(root_cause) or type(root_cause).__name__for both plain exceptions and ExceptionGroup unwrapping
Note
Filed #3773 for the pre-existing gap: ToolUpdate.validate_description lacks the forbidden-pattern check entirely, allowing bypass via update after creation.
🐛 Bug-fix PR
📌 Summary
MCP servers often include tools whose description fields contain Markdown syntax (e.g. > quoted text blockquotes, tokens, pipe characters in shell command examples). In v0.9.0 these descriptions registered without error. In v1.0.0.Beta2 a forbidden_patterns check was added to ToolCreate.validate_description in schemas.py that rejects descriptions containing &&, ;, ||, $(, |, > , or < . Unlike the similar validation in validators.py (which honours settings.validation_strict), this Pydantic validator is hardcoded — it raises unconditionally regardless of VALIDATION_STRICT, JSON_SCHEMA_VALIDATION_STRICT, or EXPERIMENTAL_VALIDATE_IO being set to false.
The result is that setting these environment variables has no effect on the registration error, contrary to documented expectations and to v0.9.0 behaviour.
Closes #3711
VALIDATION_STRICT=true:VALIDATION_STRICT=false:🔁 Reproduction Steps
descriptioncontains any of:&&,;,||,$(,|,>,<.Example description:
"Search FICO product documentation > returns results"or"> Lists available options".VALIDATION_STRICT=false,JSON_SCHEMA_VALIDATION_STRICT=false, andEXPERIMENTAL_VALIDATE_IO=false.🐞 Root Cause
File:
mcpgateway/schemas.py,ToolCreate.validate_description, lines 488–493This check:
ToolCreate.validate_description.ToolUpdateand all other schema validators (Resource, Prompt, Gateway, Server, A2AAgent, Team…) do not have it.settings.validation_strictis imported inschemas.py(line 43) but never consulted here.EXPERIMENTAL_VALIDATE_IO(which togglesValidationMiddleware) andJSON_SCHEMA_VALIDATION_STRICT(which toggles db-level JSON Schema validation) are both irrelevant to this code path.VALIDATION_STRICTis the correct setting to control this, as it is already used invalidate_shell_parameterandvalidate_sql_parameterinvalidators.pyfor the same purpose.💡 Fix Description
Wrap the
raisewith asettings.validation_strictguard:🧪 Verification
make lintmake testmake coverage📐 MCP Compliance (if relevant)
Checklist
make black isort pre-commit)