#!/bin/bash
# Comprehensive test script for all Twenty CRM MCP tools
# Tests all Person, Company, and Opportunity operations
set -e
SERVER_URL="http://localhost:5008"
MCP_ENDPOINT="${SERVER_URL}/mcp"
echo "π§ͺ Testing all Twenty CRM MCP Tools"
echo "=================================="
echo ""
# Colors
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Initialize session
echo -e "${YELLOW}π Initializing MCP session...${NC}"
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"}
}
}')
SESSION_ID=$(echo "${SESSION_RESPONSE}" | jq -r '.result.sessionId // empty')
if [ -z "${SESSION_ID}" ]; then
echo -e "${RED}β Failed to get session ID${NC}"
exit 1
fi
echo -e "${GREEN}β
Session ID: ${SESSION_ID}${NC}"
echo ""
# Test function
test_tool() {
local tool_name=$1
local args=$2
local description=$3
echo -e "${YELLOW}Testing: ${description}${NC}"
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\": \"${tool_name}\",
\"arguments\": ${args}
}
}")
# Check if response contains content
if echo "${RESPONSE}" | jq -e '.result.content' > /dev/null 2>&1; then
echo -e "${GREEN}β
${tool_name} - SUCCESS${NC}"
echo "${RESPONSE}" | jq '.result.content[0].text | fromjson' 2>/dev/null || echo "${RESPONSE}" | jq '.result.content[0].text'
else
echo -e "${RED}β ${tool_name} - FAILED${NC}"
echo "${RESPONSE}" | jq '.'
return 1
fi
echo ""
}
# Company Tests
echo "ββββββββββββββββββββββββββββ"
echo "π’ COMPANY TESTS"
echo "ββββββββββββββββββββββββββββ"
echo ""
test_tool "list-companies" '{}' "List all companies"
test_tool "get-company" '{"id":"06290608-8bf0-4806-99ae-a715a6a93fad"}' "Get Notion company"
# Person Tests
echo "ββββββββββββββββββββββββββββ"
echo "π€ PERSON TESTS"
echo "ββββββββββββββββββββββββββββ"
echo ""
test_tool "list-persons" '{}' "List all persons"
test_tool "get-person" '{"id":"cffa1183-f1bb-4bd7-aa9a-ff43cd036fa5"}' "Get Ivan Zhao"
# Opportunity Tests
echo "ββββββββββββββββββββββββββββ"
echo "πΌ OPPORTUNITY TESTS"
echo "ββββββββββββββββββββββββββββ"
echo ""
test_tool "list-opportunities" '{}' "List all opportunities"
echo ""
echo "ββββββββββββββββββββββββββββ"
echo -e "${GREEN}β
All tests completed!${NC}"
echo "ββββββββββββββββββββββββββββ"