feat(mcpserver): add add_resource_template() for programmatic template registration - #3348
feat(mcpserver): add add_resource_template() for programmatic template registration#3348pasmud wants to merge 1 commit into
Conversation
…e registration Add add_resource_template() to both ResourceManager and MCPServer so ResourceTemplate instances can be registered directly, without the @resource decorator. Duplicate uri_template registrations warn and return the existing template, mirroring add_resource() semantics. add_template() now delegates to the new method.
|
Thanks for the contribution. This repository only keeps pull requests open when they're linked to an issue that a maintainer has assigned to the author — CONTRIBUTING.md explains why and how we work. This PR has been closed for now because you aren't currently assigned to #3333. If a maintainer would like this change as a PR from you, they'll assign you to #3333 and this PR will reopen automatically — there's nothing more you need to do. (If you opened the issue, this PR already shows up on its timeline.) There's no need to open a new PR — this one will be reopened. While it's closed, please push any updates as new commits rather than force-pushing, since GitHub can't reopen a PR whose branch has been rewritten. Maintainers: reopening this PR, removing the |
Closes #3333
Summary
Adds
add_resource_template()to bothResourceManagerandMCPServerso aResourceTemplateinstance can be registered programmatically, without going through the@resourcedecorator.ResourceManager.add_resource_template()mirrorsadd_resource()semantics: registering a template whoseuri_templatealready exists logs a warning (respectingwarn_on_duplicate_resources) and returns the existing template.add_template()now delegates to the new method so there's a single registration path.Changes
src/mcp/server/mcpserver/resources/resource_manager.py: newadd_resource_template();add_template()delegates to itsrc/mcp/server/mcpserver/server.py: new thinadd_resource_template()onMCPServerdocs/servers/resources.md: document programmatic template registrationget_resource, and listing vialist_resource_templates()Verification
ruff format/ruff check/pyright: clean./scripts/test: 5747 passed, 8 skipped, 1 xfailed; coverage 100%. (The single failure,test_permission_error, is a root-user environment artifact that also fails onorigin/mainhere; it passes in CI.)Types of changes