Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jlowin
Copy link
Owner

@jlowin jlowin commented Apr 15, 2025

Closes #162

The following construction is now possible:

# Define a user lookup function that can be accessed by different identifiers
@mcp.resource("users://email/{email}")
@mcp.resource("users://name/{name}")
def lookup_user(name: str | None = None, email: str | None = None) -> dict:
    """Look up a user by either name or email."""
    if email:
        return find_user_by_email(email) # pseudocode
    elif name:
        return find_user_by_name(name) # pseudocode
    else:
        return {"error": "No lookup parameters provided"}

Copilot AI review requested due to automatic review settings April 15, 2025 05:18
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.

Files not reviewed (1)
  • docs/servers/resources.mdx: Language not supported
Comments suppressed due to low confidence (1)

src/fastmcp/server/server.py:366

  • Removing the wrapping with DecoratedFunction may remove important functionality from the decorated function. Please verify that returning the raw function rather than a DecoratedFunction is intentional.
return fn

@jlowin jlowin merged commit 45f4030 into main Apr 15, 2025
4 checks passed
@jlowin jlowin deleted the optional-resource-template-uris branch April 15, 2025 05:22
@jlowin jlowin added the enhancement Improvement to existing functionality. For issues and smaller PR improvements. label Apr 24, 2025
jordicore pushed a commit to jordicore/fastmcp that referenced this pull request Jul 2, 2025
…uris

Allow resource templates to have optional / excluded arguments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Improvement to existing functionality. For issues and smaller PR improvements.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allow optional types for resource template params

2 participants