Extend resolver DI to sampling and roots requests (#3049)
This commit is contained in:
parent
53117cb3a9
commit
d287c9868f
1 changed files with 1134 additions and 200 deletions
22
docs_src/sampling_and_roots/tutorial001.py
Normal file
22
docs_src/sampling_and_roots/tutorial001.py
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
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 draft_blurb(title: str) -> Sample:
|
||||
prompt = f"Write a one-sentence blurb for the book {title!r}."
|
||||
return Sample(
|
||||
[SamplingMessage(role="user", content=TextContent(type="text", text=prompt))],
|
||||
max_tokens=60,
|
||||
)
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
async def blurb(title: str, draft: Annotated[CreateMessageResult, Resolve(draft_blurb)]) -> str:
|
||||
"""Draft a blurb for a book."""
|
||||
return draft.content.text if draft.content.type == "text" else "No blurb."
|
||||
Loading…
Reference in a new issue