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
20
docs_src/sampling_and_roots/tutorial002.py
Normal file
20
docs_src/sampling_and_roots/tutorial002.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from typing import Annotated
|
||||
|
||||
from mcp_types import ListRootsResult
|
||||
|
||||
from mcp.server import MCPServer
|
||||
from mcp.server.mcpserver import ListRoots, Resolve
|
||||
|
||||
mcp = MCPServer("Bookshop")
|
||||
|
||||
|
||||
def workspace_roots() -> ListRoots:
|
||||
return ListRoots()
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
async def catalog_folder(roots: Annotated[ListRootsResult, Resolve(workspace_roots)]) -> str:
|
||||
"""Pick the folder the catalog export should go to."""
|
||||
if not roots.roots:
|
||||
return "No workspace folders shared."
|
||||
return str(roots.roots[0].uri)
|
||||
Loading…
Reference in a new issue