#!/bin/bash
# HTTP API Testing Script for Codebase Insights MCP Server
# This script demonstrates how to test the MCP server using curl
SERVER_URL="http://localhost:8000/mcp"
REPO_URL="https://bitbucket.org/tymerepos/tb-payshap-svc.git"
echo "๐งช Testing Codebase Insights MCP Server HTTP API"
echo " Server URL: $SERVER_URL"
echo ""
# Function to test if server is running
test_server() {
echo "๐ Testing server availability..."
response=$(curl -s -o /dev/null -w "%{http_code}" "$SERVER_URL" --max-time 5)
if [ "$response" != "200" ] && [ "$response" != "404" ]; then
echo "โ Server not responding at $SERVER_URL"
echo " Make sure the server is running with:"
echo " uvx codebase-insights-mcp --transport http --port 8000"
exit 1
fi
echo "โ
Server is responding"
echo ""
}
# Function to test server info
test_server_info() {
echo "๐ Testing get_server_info..."
response=$(curl -s -X POST "$SERVER_URL" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "get_server_info",
"arguments": {}
}
}')
echo "Response:"
echo "$response" | jq '.' 2>/dev/null || echo "$response"
echo ""
}
# Function to test collection generation
test_generate_collection() {
echo "๐๏ธ Testing generate_collection..."
echo " Repository: $REPO_URL"
response=$(curl -s -X POST "$SERVER_URL" \
-H "Content-Type: application/json" \
-d "{
\"jsonrpc\": \"2.0\",
\"id\": 2,
\"method\": \"tools/call\",
\"params\": {
\"name\": \"generate_collection\",
\"arguments\": {
\"input\": {
\"repo_url\": \"$REPO_URL\"
}
}
}
}")
echo "Response:"
echo "$response" | jq '.' 2>/dev/null || echo "$response"
echo ""
}
# Function to test tools/list
test_tools_list() {
echo "๐ง Testing tools/list..."
response=$(curl -s -X POST "$SERVER_URL" \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/list",
"params": {}
}')
echo "Available tools:"
echo "$response" | jq '.result.tools[] | {name: .name, description: .description}' 2>/dev/null || echo "$response"
echo ""
}
# Main execution
main() {
# Check if jq is available for pretty JSON formatting
if ! command -v jq &> /dev/null; then
echo "๐ Note: Install 'jq' for prettier JSON output"
echo ""
fi
test_server
test_tools_list
test_server_info
test_generate_collection
echo "โ
HTTP API testing completed!"
echo ""
echo "๐ก Tips:"
echo " - Set BITBUCKET_EMAIL and BITBUCKET_API_TOKEN for private repos"
echo " - Use different REPO_URL for testing other repositories"
echo " - Check /tmp/postman-collections/ for generated files"
}
# Allow override of repository URL
if [ "$1" != "" ]; then
REPO_URL="$1"
echo "๐ Using custom repository: $REPO_URL"
fi
main