Title: feat: add_resource_template to mcpserver and resource manager by mplemay · Pull Request #2774 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: feat: add_resource_template to mcpserver and resource manager by mplemay · Pull Request #2774 · modelcontextprotocol/python-sdk
X Title: feat: add_resource_template to mcpserver and resource manager by mplemay · Pull Request #2774 · modelcontextprotocol/python-sdk
Description: Summary Enables registering pre-built ResourceTemplate instances at init or runtime, parallel to add_resource. Adds ResourceManager.add_resource_template(), MCPServer.add_resource_template(), and an optional resource_templates constructor argument on both. add_template() now delegates to add_resource_template() after building the template from a function. Motivation and Context MCPServer already supported static resources via add_resource() and function-based templates via @server.resource(...), but there was no way to register a pre-built ResourceTemplate (for example one created with ResourceTemplate.from_function() elsewhere, or assembled manually). That blocked use cases where templates are defined outside the decorator flow or composed in library code. This change mirrors the existing add_resource / resources=[...] pattern so custom templates can be seeded at construction or added later. How Has This Been Tested? tests/server/mcpserver/resources/test_resource_manager.py: init with resource_templates, add_resource_template, duplicate handling and warnings (aligned with resource tests) tests/server/mcpserver/test_server.py: test_init_with_resource_templates and test_add_resource_template using in-memory Client(mcp) — list templates and read a templated URI end-to-end All of the above pass locally via uv run --frozen pytest on the touched test files. Breaking Changes None. Existing @server.resource(...) and add_resource() behavior is unchanged. Types of changes Bug fix (non-breaking change which fixes an issue) New feature (non-breaking change which adds functionality) Breaking change (fix or feature that would cause existing functionality to change) Documentation update Checklist I have read the MCP Documentation My code follows the repository's style guidelines New and existing tests pass locally I have added appropriate error handling I have added or updated documentation as needed Additional context Example usage: from mcp.server.mcpserver import MCPServer from mcp.server.mcpserver.resources import ResourceTemplate template = ResourceTemplate.from_function( fn=get_weather, uri_template="weather://{city}", name="weather", ) mcp = MCPServer(resource_templates=[template]) # or: mcp.add_resource_template(template) Duplicate templates are keyed by uri_template and use the same warn_on_duplicate_resources setting as concrete resources.
Open Graph Description: Summary Enables registering pre-built ResourceTemplate instances at init or runtime, parallel to add_resource. Adds ResourceManager.add_resource_template(), MCPServer.add_resource_template(), and a...
X Description: Summary Enables registering pre-built ResourceTemplate instances at init or runtime, parallel to add_resource. Adds ResourceManager.add_resource_template(), MCPServer.add_resource_template(), and a...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/pull/2774
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:4b9ec4c0-680b-b9ac-bd3c-ffb7301448af |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | E2B2:233EAB:1C7DDE:268F71:6A5A5A5D |
| html-safe-nonce | f3add351d0ed017cba7c9f6706d357aa4bee8e36af415de5f0f2c37df61b66ae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkIyOjIzM0VBQjoxQzdEREU6MjY4RjcxOjZBNUE1QTVEIiwidmlzaXRvcl9pZCI6IjM3MTQzMDgxODkxNzkyMzkwMDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b86ac8181aa3f0ebe0b17635d57c3865748bec14ffc91d1e414c4975ccad00db |
| hovercard-subject-tag | pull_request:3796942284 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/2774/files |
| twitter:image | https://avatars.githubusercontent.com/u/4324379?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/4324379?s=400&v=4 |
| og:image:alt | Summary Enables registering pre-built ResourceTemplate instances at init or runtime, parallel to add_resource. Adds ResourceManager.add_resource_template(), MCPServer.add_resource_template(), and a... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 05b9ddf6a47d2dbe13944873a99f5fb4b83ba4871f9cb8a8e256793a63ca9687 |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f8d29d1bd03dda2dd14b3f80b8bc27e1111f43bd |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width