Skip to content

Resource template parameters do not support values with slashes #159

@phernandez

Description

@phernandez

Describe the bug

Overview

Resource template values containing path separators (slashes) do not work.

Working Examples

Simple Static Resources

@mcp.resource("resource://my-resource")
def get_data() -> dict[str, Any]:
    return {
        "contents": [{
            "uri": "resource://my-resource",
            "mimeType": "text/plain",
            "text": "Hello, world!"
        }]
    }

This works reliably and shows up in the Inspector UI.

Parameter

@mcp.resource("resource://{value}")
def get_content(value: str) -> dict[str, Any]:
    # This works for: resource://
    # But fails for: resourse://value/with/slashes
    ...

To Reproduce

1. Template Pattern with Regex

@mcp.resource("resource://{value:.*}")
def get_content(value: str) -> dict[str, Any]:
    # Error: Mismatch between URI parameters set() and function parameters {'permalink'}

2. Generic Catch-all Pattern

@mcp.resource("memory://*")
def get_content(uri: str) -> dict[str, Any]:
    # Error: Mismatch between URI parameters set() and function parameters {'uri'}

3. Path Parameter Approach

@mcp.resource("resource://content/{path}")
def get_content(path: str) -> dict[str, Any]:
    # Works for simple paths but fails with slashes in {path}

4. Base Path with Query Parameters

@mcp.resource("resource://content")
def get_content(path: str = None) -> dict[str, Any]:
    # Error: Mismatch between URI parameters set() and function parameters {'path'}

Expected behavior

Resource Templates with slashes in the value should be passed to the decorated function.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions