diff options
Diffstat (limited to 'servers/hello_world/tests/test_prompts.py')
| -rw-r--r-- | servers/hello_world/tests/test_prompts.py | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/servers/hello_world/tests/test_prompts.py b/servers/hello_world/tests/test_prompts.py new file mode 100644 index 0000000..9709718 --- /dev/null +++ b/servers/hello_world/tests/test_prompts.py @@ -0,0 +1,47 @@ +import pytest +import asyncio +from unittest.mock import AsyncMock, MagicMock, patch +import mcp.types as types +from mcp_server_hello_world.server import HelloWorldServer, create_server, GREETING_PROMPT_TEMPLATE + +class TestPrompts: + """Test the prompt functionality.""" + + @pytest.mark.asyncio + async def test_list_prompts(self): + """Test the list_prompts method.""" + # Create a server + mcp = create_server() + + # Get the list of prompts + prompts = await mcp.list_prompts() + + # Verify the result + assert len(prompts) == 1 + assert prompts[0].name == "greeting" + assert "simple greeting prompt" in prompts[0].description.lower() + + @pytest.mark.asyncio + async def test_get_prompt(self): + """Test the get_prompt method.""" + # Create a server + mcp = create_server() + + # Get the prompt + prompt = await mcp.get_prompt("greeting", {"name": "Test User"}) + + # Verify the result + expected_prompt = GREETING_PROMPT_TEMPLATE.format(name="Test User") + assert len(prompt.messages) > 0 + assert prompt.messages[0].role == "user" + assert prompt.messages[0].content.type == "text" + assert expected_prompt.strip() in prompt.messages[0].content.text + + # Test with unknown prompt + with pytest.raises(ValueError): + await mcp.get_prompt("unknown", {"name": "Test User"}) + + # Test with missing name argument + with pytest.raises(ValueError) as excinfo: + await mcp.get_prompt("greeting", {}) + assert "Missing required arguments" in str(excinfo.value) |
