Add missing add_resource_template() to MCPServer - #3208
Conversation
ff9d657 to
d13e0c4
Compare
There was a problem hiding this comment.
1 issue found across 1 file (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="tests/server/mcpserver/test_server.py">
<violation number="1" location="tests/server/mcpserver/test_server.py:1017">
P2: Missing assertions: `test_add_resource_template` never verifies the template was actually registered. Call `await mcp.list_resource_templates()` and assert the expected count, or use `Client` to read a resource through the template, so the test catches regressions. Without assertions the test will pass even if `add_resource_template` is a no-op.</violation>
</file>
Tip: Review your code locally with the cubic CLI to iterate faster.
Re-trigger cubic
| return "Data" | ||
|
|
||
| template = ResourceTemplate.from_function(get_data, "resource://{param}") | ||
| mcp.add_resource_template(template) |
There was a problem hiding this comment.
P2: Missing assertions: test_add_resource_template never verifies the template was actually registered. Call await mcp.list_resource_templates() and assert the expected count, or use Client to read a resource through the template, so the test catches regressions. Without assertions the test will pass even if add_resource_template is a no-op.
Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At tests/server/mcpserver/test_server.py, line 1017:
<comment>Missing assertions: `test_add_resource_template` never verifies the template was actually registered. Call `await mcp.list_resource_templates()` and assert the expected count, or use `Client` to read a resource through the template, so the test catches regressions. Without assertions the test will pass even if `add_resource_template` is a no-op.</comment>
<file context>
@@ -1004,6 +1004,18 @@ def get_csv(user: str) -> str:
+ return "Data"
+
+ template = ResourceTemplate.from_function(get_data, "resource://{param}")
+ mcp.add_resource_template(template)
+
</file context>
There was a problem hiding this comment.
MCPServer.add_resource_template() returns None, just like add_resource().
d13e0c4 to
7132c85
Compare
|
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 |
|
Opened #3333 for this PR. |
Motivation and Context
Add the missing
add_resource_template()method toMCPServerandResourceManagerto manage resource template implementations manually and independently without using the@mcp.resourcedecorator.Note that this PR leaves
add_template()in place to maintain backward compatibility.Fixes #3333.
How Has This Been Tested?
n/a
Breaking Changes
Non-breaking changes.
Types of changes
Checklist
Additional context