README - replace code snippets with examples - streamable http (#1155)
This commit is contained in:
parent
0b4ce00be2
commit
e975d0550b
4 changed files with 186 additions and 73 deletions
|
|
@ -1,6 +1,4 @@
|
|||
"""MCP client example showing completion usage.
|
||||
|
||||
This example demonstrates how to use the completion feature in MCP clients.
|
||||
"""
|
||||
cd to the `examples/snippets` directory and run:
|
||||
uv run completion-client
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,8 +1,4 @@
|
|||
"""Client display utilities example.
|
||||
|
||||
This example shows how to use the SDK's display utilities to show
|
||||
human-readable names for tools, resources, and prompts.
|
||||
|
||||
"""
|
||||
cd to the `examples/snippets` directory and run:
|
||||
uv run display-utilities-client
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -1,6 +1,4 @@
|
|||
"""MCP client example using stdio transport.
|
||||
|
||||
This is a documentation example showing how to write an MCP client.
|
||||
"""
|
||||
cd to the `examples/snippets/clients` directory and run:
|
||||
uv run client
|
||||
"""
|
||||
|
|
|
|||
29
examples/snippets/clients/streamable_basic.py
Normal file
29
examples/snippets/clients/streamable_basic.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
"""
|
||||
Run from the repository root:
|
||||
uv run examples/snippets/clients/streamable_basic.py
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
|
||||
from mcp import ClientSession
|
||||
from mcp.client.streamable_http import streamablehttp_client
|
||||
|
||||
|
||||
async def main():
|
||||
# Connect to a streamable HTTP server
|
||||
async with streamablehttp_client("http://localhost:8000/mcp") as (
|
||||
read_stream,
|
||||
write_stream,
|
||||
_,
|
||||
):
|
||||
# Create a session using the client streams
|
||||
async with ClientSession(read_stream, write_stream) as session:
|
||||
# Initialize the connection
|
||||
await session.initialize()
|
||||
# List available tools
|
||||
tools = await session.list_tools()
|
||||
print(f"Available tools: {[tool.name for tool in tools.tools]}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Loading…
Reference in a new issue