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,24 +1,11 @@
|
|||
import anyio
|
||||
|
||||
from mcp import Client
|
||||
from mcp.server import MCPServer
|
||||
from mcp.types import TextResourceContents
|
||||
|
||||
mcp = MCPServer("Bookshop")
|
||||
|
||||
|
||||
@mcp.resource("catalog://genres")
|
||||
def genres() -> list[str]:
|
||||
"""The genres the catalog is organised by."""
|
||||
return ["fiction", "non-fiction", "poetry"]
|
||||
|
||||
|
||||
@mcp.resource("catalog://genres/{genre}")
|
||||
def books_in_genre(genre: str) -> str:
|
||||
"""Every title we stock in one genre."""
|
||||
return f"3 books filed under {genre}."
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
async with Client(mcp) as client:
|
||||
async with Client("http://localhost:8000/mcp") as client:
|
||||
listed = await client.list_resources()
|
||||
print([resource.uri for resource in listed.resources])
|
||||
|
||||
|
|
@ -29,3 +16,7 @@ async def main() -> None:
|
|||
for contents in result.contents:
|
||||
if isinstance(contents, TextResourceContents):
|
||||
print(contents.text)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
anyio.run(main)
|
||||
|
|
|
|||
Loading…
Reference in a new issue