How to use Resource templates properly? #855
Unanswered
tim-schneider-elo
asked this question in
Q&A
Replies: 1 comment
|
There is no You can use the SDK's URI-template manager instead of parsing the string manually: var template = "file:///{path}";
var uriTemplate = new DefaultMcpUriTemplateManager(template);
var spec = new McpServerFeatures.SyncResourceTemplateSpecification(
new McpSchema.ResourceTemplate(template, "file", null, null),
(exchange, request) -> {
var variables = uriTemplate.extractVariableValues(request.uri());
var path = variables.get("path");
// build and return ReadResourceResult using path
}
);For production code, construct the manager once with the specification rather than once per read. Relevant SDK API: |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Pre-submission Checklist
Question Category
Your Question
The example in the documentation doesn't use the template variable.
What's the best way to access the variable?
I can use
request.uri()and filter it out.Is there a way to just use the same name?
For the example in the docs, somthing like `request.getTemplateVariable("path")?
All reactions