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)