Skip to content

Add missing add_resource_template() to MCPServer - #3208

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

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.

Fixes #3333.

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
@github-actions github-actions Bot added the missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md) label Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

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 missing-issue-link label, or adding bypass-issue-check bypasses the check.

@okapies

okapies commented Aug 19, 2026

Copy link
Copy Markdown
Author

Opened #3333 for this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

missing-issue-link Auto-closed: PR needs a linked issue assigned to its author (see CONTRIBUTING.md)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add add_resource_template() to MCPServer

1 participant