49b9bb6724
Deploy Docs / deploy-docs (push) Failing after 1s
Conformance Tests / client-conformance (push) Failing after 3s
Conformance Tests / server-conformance (push) Failing after 1s
GitHub Actions Security Analysis / zizmor (push) Failing after 1s
CI / checks (push) Failing after 59m20s
CI / all-green (push) Waiting to run
27 lines
790 B
Python
27 lines
790 B
Python
from typing import Annotated
|
|
|
|
from mcp_types import CreateMessageResult, SamplingMessage, TextContent
|
|
|
|
from mcp.server import MCPServer
|
|
from mcp.server.mcpserver import Resolve, Sample
|
|
|
|
mcp = MCPServer("Bookshop")
|
|
|
|
|
|
def suggest_title(genre: str) -> Sample:
|
|
prompt = f"Suggest one {genre} book title. Answer with the title only."
|
|
return Sample(
|
|
[SamplingMessage(role="user", content=TextContent(type="text", text=prompt))],
|
|
max_tokens=50,
|
|
)
|
|
|
|
|
|
@mcp.tool()
|
|
async def recommend_book(
|
|
genre: str,
|
|
suggestion: Annotated[CreateMessageResult, Resolve(suggest_title)],
|
|
) -> str:
|
|
"""Recommend a book in the given genre."""
|
|
title = suggestion.content.text if suggestion.content.type == "text" else "the classics"
|
|
return f"Today's {genre} pick: {title}"
|