File tree Expand file tree Collapse file tree 3 files changed +50
-0
lines changed
Expand file tree Collapse file tree 3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ from fastmcp import FastMCP
2+ import time
3+
4+ app = FastMCP ()
5+
6+ @app .tool ("say" )
7+ def say (input : str ) -> str :
8+ """Says something."""
9+ time .sleep (5 )
10+ return f"{ input } !"
11+
12+ if __name__ == "__main__" :
13+ app .run (transport = "http" , host = "localhost" , port = 8080 )
14+ # app.run()
Original file line number Diff line number Diff line change 1+ from datetime import timedelta
2+ from strands .tools .mcp import MCPClient
3+ from mcp .client .streamable_http import streamablehttp_client
4+ from strands import Agent
5+ import logging
6+ import asyncio
7+
8+ logging .getLogger ("strands.tools.mcp" ).setLevel (logging .DEBUG )
9+
10+ # Add a handler to see the logs
11+ logging .basicConfig (
12+ format = "%(levelname)s | %(name)s | %(message)s" ,
13+ handlers = [logging .StreamHandler ()]
14+ )
15+
16+ client = MCPClient (lambda : streamablehttp_client (
17+ sse_read_timeout = 2 ,
18+ url = "http://localhost:8080/mcp" ))
19+
20+ with client as mcp :
21+ try :
22+ # mcp.call_tool_sync(tool_use_id="123", name="say", arguments={"input": "Hello!"})
23+ agent = Agent (tools = [mcp .list_tools_sync ()])
24+ while True :
25+
26+ agent (input ("\n Input: " ))
27+ except Exception as e :
28+ print (f"\n \n \n \n \n HERE: { e } " )
29+
30+ # async def call_say_tool():
31+ # await mcp.call_tool_async(tool_use_id="123", name="say", arguments={"input": "Hello!"})
32+
33+ # asyncio.run(call_say_tool())
34+ # agent = Agent(tools=[mcp.list_tools_sync()])
35+ # agent("Use the say tool three times in one request to say the world \"Hello\" \"there\" \"world!\"")
36+ # print(agent.messages)
You can’t perform that action at this time.
0 commit comments