Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
fcb2602
1
Parent(s): cc396e0
Add tests for tags in server decorators
Browse files- tests/server/test_server.py +51 -0
tests/server/test_server.py
CHANGED
|
@@ -738,3 +738,54 @@ class TestServerPrompts:
|
|
| 738 |
async with client_session(mcp._mcp_server) as client:
|
| 739 |
with pytest.raises(McpError, match="Missing required arguments"):
|
| 740 |
await client.get_prompt("prompt_fn")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 738 |
async with client_session(mcp._mcp_server) as client:
|
| 739 |
with pytest.raises(McpError, match="Missing required arguments"):
|
| 740 |
await client.get_prompt("prompt_fn")
|
| 741 |
+
|
| 742 |
+
async def test_tool_decorator_with_tags(self):
|
| 743 |
+
"""Test that the tool decorator properly sets tags."""
|
| 744 |
+
mcp = FastMCP()
|
| 745 |
+
|
| 746 |
+
@mcp.tool(tags={"example", "test-tag"})
|
| 747 |
+
def sample_tool(x: int) -> int:
|
| 748 |
+
return x * 2
|
| 749 |
+
|
| 750 |
+
# Verify the tags were set correctly
|
| 751 |
+
tools = mcp._tool_manager.list_tools()
|
| 752 |
+
assert len(tools) == 1
|
| 753 |
+
assert tools[0].tags == {"example", "test-tag"}
|
| 754 |
+
|
| 755 |
+
async def test_resource_decorator_with_tags(self):
|
| 756 |
+
"""Test that the resource decorator properly sets tags."""
|
| 757 |
+
mcp = FastMCP()
|
| 758 |
+
|
| 759 |
+
@mcp.resource("resource://sample", tags={"example", "test-tag"})
|
| 760 |
+
def sample_resource() -> str:
|
| 761 |
+
return "Sample resource"
|
| 762 |
+
|
| 763 |
+
# Verify the tags were set correctly
|
| 764 |
+
resources = mcp._resource_manager.list_resources()
|
| 765 |
+
assert len(resources) == 1
|
| 766 |
+
assert resources[0].tags == {"example", "test-tag"}
|
| 767 |
+
|
| 768 |
+
async def test_template_decorator_with_tags(self):
|
| 769 |
+
"""Test that the template decorator properly sets tags."""
|
| 770 |
+
mcp = FastMCP()
|
| 771 |
+
|
| 772 |
+
@mcp.resource("resource://{param}", tags={"template", "test-tag"})
|
| 773 |
+
def template_resource(param: str) -> str:
|
| 774 |
+
return f"Template resource: {param}"
|
| 775 |
+
|
| 776 |
+
templates = mcp._resource_manager.list_templates()
|
| 777 |
+
assert len(templates) == 1
|
| 778 |
+
assert templates[0].tags == {"template", "test-tag"}
|
| 779 |
+
|
| 780 |
+
async def test_prompt_decorator_with_tags(self):
|
| 781 |
+
"""Test that the prompt decorator properly sets tags."""
|
| 782 |
+
mcp = FastMCP()
|
| 783 |
+
|
| 784 |
+
@mcp.prompt(tags={"example", "test-tag"})
|
| 785 |
+
def sample_prompt() -> str:
|
| 786 |
+
return "Sample prompt"
|
| 787 |
+
|
| 788 |
+
# Verify the tags were set correctly
|
| 789 |
+
prompts = mcp._prompt_manager.list_prompts()
|
| 790 |
+
assert len(prompts) == 1
|
| 791 |
+
assert prompts[0].tags == {"example", "test-tag"}
|