sse_debug.py•1.38 kB
"""
Debug script to print SSE events from the server.
This script connects to the SSE endpoint and prints all events received,
to help diagnose issues with tool registration.
"""
import requests
import sseclient
import json
import time
# SSE endpoint URL
SSE_URL = "http://localhost:8083/sse"
def print_event(event):
"""Pretty-print an SSE event."""
print("\n------- EVENT -------")
print(f"Event type: {event.event}")
try:
# Try to parse and pretty-print JSON data
data = json.loads(event.data)
print(f"Data: {json.dumps(data, indent=2)}")
except:
# If not valid JSON, print as-is
print(f"Data: {event.data}")
print("---------------------\n")
def main():
"""Connect to the SSE endpoint and print all events received."""
print(f"Connecting to SSE endpoint: {SSE_URL}")
try:
# Make a GET request to the SSE endpoint
response = requests.get(SSE_URL, stream=True)
client = sseclient.SSEClient(response)
print("Connection established. Waiting for events...")
# Process events as they arrive
for event in client.events():
print_event(event)
except KeyboardInterrupt:
print("\nExiting...")
except Exception as e:
print(f"\nError: {str(e)}")
if __name__ == "__main__":
main()