File size: 984 Bytes
ada812e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
"""
 Source :https://github.com/modelcontextprotocol/python-sdk/blob/6353dd192c41b891ef3bf1dfc093db46f6e2175a/README.md?plain=1#L779
 
Author: Alex Punnen
Status:  Demo
"""

from mcp.client.streamable_http import streamablehttp_client
from mcp import ClientSession


async def main():
    # Connect to a streamable HTTP server
    async with streamablehttp_client("http://127.0.0.0:4200/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()
            # Call a tool
            tools = await session.list_tools()
            print("Available tools:", tools)
            tool_result = await session.call_tool("add", {"a": 1, "b": 2})
            print("Tool result:", tool_result)
            
if __name__ == "__main__":
    import asyncio
    asyncio.run(main())