fix: correct get_more_tools schema, harden truncation, and capture intent#25
Merged
fix: correct get_more_tools schema, harden truncation, and capture intent#25
Conversation
…tent - Make get_more_tools context parameter a required string instead of nullable/optional to prevent anyOf schema generation by Pydantic - Extract _ensure_context_parameter() helper in community tool manager to DRY up duplicated schema injection logic - Fix truncation depth=0 crash by introducing MIN_DEPTH and breadth reduction as a fallback; each pass now starts from a fresh model_dump - Capture user_intent from context on get_more_tools calls in events - Add schema validation, megabyte string, and many-keys regression tests
kashishhora
requested changes
Feb 27, 2026
src/mcpcat/modules/truncation.py
Outdated
| # Always start from a fresh dump to avoid compounding artifacts | ||
| truncated_dict = _truncate_value( | ||
| truncated_dict, max_depth=depth, max_string_bytes=string_bytes, | ||
| event.model_dump(), |
Member
There was a problem hiding this comment.
Shouldn't feed in entire event here, since that can truncate the protected fields (resource name, timestamp, etc.) in case another field is too big. Added unit test for this.
tests/test_dynamic_tracking.py
Outdated
| await fastmcp_server.call_tool("get_more_tools", {}) | ||
| assert False, "Expected ToolError for missing required context parameter" | ||
| except Exception: | ||
| pass # Expected: context is required |
Member
There was a problem hiding this comment.
Should probably check the correct type of exception returned. Something like pytest.raises(Exception, match=...) with a regex
Truncation now targets only TRUNCATABLE_FIELDS (parameters, response, error, etc.) instead of blindly truncating the entire event dict. This prevents metadata like event_type, resource_name, session_id, and actor_id from being mangled under extreme payload pressure. Also hardens breadth reduction floor (10 -> 1) and tightens test assertions for get_more_tools error cases using pytest.raises.
kashishhora
approved these changes
Feb 27, 2026
Older FastMCP versions use JSON Schema validation messages (e.g.
"'context' is a required property") while newer versions use Pydantic
messages ("Missing required argument"). Use version-agnostic patterns
like (?i)required and (?i)string to match both.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
get_more_toolscontext parameter a requiredstringinstead of nullable/optional, preventing Pydantic from generatinganyOf: [string, null]schemas that confuse LLM clients. AddsGET_MORE_TOOLS_SCHEMAconstant and forces correct schema post-registration in community FastMCP._ensure_context_parameter()helper in community tool manager to eliminate duplicated context parameter injection logic acrosspatch_existing_toolsandpatch_add_tool_fn.model_validate()to fail on string markers replacing dict-typed fields. IntroducesMIN_DEPTH, breadth reduction as a fallback, and freshmodel_dump()per pass to avoid compounding artifacts.get_more_toolscalls now captureuser_intentfrom the context argument in published events, matching the behavior of regular tool calls with context enabled.Test plan
uv run pytestuv run pytest tests/test_tool_context.py tests/community/test_community_report_missing.py -vuv run pytest tests/test_truncation.py -vuv run pytest tests/test_tool_context.py::TestUserIntentCaptureInEvents -v