Skip to content

Add missing add_resource_template() to MCPServer - #3208

Open
okapies wants to merge 2 commits into
modelcontextprotocol:mainfrom
okapies:feature/mcpserver-add-template
Open

Add missing add_resource_template() to MCPServer#3208
okapies wants to merge 2 commits into
modelcontextprotocol:mainfrom
okapies:feature/mcpserver-add-template

Conversation

@okapies

@okapies okapies commented Jul 29, 2026

Copy link
Copy Markdown

Motivation and Context

Add the missing add_resource_template() method to MCPServer and ResourceManager to manage resource template implementations manually and independently without using the @mcp.resource decorator.

Note that this PR leaves add_template() in place to maintain backward compatibility.

How Has This Been Tested?

n/a

Breaking Changes

Non-breaking changes.

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

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 2 files

Re-trigger cubic

@okapies
okapies force-pushed the feature/mcpserver-add-template branch from ff9d657 to d13e0c4 Compare July 29, 2026 11:47

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MCPServer.add_resource_template() returns None, just like add_resource().

@okapies
okapies force-pushed the feature/mcpserver-add-template branch from d13e0c4 to 7132c85 Compare July 29, 2026 12:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant