import anthropic
from rich import print
from dotenv import load_dotenv
import os
load_dotenv()
# Your Observee MCP server URL
# Replace {your_client_id} with your actual client ID from the Observee dashboard
url = 'https://mcp.observee.ai/mcp?client_id={your_client_id}'
client = anthropic.Anthropic()
# Create streaming response with MCP server connection
stream = client.beta.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=1000,
messages=[{"role": "user", "content": "Check my latest email"}],
mcp_servers=[
{
"type": "url",
"url": url,
"name": "observee",
"authorization_token": "{observee_api_key}" # Replace with your API key
}
],
extra_headers={
"anthropic-beta": "mcp-client-2025-04-04"
},
stream=True
)
# Process the streaming response
print("Streaming response:")
for chunk in stream:
if chunk.type == "content_block_delta":
if chunk.delta.type == "text_delta":
print(chunk.delta.text, end="", flush=True)
elif chunk.type == "message_stop":
print("\n\nStream completed.")
break
print() # Final newline for clean output