#!/bin/bash
# Manual test script for MCP server
# Usage: ./test-manual.sh
set -e
# Colors
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Test Data Constants
TEST_USERNAME="ravindra-adireddy"
TEST_FROM="2025-02-01T00:00:00Z"
TEST_TO="2025-12-31T23:59:59Z"
TEST_REPOS='["radireddy/AiApps"]'
echo -e "${BLUE}🧪 Testing MCP Server${NC}\n"
# Load GITHUB_TOKEN from .env file if it exists
if [ -f ".env" ]; then
# Export variables from .env file (ignoring comments and empty lines)
set -a
source .env 2>/dev/null || true
set +a
fi
# Check if GITHUB_TOKEN is set
if [ -z "$GITHUB_TOKEN" ]; then
echo -e "${YELLOW}⚠️ Warning: GITHUB_TOKEN not set${NC}"
echo " Set it in .env file: GITHUB_TOKEN=your_token_here"
echo " Or export it: export GITHUB_TOKEN=your_token_here"
echo ""
fi
# Check if server is built
if [ ! -f "dist/mcp/server.js" ]; then
echo -e "${YELLOW}Building server...${NC}"
npm run build
fi
# Helper function to send MCP request with proper Content-Length header
send_mcp_request() {
local json_request="$1"
# Add newline to match MCP protocol (as done in test-server.ts)
local request_with_newline="${json_request}"$'\n'
# Calculate byte length including the newline (UTF-8)
local json_bytes=$(printf "%s" "$request_with_newline" | wc -c | tr -d '[:space:]')
# Format: Content-Length: <bytes>\r\n\r\n<json>\n
printf "Content-Length: %d\r\n\r\n%s" "$json_bytes" "$request_with_newline" | \
node dist/mcp/server.js 2>/dev/null | \
grep -v "^Content-Length:" | \
tail -n +2 | \
jq '.' 2>/dev/null || echo "Response received (install jq for pretty printing)"
}
echo -e "${BLUE}Test 1: List Tools${NC}"
echo "Request: tools/list"
echo ""
send_mcp_request '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
echo ""
echo -e "${BLUE}Test 2: Get Authored PRs (with repos and time range)${NC}"
echo "Request: github.getAuthoredPRs"
echo "Params: username=${TEST_USERNAME}, repos=${TEST_REPOS}, from=${TEST_FROM}, to=${TEST_TO}"
echo ""
REQUEST="{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/call\",\"params\":{\"name\":\"github.getAuthoredPRs\",\"arguments\":{\"username\":\"${TEST_USERNAME}\",\"repos\":${TEST_REPOS},\"from\":\"${TEST_FROM}\",\"to\":\"${TEST_TO}\"}}}"
send_mcp_request "$REQUEST"
echo ""
echo -e "${BLUE}Test 3: Get Authored PRs (with repos, using default 3-month time range)${NC}"
echo "Request: github.getAuthoredPRs"
echo "Params: username=${TEST_USERNAME}, repos=${TEST_REPOS} (from/to omitted - defaults to last 3 months)"
echo ""
REQUEST="{\"jsonrpc\":\"2.0\",\"id\":3,\"method\":\"tools/call\",\"params\":{\"name\":\"github.getAuthoredPRs\",\"arguments\":{\"username\":\"${TEST_USERNAME}\",\"repos\":${TEST_REPOS}}}}"
send_mcp_request "$REQUEST"
echo ""
echo -e "${BLUE}Test 4: Get PR Reviews${NC}"
echo "Request: github.getPRReviews"
echo "Params: username=${TEST_USERNAME}, repos=${TEST_REPOS}, from=${TEST_FROM}, to=${TEST_TO}"
echo ""
REQUEST="{\"jsonrpc\":\"2.0\",\"id\":4,\"method\":\"tools/call\",\"params\":{\"name\":\"github.getPRReviews\",\"arguments\":{\"username\":\"${TEST_USERNAME}\",\"repos\":${TEST_REPOS},\"from\":\"${TEST_FROM}\",\"to\":\"${TEST_TO}\"}}}"
send_mcp_request "$REQUEST"
echo ""
echo -e "${BLUE}Test 5: Get Review Comments${NC}"
echo "Request: github.getReviewComments"
echo "Params: username=${TEST_USERNAME}, repos=${TEST_REPOS}, from=${TEST_FROM}, to=${TEST_TO}"
echo ""
REQUEST="{\"jsonrpc\":\"2.0\",\"id\":5,\"method\":\"tools/call\",\"params\":{\"name\":\"github.getReviewComments\",\"arguments\":{\"username\":\"${TEST_USERNAME}\",\"repos\":${TEST_REPOS},\"from\":\"${TEST_FROM}\",\"to\":\"${TEST_TO}\"}}}"
send_mcp_request "$REQUEST"
echo ""
echo -e "${BLUE}Test 6: Get Comment Impact${NC}"
echo "Request: github.getCommentImpact"
echo "Params: username=${TEST_USERNAME}, repos=${TEST_REPOS}, from=${TEST_FROM}, to=${TEST_TO}"
echo ""
REQUEST="{\"jsonrpc\":\"2.0\",\"id\":6,\"method\":\"tools/call\",\"params\":{\"name\":\"github.getCommentImpact\",\"arguments\":{\"username\":\"${TEST_USERNAME}\",\"repos\":${TEST_REPOS},\"from\":\"${TEST_FROM}\",\"to\":\"${TEST_TO}\"}}}"
send_mcp_request "$REQUEST"
echo ""
echo -e "${BLUE}Test 7: Get User Comments${NC}"
echo "Request: github.getUserComments"
echo "Params: username=${TEST_USERNAME}, repos=${TEST_REPOS}, from=${TEST_FROM}, to=${TEST_TO}"
echo ""
REQUEST="{\"jsonrpc\":\"2.0\",\"id\":7,\"method\":\"tools/call\",\"params\":{\"name\":\"github.getUserComments\",\"arguments\":{\"username\":\"${TEST_USERNAME}\",\"repos\":${TEST_REPOS},\"from\":\"${TEST_FROM}\",\"to\":\"${TEST_TO}\"}}}"
send_mcp_request "$REQUEST"
echo ""
echo -e "${BLUE}Test 8: Get User Repository Statistics${NC}"
echo "Request: github.getUserRepoStats"
echo "Params: username=${TEST_USERNAME}, repos=${TEST_REPOS}, from=${TEST_FROM}, to=${TEST_TO}"
echo ""
REQUEST="{\"jsonrpc\":\"2.0\",\"id\":8,\"method\":\"tools/call\",\"params\":{\"name\":\"github.getUserRepoStats\",\"arguments\":{\"username\":\"${TEST_USERNAME}\",\"repos\":${TEST_REPOS},\"from\":\"${TEST_FROM}\",\"to\":\"${TEST_TO}\"}}}"
send_mcp_request "$REQUEST"
echo ""
echo -e "${BLUE}Test 9: Get User Repository Statistics (using default 3-month time range)${NC}"
echo "Request: github.getUserRepoStats"
echo "Params: username=${TEST_USERNAME}, repos=${TEST_REPOS} (from/to omitted - defaults to last 3 months)"
echo ""
REQUEST="{\"jsonrpc\":\"2.0\",\"id\":9,\"method\":\"tools/call\",\"params\":{\"name\":\"github.getUserRepoStats\",\"arguments\":{\"username\":\"${TEST_USERNAME}\",\"repos\":${TEST_REPOS}}}}"
send_mcp_request "$REQUEST"
echo ""
echo -e "${GREEN}✅ Tests completed!${NC}"
echo ""
echo "Tip: Install 'jq' for pretty JSON output: brew install jq"