Skip to content

Conversation

codecracker007
Copy link

Add RFC 6570 support for optional parameters as form-style query expansions

Motivation and Context

Adds optional parameter support with RFC 6570 compliance as form-style query expansions. This change addresses issue #378, .

Breaking Changes

None

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

@ihrpr ihrpr added this to the r-05-25 milestone May 13, 2025
Copy link
Contributor

@ihrpr ihrpr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for working on this!

This PR makes good progress toward RFC 6570 support by adding form-style query expansion.

There are a few suggestions:

  1. Type Conversion for Query Parameters. Query parameters from URLs are always strings, but the code doesn't convert them to match function parameter
    types.

Example of the problem:

@server.resource("resource://items/{category}{?limit}")
def get_items(category: str, limit: int = 10) -> str:
    # When called with resource://items/books?limit=20
    # limit will be string "20" not int 20
    return f"Items in {category}, limit: {limit} (type: {type(limit)})"

Suggested fix: Add type conversion based on function annotations in

  1. Handle Edge Cases in Query Parsing. The current implementation might not handle edge cases properly:
  • Empty query values (?param=)
  • URL-encoded values (?name=John%20Doe)
  1. Add Tests for Type Conversion Scenarios

  2. Consider Documenting Query Parameter Behavior

@codecracker007
Copy link
Author

@ihrpr thanks for the feedback

during the fn call with params result = self.fn(**params)

can i use call_fn_with_arg_validation

async def call_fn_with_arg_validation(
for type validation and conversion and should i fallback to default values for optional parameters if validation fails for any one of them

@codecracker007
Copy link
Author

@ihrpr the pydantic validate_call already takes care of the compatible type conversion based on annontated parameters for query parameters and raises validation error for incompatible types added a decorator which check if the validation error is raised by optional parameters and ignores them so they fall back to default values to keep it compliant

added relevant tests covering these cases

for the cases in query parsing the empty values and url encoded parameters are handled by parse_qs added relevant tests covering these

@codecracker007 codecracker007 requested a review from ihrpr May 31, 2025 12:41
@felixweinberger felixweinberger added the needs more work Not ready to be merged yet, needs additional changes. label Sep 5, 2025
Copy link
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies for the delay in coming back to this - there seem to be some failing tests & merge conflicts, would you be able to resolve?

I'll prioritize responding quickly if you have the bandwidth to update the PR here.

@codecracker007 codecracker007 requested review from a team and felixweinberger September 6, 2025 08:23
@felixweinberger felixweinberger added needs sync Needs sync with latest main branch to ensure CI passes needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention and removed needs more work Not ready to be merged yet, needs additional changes. labels Sep 29, 2025
@felixweinberger felixweinberger self-assigned this Sep 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs maintainer action Potentially serious issue - needs proactive fix and maintainer attention needs sync Needs sync with latest main branch to ensure CI passes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants