Let’s send your first message to the MCP Server with LangGraph! This guide walks you through authentication, making a request, and understanding the response.
Before you start: Make sure you’ve completed the Quick Start and have the services running.
from mcp_server_langgraph.auth.middleware import AuthMiddleware# Create auth instanceauth = AuthMiddleware()# Get token for user 'alice'token = auth.create_token("alice", expires_in=3600)print(f"Token: {token}")
In production, obtain tokens through proper authentication flows (Keycloak OAuth2, etc.). See Authentication Guide.
2
Send Your First Message
Python
cURL
JavaScript
Copy
Ask AI
import httpx# API endpointurl = "http://localhost:8000/message"# Request with auth headerheaders = { "Authorization": f"Bearer {token}", "Content-Type": "application/json"}# Message payloaddata = { "query": "Hello! What can you help me with today?"}# Send requestresponse = httpx.post(url, headers=headers, json=data)print(response.json())
3
Understanding the Response
The agent returns a structured JSON response:
Copy
Ask AI
{ "content": "Hello! I'm an AI assistant powered by LangGraph. I can help you with:\n- Answering questions\n- Information lookup\n- Task automation\n- And more!\n\nWhat would you like to know?", "role": "assistant", "model": "gemini-2.5-flash-002", "usage": { "prompt_tokens": 28, "completion_tokens": 52, "total_tokens": 80 }, "trace_id": "a1b2c3d4-e5f6-7890-abcd-ef1234567890", "authorized": true}
## Conversation with contextconversation = [ {"role": "user", "content": "I'm learning Python"}, {"role": "assistant", "content": "Great! What would you like to know?"}, {"role": "user", "content": "How do I read a file?"}]response = httpx.post(url, headers=headers, json={ "messages": conversation})
## Agent can use tools automaticallyresponse = httpx.post(url, headers=headers, json={ "query": "Search for the latest news about AI"})## Agent will invoke search tool and return results
## Get streaming response (SSE)async with httpx.AsyncClient() as client: async with client.stream( 'POST', 'http://localhost:8000/message/stream', headers=headers, json={"query": "Tell me a story"} ) as response: async for chunk in response.aiter_text(): print(chunk, end='', flush=True)