MCPcopy Index your code
hub / github.com/modelcontextprotocol/python-sdk / test_prompt_title

Function test_prompt_title

tests/server/mcpserver/test_title.py:89–118  ·  view source on GitHub ↗

Test that prompt titles work correctly.

()

Source from the content-addressed store, hash-verified

87
88@pytest.mark.anyio
89async 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

Callers

nothing calls this directly

Calls 3

MCPServerClass · 0.90
ClientClass · 0.90
list_promptsMethod · 0.45

Tested by

no test coverage detected