Test that prompt titles work correctly.
()
| 87 | |
| 88 | @pytest.mark.anyio |
| 89 | async def test_prompt_title(): |
| 90 | """Test that prompt titles work correctly.""" |
| 91 | mcp = MCPServer(name="PromptTitleServer") |
| 92 | |
| 93 | # Prompt with only name |
| 94 | @mcp.prompt(description="Basic prompt") |
| 95 | def basic_prompt(topic: str) -> str: # pragma: no cover |
| 96 | return f"Tell me about {topic}" |
| 97 | |
| 98 | # Prompt with title |
| 99 | @mcp.prompt(description="Titled prompt", title="Ask About Topic") |
| 100 | def titled_prompt(topic: str) -> str: # pragma: no cover |
| 101 | return f"Tell me about {topic}" |
| 102 | |
| 103 | # Start server and connect client |
| 104 | async with Client(mcp) as client: |
| 105 | # List prompts |
| 106 | prompts_result = await client.list_prompts() |
| 107 | prompts = {prompt.name: prompt for prompt in prompts_result.prompts} |
| 108 | |
| 109 | # Verify basic prompt uses name |
| 110 | assert "basic_prompt" in prompts |
| 111 | basic = prompts["basic_prompt"] |
| 112 | assert basic.title is None |
| 113 | assert basic.name == "basic_prompt" |
| 114 | |
| 115 | # Verify prompt with title |
| 116 | assert "titled_prompt" in prompts |
| 117 | titled = prompts["titled_prompt"] |
| 118 | assert titled.title == "Ask About Topic" |
| 119 | |
| 120 | |
| 121 | @pytest.mark.anyio |
nothing calls this directly
no test coverage detected