docs: stop presenting the in-memory client as the way to connect (#3443)
This commit is contained in:
parent
0c9136841f
commit
7bb486a10f
1 changed files with 803 additions and 598 deletions
|
|
@ -1,31 +1,17 @@
|
|||
import anyio
|
||||
|
||||
from mcp import Client
|
||||
from mcp.server import MCPServer
|
||||
from mcp.types import Completion, CompletionArgument, CompletionContext, PromptReference, ResourceTemplateReference
|
||||
|
||||
mcp = MCPServer("Bookshop")
|
||||
|
||||
GENRES = ["fiction", "non-fiction", "poetry"]
|
||||
|
||||
|
||||
@mcp.prompt()
|
||||
def recommend(genre: str) -> str:
|
||||
"""Ask for a recommendation in a genre."""
|
||||
return f"Recommend one {genre} book from the catalog and say why."
|
||||
|
||||
|
||||
@mcp.completion()
|
||||
async def complete_genre(
|
||||
ref: PromptReference | ResourceTemplateReference,
|
||||
argument: CompletionArgument,
|
||||
context: CompletionContext | None,
|
||||
) -> Completion | None:
|
||||
return Completion(values=[genre for genre in GENRES if genre.startswith(argument.value)])
|
||||
from mcp.types import PromptReference
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
async with Client(mcp) as client:
|
||||
async with Client("http://localhost:8000/mcp") as client:
|
||||
result = await client.complete(
|
||||
ref=PromptReference(type="ref/prompt", name="recommend"),
|
||||
argument={"name": "genre", "value": "p"},
|
||||
)
|
||||
print(result.completion.values)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
anyio.run(main)
|
||||
|
|
|
|||
Loading…
Reference in a new issue