#!/bin/bash
# Test script for list-companies endpoint
# This script tests the MCP server's list-companies tool
echo "🧪 Testing list-companies endpoint..."
echo ""
# Load environment
if [ ! -f .env ]; then
echo "❌ .env file not found"
exit 1
fi
# Get the server URL
SERVER_URL="http://localhost:5008"
MCP_ENDPOINT="${SERVER_URL}/mcp"
echo "📍 Server: ${MCP_ENDPOINT}"
echo ""
# Step 1: Initialize session
echo "1️⃣ Initializing MCP session..."
SESSION_RESPONSE=$(curl -s -X POST "${MCP_ENDPOINT}" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
}
}')
echo "Response: ${SESSION_RESPONSE}"
# Extract session ID from response header
SESSION_ID=$(echo "${SESSION_RESPONSE}" | grep -o '"sessionId":"[^"]*"' | cut -d'"' -f4 || echo "")
if [ -z "${SESSION_ID}" ]; then
echo "❌ Failed to get session ID"
echo "Response was: ${SESSION_RESPONSE}"
exit 1
fi
echo "✅ Session ID: ${SESSION_ID}"
echo ""
# Step 2: Call list-companies tool
echo "2️⃣ Calling list-companies tool..."
TOOL_RESPONSE=$(curl -s -X POST "${MCP_ENDPOINT}" \
-H "Content-Type: application/json" \
-H "mcp-session-id: ${SESSION_ID}" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "list-companies",
"arguments": {}
}
}')
echo ""
echo "📦 Response:"
echo "${TOOL_RESPONSE}" | jq '.' 2>/dev/null || echo "${TOOL_RESPONSE}"
echo ""
# Check if successful
if echo "${TOOL_RESPONSE}" | grep -q '"content"'; then
echo "✅ list-companies endpoint working!"
else
echo "❌ list-companies endpoint failed"
exit 1
fi