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.diff

rce://{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. @@ -1427,6 +1534,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: + 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.""" 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