Skip to content

Any method to match and handle the resource by dynamic uri path? #100

Closed

Description

@Smileslime47

For example,I have 1000000 resource item stored in my database,and I'd like to match them by the uri like "document://index-A/index-B/index-C",it will be convenient to match them like "document://{index-A}/{index-B}/{index-C}" in a handler,and then use a select query to return the matched data item

I saw the ResourceTemplate class in sdk,but I couldn't see any method to match a template and handle them - McpServer have a method named "addResource" but doesn't have a method named "addResourceTemplate",ResourceTemplate seems just an "instruction" to client,and not used to handle parameterized uri

Maybe try to run a loop of 1000000 times calling addResource method to register them is not acceptable,and surely that will lose the significance of database,or I did not find the correct way to handle the ResourceTemplate?

As other sdk implement,Python and TypeScript SDKs seem support this feature:

# Add a dynamic greeting resource
@mcp.resource("greeting://{name}")
def get_greeting(name: str) -> str:
    """Get a personalized greeting"""
    return f"Hello, {name}!"
// Dynamic resource with parameters
server.resource(
  "user-profile",
  new ResourceTemplate("users://{userId}/profile", { list: undefined }),
  async (uri, { userId }) => ({
    contents: [{
      uri: uri.href,
      text: `Profile data for user ${userId}`
    }]
  })
);

Activity

  1. Smileslime47 commented on Apr 2, 2025

    @Smileslime47
    Author

    okay,I saw the PR about this feature which hasn't been merged

    seems I couldn't develop my mcp server in a short time :(

  2. arcaputo3 commented on Apr 11, 2025

    @arcaputo3
    Contributor

    This seems like a critical feature and it isn't well-documented that this isn't supported yet...

  3. benken-parasoft commented on Jul 9, 2025

    @benken-parasoft

    Using the solution from #208, registering resource templates enables the server to return that list back to clients who query "resources/templates/list". In terms of handling dynamic resources, I see that I can register a resource with the same parameterized URI. I can then add whatever code I want in my "readHandler" method for returning the dynamic content.

    I suspect #25 may not be merged as it seems to take a contradictory approach but who knows?

  4. Smileslime47 commented on Jul 10, 2025

    @Smileslime47
    Author

    Using the solution from #208, registering resource templates enables the server to return that list back to clients who query "resources/templates/list". In terms of handling dynamic resources, I see that I can register a resource with the same parameterized URI. I can then add whatever code I want in my "readHandler" method for returning the dynamic content.

    I suspect #25 may not be merged as it seems to take a contradictory approach but who knows?

    #208 seems resolved the problem,but now I use mcp's tool_call to implement the api of resource query,as it is compatible to general tool_call,and I needn't to do any works to let the agent know the format difference between tool_call and resource_query

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions