fix(adapters/langgraph): tolerate nested schema titles in MCP tool schemas#21
Merged
Conversation
…hemas MCP servers commonly derive tool schemas from OpenAPI documents whose nested schemas carry human-readable titles (e.g. Notion's "Rich Text"). The on-the-fly MCPTool built for the tracing callback fed those raw schemas into Property, whose title validation rejects any title with spaces or special characters, failing the whole agent run before the model was ever invoked. Strip title annotations from the arg schema before building the tracing Property, visiting exactly the positions the validator traverses (items, anyOf, additionalProperties, properties values) so non-schema payloads like default values are left intact. The LLM-facing args_schema is untouched.
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.
Problem
Attaching an MCP toolbox whose server ships OpenAPI-derived tool schemas (e.g. the Notion MCP server) kills every agent run with:
_get_or_create_langgraph_mcp_toolsbuilds an on-the-flyMCPTool(only used to back the tracing callback) withProperty(title=arg_name, json_schema=arg_json_schema)from the server's raw schemas.Property's validator recursively rejects any nestedtitlecontaining spaces/special characters, so a schema like Notion'schildrenargument (nested"title": "Rich Text") fails the whole run at the model step.Fix
Strip
titleannotations from the arg schema before constructing the tracingProperty. The traversal mirrors exactly the positions the validator visits (items,anyOf,additionalProperties,propertiesvalues) - a generic recursive strip would corrupt non-schema payloads such asdefault/examplesvalues containing atitlekey. The LLM-facingargs_schemaon the langchain tool is untouched, and the port name is passed explicitly astitle=, so nothing behavioral changes for tool calling.Tests
test_strip_schema_titles_removes_only_schema_title_annotations- helper unit test incl. a property literally namedtitleand adefaultpayload that must survive.test_mcp_toolbox_tolerates_openapi_style_nested_schema_titles- toolbox conversion with a Notion-shaped tool schema; fails with the exact production error without the fix.tests/adapters/langgraph/mcp/passes (1 pre-existing local-server fixture failure unrelated to this change, fails on base commit too);tests/test_properties.py176 passed.