pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/modelcontextprotocol/python-sdk/pull/2335.patch

result.contents[0], TextResourceContents) + assert result.contents[0].text == "Hello" + + mcp.remove_resource("resource://test") + + async with Client(mcp) as client: + with pytest.raises(MCPError, match="Unknown resource"): + await client.read_resource("resource://test") + class TestServerResourceTemplates: async def test_resource_with_params(self): @@ -920,6 +983,50 @@ def get_csv(user: str) -> str: ) ) + async def test_remove_resource_template(self): + """Test removing a resource template from the server.""" + mcp = MCPServer() + + @mcp.resource("resource://{name}/data") + def get_data(name: str) -> str: # pragma: no cover + return f"Data for {name}" + + assert len(mcp._resource_manager._templates) == 1 + + mcp.remove_resource_template("resource://{name}/data") + + assert len(mcp._resource_manager._templates) == 0 + + async def test_remove_nonexistent_resource_template(self): + """Test that removing a non-existent template raises ResourceError.""" + mcp = MCPServer() + + with pytest.raises(ResourceError, match="Unknown resource template: resource://\\{name\\}/data"): + mcp.remove_resource_template("resource://{name}/data") + + async def test_remove_resource_template_and_list(self): + """Test that a removed template doesn't appear in list_resource_templates.""" + mcp = MCPServer() + + @mcp.resource("resource://{name}/first") + def first(name: str) -> str: # pragma: no cover + return f"first {name}" + + @mcp.resource("resource://{name}/second") + def second(name: str) -> str: # pragma: no cover + return f"second {name}" + + async with Client(mcp) as client: + templates = await client.list_resource_templates() + assert len(templates.resource_templates) == 2 + + mcp.remove_resource_template("resource://{name}/first") + + async with Client(mcp) as client: + templates = await client.list_resource_templates() + assert len(templates.resource_templates) == 1 + assert templates.resource_templates[0].uri_template == "resource://{name}/second" + class TestServerResourceMetadata: """Test MCPServer @resource decorator meta parameter for list operations. @@ -1418,6 +1525,68 @@ def prompt_fn(name: str) -> str: ... # pragma: no branch with pytest.raises(MCPError, match="Missing required arguments"): await client.get_prompt("prompt_fn") + async def test_remove_prompt(self): + """Test removing a prompt from the server.""" + mcp = MCPServer() + + @mcp.prompt() + def fn() -> str: # pragma: no cover + return "Hello" + + assert len(mcp._prompt_manager.list_prompts()) == 1 + + mcp.remove_prompt("fn") + + assert len(mcp._prompt_manager.list_prompts()) == 0 + + async def test_remove_nonexistent_prompt(self): + """Test that removing a non-existent prompt raises PromptError.""" + mcp = MCPServer() + + with pytest.raises(PromptError, match="Unknown prompt: nonexistent"): + mcp.remove_prompt("nonexistent") + + async def test_remove_prompt_and_list(self): + """Test that a removed prompt doesn't appear in list_prompts.""" + mcp = MCPServer() + + @mcp.prompt() + def first() -> str: # pragma: no cover + return "first" + + @mcp.prompt() + def second() -> str: # pragma: no cover + return "second" + + async with Client(mcp) as client: + prompts = await client.list_prompts() + assert len(prompts.prompts) == 2 + + mcp.remove_prompt("first") + + async with Client(mcp) as client: + prompts = await client.list_prompts() + assert len(prompts.prompts) == 1 + assert prompts.prompts[0].name == "second" + + async def test_remove_prompt_and_get(self): + """Test that getting a removed prompt fails appropriately.""" + mcp = MCPServer() + + @mcp.prompt() + def fn() -> str: # pragma: no cover + return "Hello" + + async with Client(mcp) as client: + result = await client.get_prompt("fn") + assert result.messages[0].content == TextContent(text="Hello") + + mcp.remove_prompt("fn") + + async with Client(mcp) as client: + with pytest.raises(MCPError, match="Unknown prompt"): + await client.get_prompt("fn") + async def test_completion_decorator() -> None: """Test that the completion decorator registers a working handler.""" From 63bb3508a30b5251c335430d51e66c01a780255c Mon Sep 17 00:00:00 2001 From: Ryan Goldstein Date: Sun, 22 Mar 2026 19:53:38 -0400 Subject: [PATCH 2/2] fix: remove incorrect pragma: no cover from test helpers that are executed The test_remove_resource_and_read and test_remove_prompt_and_get tests call the resource/prompt before removing it, so the function bodies are covered. Remove the pragma to satisfy strict-no-cover. --- tests/server/mcpserver/test_server.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/server/mcpserver/test_server.py b/tests/server/mcpserver/test_server.py index 8a9b4029e..f96b19b43 100644 --- a/tests/server/mcpserver/test_server.py +++ b/tests/server/mcpserver/test_server.py @@ -834,7 +834,7 @@ async def test_remove_resource_and_read(self): mcp = MCPServer() @mcp.resource("resource://test") - def get_data() -> str: # pragma: no cover + def get_data() -> str: return "Hello" async with Client(mcp) as client: @@ -1574,7 +1574,7 @@ async def test_remove_prompt_and_get(self): mcp = MCPServer() @mcp.prompt() - def fn() -> str: # pragma: no cover + def fn() -> str: return "Hello" async with Client(mcp) as client: pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy