test_session_issue.pyā¢772 B
#!/usr/bin/env python3
"""Test to demonstrate the session ID issue."""
class MockSession:
"""Mock session object."""
pass
def test_session_id_stability():
"""Test if id() is stable across different calls."""
# Simulate first tool call
session1 = MockSession()
id1 = id(session1)
print(f"First call - Session ID: {id1}")
# Simulate second tool call - NEW session object
session2 = MockSession()
id2 = id(session2)
print(f"Second call - Session ID: {id2}")
# In MCP, each tool call gets a NEW Context object
# but we need persistent session state
print(f"\nAre they the same? {id1 == id2}")
print(f"This is why tokens are lost between tool calls!")
if __name__ == "__main__":
test_session_id_stability()