René's URL Explorer Experiment


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

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:4b9ec4c0-680b-b9ac-bd3c-ffb7301448af
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE2B2:233EAB:1C7DDE:268F71:6A5A5A5D
html-safe-noncef3add351d0ed017cba7c9f6706d357aa4bee8e36af415de5f0f2c37df61b66ae
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMkIyOjIzM0VBQjoxQzdEREU6MjY4RjcxOjZBNUE1QTVEIiwidmlzaXRvcl9pZCI6IjM3MTQzMDgxODkxNzkyMzkwMDUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmacb86ac8181aa3f0ebe0b17635d57c3865748bec14ffc91d1e414c4975ccad00db
hovercard-subject-tagpull_request:3796942284
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/modelcontextprotocol/python-sdk/pull/2774/files
twitter:imagehttps://avatars.githubusercontent.com/u/4324379?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/4324379?s=400&v=4
og:image:altSummary 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_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None05b9ddf6a47d2dbe13944873a99f5fb4b83ba4871f9cb8a8e256793a63ca9687
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git
octolytics-dimension-user_id182288589
octolytics-dimension-user_loginmodelcontextprotocol
octolytics-dimension-repository_id862584018
octolytics-dimension-repository_nwomodelcontextprotocol/python-sdk
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id862584018
octolytics-dimension-repository_network_root_nwomodelcontextprotocol/python-sdk
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
releasef8d29d1bd03dda2dd14b3f80b8bc27e1111f43bd
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F2774%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub Copilot appDirect agents from issue to mergehttps://github.com/features/ai/github-app
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
View all resourceshttps://github.com/resources
GitHub SponsorsFund open source developershttps://github.com/open-source/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/open-source/accelerator
GitHub Starshttps://stars.github.com
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fmodelcontextprotocol%2Fpython-sdk%2Fpull%2F2774%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=modelcontextprotocol%2Fpython-sdk
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files
Reloadhttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files
modelcontextprotocol https://github.com/modelcontextprotocol
python-sdkhttps://github.com/modelcontextprotocol/python-sdk
Notifications https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Fork 3.7k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Star 23.6k https://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk
Code https://github.com/modelcontextprotocol/python-sdk
Issues 256 https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests 303 https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality 6 https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Code https://github.com/modelcontextprotocol/python-sdk
Issues https://github.com/modelcontextprotocol/python-sdk/issues
Pull requests https://github.com/modelcontextprotocol/python-sdk/pulls
Actions https://github.com/modelcontextprotocol/python-sdk/actions
Projects https://github.com/modelcontextprotocol/python-sdk/projects
Models https://github.com/modelcontextprotocol/python-sdk/models
Security and quality https://github.com/modelcontextprotocol/python-sdk/security
Insights https://github.com/modelcontextprotocol/python-sdk/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fmodelcontextprotocol%2Fpython-sdk%2Fissues%2Fnew%2Fchoose
mplemayhttps://github.com/mplemay
modelcontextprotocol:mainhttps://github.com/modelcontextprotocol/python-sdk/tree/main
mplemay:resource-templateshttps://github.com/mplemay/python-sdk/tree/resource-templates
Conversation 0 https://github.com/modelcontextprotocol/python-sdk/pull/2774
Commits 5 https://github.com/modelcontextprotocol/python-sdk/pull/2774/commits
Checks 27 https://github.com/modelcontextprotocol/python-sdk/pull/2774/checks
Files changed https://github.com/modelcontextprotocol/python-sdk/pull/2774/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files
feat: add_resource_template to mcpserver and resource manager https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#top
Show all changes 5 commits https://github.com/modelcontextprotocol/python-sdk/pull/2774/files
13d062e Add add_resource_template to MCPServer and ResourceManager. mplemay Jun 3, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2774/commits/13d062ecaf9d7fc3a905a559a15806c34efab1a7
fcd9e07 refactor(resources): use walrus in add_resource_template duplicate check mplemay Jun 3, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2774/commits/fcd9e078c38edd11d0cbc8ac5fa291804fe9c8e8
acac516 style(tests): fix ruff import order in test_server mplemay Jun 3, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2774/commits/acac5168725046ccaec531905da0c652ab1baea2
71d6078 test(resources): hoist greet helper for coverage mplemay Jun 3, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2774/commits/71d60786639ff6a48436e25e85ed8efe952eab73
61fd3a6 test(stdio): allow stderr warnings before clean-exit line mplemay Jun 3, 2026 https://github.com/modelcontextprotocol/python-sdk/pull/2774/commits/61fd3a66e94793eb9f6a1e7629eca411fc3797cf
Clear filters https://github.com/modelcontextprotocol/python-sdk/pull/2774/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files
resource_manager.py https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-3638946fe0f98df2b1f99f9237907bc1344596ddd20cdfbb297d3ae874894cfd
server.py https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-51d6996c0b80b8a5c42e7071451cb9ed3c91b398facebe99b94aad911059190e
test_stdio.py https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-e87dd7470dc7d367b9901aacfcc577a54864d05e8e50b4b9a25c6d1bfc543fb5
test_resource_manager.py https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-8c172adad20fc633a6965eec4784cfb4f2631fd7d88fa37003b689ca6e44dce1
test_server.py https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-c191383f010475fc22bf69d35f14f16d7e45098b05a1a0f03ad66d6c151d1f34
src/mcp/server/mcpserver/resources/resource_manager.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-3638946fe0f98df2b1f99f9237907bc1344596ddd20cdfbb297d3ae874894cfd
View file https://github.com/modelcontextprotocol/python-sdk/blob/61fd3a66e94793eb9f6a1e7629eca411fc3797cf/src/mcp/server/mcpserver/resources/resource_manager.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2774/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-3638946fe0f98df2b1f99f9237907bc1344596ddd20cdfbb297d3ae874894cfd
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-3638946fe0f98df2b1f99f9237907bc1344596ddd20cdfbb297d3ae874894cfd
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-3638946fe0f98df2b1f99f9237907bc1344596ddd20cdfbb297d3ae874894cfd
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-3638946fe0f98df2b1f99f9237907bc1344596ddd20cdfbb297d3ae874894cfd
src/mcp/server/mcpserver/server.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-51d6996c0b80b8a5c42e7071451cb9ed3c91b398facebe99b94aad911059190e
View file https://github.com/modelcontextprotocol/python-sdk/blob/61fd3a66e94793eb9f6a1e7629eca411fc3797cf/src/mcp/server/mcpserver/server.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2774/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-51d6996c0b80b8a5c42e7071451cb9ed3c91b398facebe99b94aad911059190e
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-51d6996c0b80b8a5c42e7071451cb9ed3c91b398facebe99b94aad911059190e
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-51d6996c0b80b8a5c42e7071451cb9ed3c91b398facebe99b94aad911059190e
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-51d6996c0b80b8a5c42e7071451cb9ed3c91b398facebe99b94aad911059190e
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-51d6996c0b80b8a5c42e7071451cb9ed3c91b398facebe99b94aad911059190e
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-51d6996c0b80b8a5c42e7071451cb9ed3c91b398facebe99b94aad911059190e
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-51d6996c0b80b8a5c42e7071451cb9ed3c91b398facebe99b94aad911059190e
tests/interaction/transports/test_stdio.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-e87dd7470dc7d367b9901aacfcc577a54864d05e8e50b4b9a25c6d1bfc543fb5
View file https://github.com/modelcontextprotocol/python-sdk/blob/61fd3a66e94793eb9f6a1e7629eca411fc3797cf/tests/interaction/transports/test_stdio.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2774/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-e87dd7470dc7d367b9901aacfcc577a54864d05e8e50b4b9a25c6d1bfc543fb5
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-e87dd7470dc7d367b9901aacfcc577a54864d05e8e50b4b9a25c6d1bfc543fb5
tests/server/mcpserver/resources/test_resource_manager.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-8c172adad20fc633a6965eec4784cfb4f2631fd7d88fa37003b689ca6e44dce1
View file https://github.com/modelcontextprotocol/python-sdk/blob/61fd3a66e94793eb9f6a1e7629eca411fc3797cf/tests/server/mcpserver/resources/test_resource_manager.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2774/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-8c172adad20fc633a6965eec4784cfb4f2631fd7d88fa37003b689ca6e44dce1
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-8c172adad20fc633a6965eec4784cfb4f2631fd7d88fa37003b689ca6e44dce1
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-8c172adad20fc633a6965eec4784cfb4f2631fd7d88fa37003b689ca6e44dce1
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-8c172adad20fc633a6965eec4784cfb4f2631fd7d88fa37003b689ca6e44dce1
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-8c172adad20fc633a6965eec4784cfb4f2631fd7d88fa37003b689ca6e44dce1
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-8c172adad20fc633a6965eec4784cfb4f2631fd7d88fa37003b689ca6e44dce1
tests/server/mcpserver/test_server.pyhttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-c191383f010475fc22bf69d35f14f16d7e45098b05a1a0f03ad66d6c151d1f34
View file https://github.com/modelcontextprotocol/python-sdk/blob/61fd3a66e94793eb9f6a1e7629eca411fc3797cf/tests/server/mcpserver/test_server.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/modelcontextprotocol/python-sdk/pull/2774/{{ revealButtonHref }}
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-c191383f010475fc22bf69d35f14f16d7e45098b05a1a0f03ad66d6c151d1f34
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-c191383f010475fc22bf69d35f14f16d7e45098b05a1a0f03ad66d6c151d1f34
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-c191383f010475fc22bf69d35f14f16d7e45098b05a1a0f03ad66d6c151d1f34
https://github.com/modelcontextprotocol/python-sdk/pull/2774/files#diff-c191383f010475fc22bf69d35f14f16d7e45098b05a1a0f03ad66d6c151d1f34
Please reload this pagehttps://github.com/modelcontextprotocol/python-sdk/pull/2774/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.