modelcontextprotocol / modelcontextprotocol/typescript-sdk
ResourceTemplate fails when user selects <Empty> for optional parameter
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 13.4k
- Forks
- 2.2k
- Avg merge
- 3d 15h
- Merged PRs (30d)
- 4
Description
Description
When using ResourceTemplate with optional parameters (e.g., {param?}), if a user selects <Empty> from the completion dropdown, the resulting URI doesn't match the template pattern, causing the resource to fail to load.
The resource kubernetes://resources/nodes/ was not found.
Steps to Reproduce
- Create a ResourceTemplate with an optional parameter:
"scheme://path/{required}/{optional?}" - User selects a value for
requiredparameter - User selects
<Empty>for theoptionalparameter from the completion dropdown - The resulting URI becomes something like
scheme://path/required/<Empty> - This URI doesn't match the original template pattern and fails validation
Expected Behavior
When a user selects <Empty> for an optional parameter, the URI should either:
- Omit that path segment entirely (e.g.,
scheme://path/required) - Map
<Empty>to an empty string and handle it gracefully in the URI parsing
Current Workaround
We have to manually handle both cases in our readCallback:
scheme://path/required(when optional param is truly omitted)scheme://path/required/<Empty>(when user explicitly selects<Empty>)
Impact
This makes ResourceTemplates with optional parameters brittle and requires additional error-prone parsing logic in every implementation.
Environment
- MCP TypeScript SDK version: latest
- Context: ResourceTemplate with pattern like
kubernetes://resources/{resourceType}/{namespace?}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start at the ResourceTemplate completion and URI validation path, using the optional-parameter pattern and selection described in the reproduction steps. Verify the behavior for both an omitted optional segment and a URI ending in ; done means the selected URI matches the template and loads without requiring custom readCallback handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100