Skip to content

Instantly share code, notes, and snippets.

@hunzo
Created August 7, 2026 05:13
Show Gist options
  • Select an option

  • Save hunzo/91ebbfe568f812bcf8a119930898c9c9 to your computer and use it in GitHub Desktop.

Select an option

Save hunzo/91ebbfe568f812bcf8a119930898c9c9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# ==========================================
# Configuration
# ==========================================
DOMAIN="http://localhost:4000"
LITELLM_KEY="sk-1234xxxx" # เปลี่ยนเป็น API Key ของคุณ
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
YELLOW='\033[1;33m'
NC='\033[0m'
# Common Headers
HEADERS=(
-H "Authorization: Bearer ${LITELLM_KEY}"
-H "Content-Type: application/json"
-H "Accept: application/json, text/event-stream"
)
# Helper function เพื่อแปลง SSE Data เป็น JSON ผ่าน jq
parse_sse_json() {
grep '^data: ' | sed 's/^data: //' | jq '.'
}
echo -e "${CYAN}==========================================${NC}"
echo -e "${CYAN} Testing MCP Streamable HTTP (Full Flow) ${NC}"
echo -e "${CYAN} Domain: ${DOMAIN}/mcp/ ${NC}"
echo -e "${CYAN}==========================================${NC}"
# ------------------------------------------
# Step 1: Initialize
# ------------------------------------------
echo -e "\n${BLUE}[Step 1] Sending 'initialize'...${NC}"
INIT_RESPONSE=$(curl -s -X POST "${DOMAIN}/mcp/" \
"${HEADERS[@]}" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "bash-mcp-tester",
"version": "1.0.0"
}
}
}')
echo "$INIT_RESPONSE" | parse_sse_json
# ------------------------------------------
# Step 2: Initialized Notification
# ------------------------------------------
echo -e "\n${BLUE}[Step 2] Sending 'notifications/initialized'...${NC}"
NOTIF_STATUS=$(curl -s -o /dev/null -w "%{http_code}" -X POST "${DOMAIN}/mcp/" \
"${HEADERS[@]}" \
-d '{
"jsonrpc": "2.0",
"method": "notifications/initialized",
"params": {}
}')
if [ "$NOTIF_STATUS" -eq 200 ] || [ "$NOTIF_STATUS" -eq 202 ] || [ "$NOTIF_STATUS" -eq 204 ]; then
echo -e "${GREEN}✓ Initialized notification sent successfully (HTTP ${NOTIF_STATUS})${NC}"
else
echo -e "${YELLOW}! Sent notification (HTTP ${NOTIF_STATUS})${NC}"
fi
# ------------------------------------------
# Step 3: Tools List
# ------------------------------------------
echo -e "\n${BLUE}[Step 3] Sending 'tools/list'...${NC}"
TOOLS_RESPONSE=$(curl -s -X POST "${DOMAIN}/mcp/" \
"${HEADERS[@]}" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list",
"params": {}
}')
echo "$TOOLS_RESPONSE" | parse_sse_json
# ------------------------------------------
# Step 4: Summary (Extracting Tool Names)
# ------------------------------------------
echo -e "\n${BLUE}[Summary] Available Tools Summary:${NC}"
TOOL_NAMES=$(echo "$TOOLS_RESPONSE" | grep '^data: ' | sed 's/^data: //' | jq -r '.result.tools[].name' 2>/dev/null)
if [ -n "$TOOL_NAMES" ]; then
echo "$TOOL_NAMES" | while read -r name; do
echo -e " - ${GREEN}${name}${NC}"
done
else
echo -e "${YELLOW}No tools found or failed to parse tool list.${NC}"
fi
echo -e "\n${CYAN}==========================================${NC}"
echo -e "${GREEN}MCP Lifecycle Test Completed!${NC}"
echo -e "${CYAN}==========================================${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment