modelcontextprotocol / modelcontextprotocol/typescript-sdk

ResourceTemplate fails when user selects <Empty> for optional parameter

Open
#677 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug fix proposed P2 ready for work
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

  1. Create a ResourceTemplate with an optional parameter: "scheme://path/{required}/{optional?}"
  2. User selects a value for required parameter
  3. User selects <Empty> for the optional parameter from the completion dropdown
  4. The resulting URI becomes something like scheme://path/required/<Empty>
  5. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.