Skip to content

fix: mcp parameter fields are being dropped - #362

Merged
NicoleMGomes merged 3 commits into
mainfrom
fix/mcp-missing-parameters
Oct 1, 2026
Merged

NicoleMGomes merged 3 commits into
mainfrom
fix/mcp-missing-parameters

Conversation

@NicoleMGomes

@NicoleMGomes NicoleMGomes commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Disclaimer: Do not include SAP-internal or customer-specific information in this PR (e.g. internal system URLs, customer names, tenant IDs, or confidential configurations). This is a public repository.

Description

mcp_tool_to_langchain in sap_cloud_sdk.agentgateway.converters was silently dropping all JSON Schema property metadata other than type and required. This meant fields like description, enum, format, examples, minimum/maximum, pattern, and others were never forwarded to the Pydantic model or the LangChain tool schema — so the LLM had no visibility into allowed values, constraints, or hints.

The fix introduces a two-bucket mapping strategy:

  • Native Pydantic Field kwargs (description, title, examples, deprecated, pattern, minLength/maxLength → min_length/max_length, minimum/maximum → ge/le, exclusiveMinimum/exclusiveMaximum → gt/lt, multipleOf) are forwarded directly as Field(...) keyword arguments with the required camelCase → snake_case translation. These are also enforced at Pydantic validation time.
  • Schema-only fields (enum, default, example, const, format, contentEncoding, uniqueItems, items, properties, required, additionalProperties, oneOf, anyOf, allOf) are collected into json_schema_extra so they pass through verbatim into model_json_schema() and reach the LLM.
  • Unknown keys (future extensions, x-custom-*) are silently ignored — no crash.

The full set of fields emitted by the MCP builder (type, description, title, enum, default, examples, example, const, maxLength, minimum, pattern, format, contentEncoding, uniqueItems, items, properties, additionalProperties, oneOf/anyOf/allOf) are now all handled.

Related Issue

Closes #

Type of Change

  • Bug fix (non-breaking change that fixes an issue)

How to Test

  1. Install the package: pip install sap-cloud-sdk[langchain]
  2. Construct an MCPTool with a rich input_schema — include description, enum, format, minimum, maxLength, and examples on properties.
  3. Call mcp_tool_to_langchain(tool, call_tool, get_user_token).
  4. Inspect lc_tool.args_schema.model_json_schema()["properties"] — all metadata fields should be present on each property.
  5. Verify Pydantic enforces native constraints: pass a value exceeding maxLength or below minimum and confirm a ValidationError is raised.
  6. Run the unit tests: uv run pytest tests/agentgateway/unit/test_converters.py -v

Checklist

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

Additional Notes

  • enum is intentionally forwarded via json_schema_extra rather than as a Literal type — it serves as a hint to the LLM, not a Python validation constraint. This matches how MCP tool schemas are intended to be used.
  • default from the MCP schema is also in json_schema_extra (not Field(default=...)), because MCP's default is a documentation hint; promoting it to a Python default would silently make required fields optional.
  • The examples field is native to Pydantic v2's Field and goes through the native path.
  • 45 unit tests cover all paths: each native kwarg, each extra-bucket key, coexistence of multiple fields, unknown key handling, and all pre-existing behaviour (required/optional, nullable, OData underscore stripping, omit_none, invocation forwarding).

@NicoleMGomes
NicoleMGomes marked this pull request as ready for review October 1, 2026 19:16
@NicoleMGomes
NicoleMGomes requested a review from a team as a code owner October 1, 2026 19:16
@NicoleMGomes
NicoleMGomes merged commit 78a25f4 into main Oct 1, 2026
10 of 11 checks passed
@NicoleMGomes
NicoleMGomes deleted the fix/mcp-missing-parameters branch October 1, 2026 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants