Skip to content

ResourceTemplate fails when user selects <Empty> for optional parameter #677

Open
@dudo

Description

@dudo

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?}

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