Skip to content

Resource template registration fails when param names contain hyphens #3921

@strawgate

Description

@strawgate

URI templates with hyphenated parameter names fail at registration time.

@mcp.resource("data://{user-id}/profile")
def get_profile(user_id: str) -> str:
    return f"profile for {user_id}"
# ValueError: URI template must contain at least one parameter

The regex in template.py:505 uses \w+ which matches [a-zA-Z0-9_] — hyphens are excluded:

path_params = set(re.findall(r"{(\w+)(?:\*)?}", uri_template))

So {user-id} is not recognized as a parameter, and the template appears to have zero parameters.

RFC 6570 allows hyphens in variable names. The fix is [\w-]+ or [\w.-]+ in the regex.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working. Reports of errors, unexpected behavior, or broken functionality.serverRelated to FastMCP server implementation or server-side functionality.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions