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}")
Copy
Ask AI
# Development: Get token from auth middlewareTOKEN=$(python -c "from mcp_server_langgraph.auth.middleware import AuthMiddleware; print(AuthMiddleware().create_token('alice'))")echo "Token: $TOKEN"
Copy
Ask AI
// In production, get token from your auth endpoint// For development, use a pre-generated tokenconst token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9...";
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())
Copy
Ask AI
curl -X POST http://localhost:8000/message \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "query": "Hello! What can you help me with today?" }'
Copy
Ask AI
const response = await fetch('http://localhost:8000/message', { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, 'Content-Type': 'application/json' }, body: JSON.stringify({ query: 'Hello! What can you help me with today?' })});const data = await response.json();console.log(data);
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)