docs: restructure into topical sections and add the four most-asked-for pages (#3044)
This commit is contained in:
parent
080f2a869d
commit
220d362112
1 changed files with 2403 additions and 343 deletions
28
docs_src/legacy_clients/tutorial002.py
Normal file
28
docs_src/legacy_clients/tutorial002.py
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
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)
|
||||
Loading…
Reference in a new issue