Checks
Strands Version
1.26.0
Python Version
3.13.9
Operating System
macOS 15.7.3
Installation Method
pip
Steps to Reproduce
math_mcp_server.py:
"""Math MCP server implemented with mcp library"""
import math
from pydantic import Field
from mcp.server import FastMCP
# Create a server instance
mcp = FastMCP(name="MathServer")
@mcp.tool(description="Calculates the cosine of x.")
def cosine(x: float = Field(description="The value of x in radians")) -> float:
"""Cosine tool"""
return math.cos(x)
@mcp.tool(description="Calculates the sine of x")
def sine(x: float = Field(description="The value of x in radians")) -> float:
"""Sine tool"""
return math.sin(x)
if __name__ == "__main__":
mcp.run()
mcp_managed_client.py:
"""Basic local MCP client"""
import logging
from mcp import stdio_client, StdioServerParameters
from strands import Agent
from strands.tools.mcp import MCPClient
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.DEBUG, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
def get_agent():
stdio_mcp_client = MCPClient(
lambda: stdio_client(StdioServerParameters(command="python", args=["math_mcp_server.py"]))
)
new_agent = Agent(tools=[stdio_mcp_client])
return new_agent
#### BEGIN EXAMPLE THAT HANGS ON EXIT
def main():
agent = get_agent()
# agent("Sine 1.2 rads?") # Problem occurs regardless if you call the agent or not.
if __name__ == "__main__":
main()
#### END EXAMPLE THAT HANGS ON EXIT
#### BEGIN EXAMPLE THAT DOES NOT HANG ON EXIT
# agent = get_agent()
#### END EXAMPLE THAT DOES NOT HANG ON EXIT
print("DONE")
Final logger statements after printing "DONE":
2026-02-19 11:11:44,670 - strands.tools.mcp.mcp_client - DEBUG - removed provider consumer, count=0
2026-02-19 11:11:44,670 - strands.tools.mcp.mcp_client - DEBUG - no consumers remaining, cleaning up
2026-02-19 11:11:44,670 - strands.tools.mcp.mcp_client - DEBUG - [Thread: MainThread, Session: 5ed09f9e-fab2-45eb-9b31-8b81f376682f] exiting MCPClient context
2026-02-19 11:11:44,670 - strands.tools.mcp.mcp_client - DEBUG - [Thread: MainThread, Session: 5ed09f9e-fab2-45eb-9b31-8b81f376682f] waiting for background thread to join
Expected Behavior
Script exits without hanging.
Actual Behavior
Script hangs on exit.
Additional Context
This was also observed using aws_iam_streamablehttp_client from mcp-proxy-for-aws
Explicitly calling mcp_client.stop() will also allow the script to exit properly.
Possible Solution
No response
Related Issues
No response
Checks
Strands Version
1.26.0
Python Version
3.13.9
Operating System
macOS 15.7.3
Installation Method
pip
Steps to Reproduce
math_mcp_server.py:
mcp_managed_client.py:
Final logger statements after printing "DONE":
Expected Behavior
Script exits without hanging.
Actual Behavior
Script hangs on exit.
Additional Context
This was also observed using aws_iam_streamablehttp_client from mcp-proxy-for-aws
Explicitly calling mcp_client.stop() will also allow the script to exit properly.
Possible Solution
No response
Related Issues
No response