#!/bin/bash # # End-to-End Test Script for CODEX MCP Server # Tests all 6 tools via JSON-RPC 2.0 protocol over stdin/stdout # set -e PROJECT_DIR="/home/svrnty/codex/OpenHarbor.MCP" SERVER_PROJECT="$PROJECT_DIR/samples/CodexMcpServer" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color echo -e "${BLUE}================================${NC}" echo -e "${BLUE}CODEX MCP Server - E2E Test${NC}" echo -e "${BLUE}================================${NC}" echo "" # Function to send JSON-RPC request and capture response test_mcp_request() { local test_name="$1" local request="$2" local timeout_secs="${3:-3}" echo -e "${YELLOW}Test: ${test_name}${NC}" echo -e "Request: ${request}" # Send request to server with timeout response=$(echo "$request" | timeout "$timeout_secs" dotnet run --project "$SERVER_PROJECT" 2>&1 | grep -v "Building..." | grep -v "Determining projects" | grep -v "Restore" | grep -v "warnings" || true) if [ -z "$response" ]; then echo -e "${RED}✗ FAILED: No response received${NC}" return 1 fi # Check if response contains valid JSON-RPC structure if echo "$response" | jq -e '.jsonrpc' > /dev/null 2>&1; then echo -e "${GREEN}✓ PASSED${NC}" echo -e "Response: $(echo "$response" | jq -c .)" echo "" return 0 else echo -e "${RED}✗ FAILED: Invalid JSON-RPC response${NC}" echo -e "Response: $response" echo "" return 1 fi } # Track test results PASSED=0 FAILED=0 echo -e "${BLUE}Building server...${NC}" dotnet build "$SERVER_PROJECT" > /dev/null 2>&1 echo -e "${GREEN}✓ Build successful${NC}" echo "" # Test 1: List all tools echo -e "${BLUE}--- Test 1: List Tools (tools/list) ---${NC}" if test_mcp_request "List all available tools" \ '{"jsonrpc":"2.0","id":"1","method":"tools/list"}' 5; then ((PASSED++)) else ((FAILED++)) fi # Test 2: Search CODEX (will fail if API not running, but server should return proper error) echo -e "${BLUE}--- Test 2: Search CODEX Tool ---${NC}" if test_mcp_request "Call search_codex tool" \ '{"jsonrpc":"2.0","id":"2","method":"tools/call","params":{"name":"search_codex","arguments":{"query":"test"}}}' 5; then ((PASSED++)) else ((FAILED++)) fi # Test 3: Get Document Tool echo -e "${BLUE}--- Test 3: Get Document Tool ---${NC}" if test_mcp_request "Call get_document tool" \ '{"jsonrpc":"2.0","id":"3","method":"tools/call","params":{"name":"get_document","arguments":{"id":"test123"}}}' 5; then ((PASSED++)) else ((FAILED++)) fi # Test 4: List Documents Tool echo -e "${BLUE}--- Test 4: List Documents Tool ---${NC}" if test_mcp_request "Call list_documents tool" \ '{"jsonrpc":"2.0","id":"4","method":"tools/call","params":{"name":"list_documents","arguments":{"page":1,"pageSize":10}}}' 5; then ((PASSED++)) else ((FAILED++)) fi # Test 5: Search By Tag Tool echo -e "${BLUE}--- Test 5: Search By Tag Tool ---${NC}" if test_mcp_request "Call search_by_tag tool" \ '{"jsonrpc":"2.0","id":"5","method":"tools/call","params":{"name":"search_by_tag","arguments":{"tag":"architecture"}}}' 5; then ((PASSED++)) else ((FAILED++)) fi # Test 6: Get Document Sections Tool echo -e "${BLUE}--- Test 6: Get Document Sections Tool ---${NC}" if test_mcp_request "Call get_document_sections tool" \ '{"jsonrpc":"2.0","id":"6","method":"tools/call","params":{"name":"get_document_sections","arguments":{"id":"doc123"}}}' 5; then ((PASSED++)) else ((FAILED++)) fi # Test 7: List Tags Tool echo -e "${BLUE}--- Test 7: List Tags Tool ---${NC}" if test_mcp_request "Call list_tags tool" \ '{"jsonrpc":"2.0","id":"7","method":"tools/call","params":{"name":"list_tags"}}' 5; then ((PASSED++)) else ((FAILED++)) fi # Test 8: Error Handling - Unknown Method echo -e "${BLUE}--- Test 8: Error Handling (Unknown Method) ---${NC}" if test_mcp_request "Call unknown method" \ '{"jsonrpc":"2.0","id":"8","method":"unknown/method"}' 5; then ((PASSED++)) else ((FAILED++)) fi # Test 9: Error Handling - Unknown Tool echo -e "${BLUE}--- Test 9: Error Handling (Unknown Tool) ---${NC}" if test_mcp_request "Call nonexistent tool" \ '{"jsonrpc":"2.0","id":"9","method":"tools/call","params":{"name":"nonexistent_tool","arguments":{}}}' 5; then ((PASSED++)) else ((FAILED++)) fi # Test 10: Error Handling - Missing Tool Name echo -e "${BLUE}--- Test 10: Error Handling (Missing Tool Name) ---${NC}" if test_mcp_request "Call tool without name parameter" \ '{"jsonrpc":"2.0","id":"10","method":"tools/call","params":{"arguments":{}}}' 5; then ((PASSED++)) else ((FAILED++)) fi # Summary echo -e "${BLUE}================================${NC}" echo -e "${BLUE}Test Summary${NC}" echo -e "${BLUE}================================${NC}" echo -e "${GREEN}Passed: $PASSED${NC}" echo -e "${RED}Failed: $FAILED${NC}" echo -e "Total: $((PASSED + FAILED))" echo "" if [ $FAILED -eq 0 ]; then echo -e "${GREEN}✓ All tests passed!${NC}" echo "" echo -e "${BLUE}Next Steps:${NC}" echo "1. Ensure CODEX API is running at http://localhost:5050" echo "2. Configure Claude Desktop with this MCP server" echo "3. Ask Claude to search your CODEX knowledge base!" exit 0 else echo -e "${RED}✗ Some tests failed${NC}" echo "" echo -e "${YELLOW}Troubleshooting:${NC}" echo "- Check if CODEX API is running at http://localhost:5050" echo "- Verify the server builds: dotnet build $SERVER_PROJECT" echo "- Run tests: dotnet test" exit 1 fi