Skip to content

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

Closed
@Smileslime47

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}`
    }]
  })
);

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