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
29 lines
802 B
Python
29 lines
802 B
Python
from typing import Annotated
|
|
|
|
from pydantic import BaseModel
|
|
|
|
from mcp.server import MCPServer
|
|
from mcp.server.mcpserver import AcceptedElicitation, Elicit, ElicitationResult, Resolve
|
|
|
|
mcp = MCPServer("Bookshop")
|
|
|
|
|
|
class Quantity(BaseModel):
|
|
copies: int
|
|
|
|
|
|
async def ask_quantity() -> Elicit[Quantity]:
|
|
"""Resolver: ask the user how many copies to put aside."""
|
|
return Elicit("How many copies?", Quantity)
|
|
|
|
|
|
@mcp.tool()
|
|
async def reserve(title: str, quantity: Annotated[ElicitationResult[Quantity], Resolve(ask_quantity)]) -> str:
|
|
"""Reserve copies of a book, asking the user how many."""
|
|
if isinstance(quantity, AcceptedElicitation):
|
|
return f"Reserved {quantity.data.copies} of {title!r}."
|
|
return "Nothing reserved."
|
|
|
|
|
|
app = mcp.streamable_http_app(stateless_http=True)
|