Add pathVariableNames and queryVariableNames getters in UriTemplate#609
Open
Mubashwer wants to merge 1 commit intomodelcontextprotocol:mainfrom
Open
Add pathVariableNames and queryVariableNames getters in UriTemplate#609Mubashwer wants to merge 1 commit intomodelcontextprotocol:mainfrom
pathVariableNames and queryVariableNames getters in UriTemplate#609Mubashwer wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
Add new getter methods to UriTemplate class to distinguish between path-like
and query-like variables based on RFC 6570 expansion operators. This enables
better resource browsing in MCP Inspector by identifying which variables are
structurally required vs. optional.
**New Features:**
- `pathVariableNames`: Returns variables used in path-like expansions
- Simple expansion: `{var}`
- Reserved expansion: `{+var}`
- Fragment expansion: `{#var}`
- Label expansion: `{.var}`
- Path segment expansion: `{/var}`
- `queryVariableNames`: Returns variables used in query-like expansions
- Form-style query: `{?var}`
- Query continuation: `{&var}`
**Use Case:**
This change will improve MCP Inspector UX by allowing users to browse resource templates
with only path variables filled, while treating query variables as optional
filters. For example, with template `database://users/{id}{?limit,offset}`:
- Path variables (`id`) identify the core resource
- Query variables (`limit`, `offset`) are optional filtering parameters
**Technical Details:**
- Classification based on RFC 6570 expansion operators, not semantic assumptions
- Path-like variables affect URI structure when omitted
- Query-like variables only affect query parameters when omitted
- Maintains backward compatibility with existing `variableNames` getter
**Tests:**
- Added comprehensive test suite covering all operator types
- Tests for edge cases (no variables, only path, only query)
- Validates correct classification of mixed templates
0845a57 to
c94ba4b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds two new getter methods to the
UriTemplateclass that distinguish between path-like variables (which identify core resources) and query-like variables (which are optional parameters). This will enable the MCP Inspector to allow resource browsing with only essential path variables filled, while treating query parameters as optional filters.Motivation and Context
The MCP Inspector currently requires all URI template variables to be filled before allowing reading of resources from resource templates, which makes it difficult to explore available resources and understand what variables are needed. Some query parameters MAY be optional. This change enables better resource discovery by distinguishing between path-like variables (which identify the core resource) and query-like variables (which are optional filters/parameters).
This addresses the need for more intuitive resource browsing in MCP Inspector, where users should be able to access resources with only essential path variables while treating query parameters as optional enhancements.
How Has This Been Tested?
database://users/{id}{?limit,offset}Breaking Changes
No breaking changes. This is a purely additive feature that maintains full backward compatibility with existing code.
Types of changes
Checklist
Additional context
Implementation Details:
pathVariableNames: Returns variables from path-like expansions ("","+","#",".","/"operators)queryVariableNames: Returns variables from query-like expansions ("?","&"operators)variableNamesgetter for full compatibilityUse Case Example:
This change will enable MCP Inspector to allow browsing
database://users/123/postswithout requiring query parameters, while still showing what optional filters are available.RFC 6570 Compliance: