|
| 1 | +#!/bin/bash |
| 2 | +# Test agentic tools via HTTP transport with structured outputs |
| 3 | + |
| 4 | +set -e |
| 5 | + |
| 6 | +PORT="${CODEGRAPH_HTTP_PORT:-3000}" |
| 7 | +HOST="${CODEGRAPH_HTTP_HOST:-127.0.0.1}" |
| 8 | +BASE_URL="http://${HOST}:${PORT}" |
| 9 | + |
| 10 | +echo "🌐 Testing CodeGraph HTTP Server with Structured Outputs" |
| 11 | +echo "==================================================" |
| 12 | +echo "Server: $BASE_URL" |
| 13 | +echo "" |
| 14 | + |
| 15 | +# Check if server is running |
| 16 | +echo "1. Health Check..." |
| 17 | +if curl -sf "${BASE_URL}/health" > /dev/null; then |
| 18 | + echo "✅ Server is running" |
| 19 | +else |
| 20 | + echo "❌ Server not running. Start with:" |
| 21 | + echo " ./target/release/codegraph start http --port $PORT" |
| 22 | + exit 1 |
| 23 | +fi |
| 24 | + |
| 25 | +echo "" |
| 26 | +echo "2. Initialize MCP connection..." |
| 27 | +INIT_RESPONSE=$(curl -s -X POST "${BASE_URL}/mcp" \ |
| 28 | + -H "Content-Type: application/json" \ |
| 29 | + -d '{ |
| 30 | + "jsonrpc": "2.0", |
| 31 | + "id": 1, |
| 32 | + "method": "initialize", |
| 33 | + "params": { |
| 34 | + "protocolVersion": "2025-06-18", |
| 35 | + "capabilities": {}, |
| 36 | + "clientInfo": {"name": "http-tester", "version": "1.0"} |
| 37 | + } |
| 38 | + }') |
| 39 | + |
| 40 | +echo "$INIT_RESPONSE" | jq '.' 2>/dev/null || echo "$INIT_RESPONSE" |
| 41 | + |
| 42 | +if echo "$INIT_RESPONSE" | grep -q '"result"'; then |
| 43 | + echo "✅ MCP initialized" |
| 44 | +else |
| 45 | + echo "❌ Initialize failed" |
| 46 | + exit 1 |
| 47 | +fi |
| 48 | + |
| 49 | +echo "" |
| 50 | +echo "3. Test agentic_code_search with structured output..." |
| 51 | +echo " Query: How is configuration loaded in this codebase?" |
| 52 | +echo " Expected: structured_output with components[] containing file paths" |
| 53 | +echo "" |
| 54 | + |
| 55 | +SEARCH_RESPONSE=$(curl -s -X POST "${BASE_URL}/mcp" \ |
| 56 | + -H "Content-Type: application/json" \ |
| 57 | + -d '{ |
| 58 | + "jsonrpc": "2.0", |
| 59 | + "id": 201, |
| 60 | + "method": "tools/call", |
| 61 | + "params": { |
| 62 | + "name": "agentic_code_search", |
| 63 | + "arguments": { |
| 64 | + "query": "How is configuration loaded in this codebase? Find all config loading mechanisms." |
| 65 | + } |
| 66 | + } |
| 67 | + }') |
| 68 | + |
| 69 | +# Save full response |
| 70 | +echo "$SEARCH_RESPONSE" > test_http_search_response.json |
| 71 | +echo "📁 Full response saved to: test_http_search_response.json" |
| 72 | + |
| 73 | +# Extract and display structured output |
| 74 | +echo "" |
| 75 | +echo "Response Analysis:" |
| 76 | +echo "==================================================" |
| 77 | + |
| 78 | +if echo "$SEARCH_RESPONSE" | jq -e '.result[0].content[0].text' > /dev/null 2>&1; then |
| 79 | + RESULT_TEXT=$(echo "$SEARCH_RESPONSE" | jq -r '.result[0].content[0].text') |
| 80 | + |
| 81 | + # Parse the result text as JSON |
| 82 | + echo "$RESULT_TEXT" > /tmp/result_parsed.json |
| 83 | + |
| 84 | + if echo "$RESULT_TEXT" | jq -e '.structured_output' > /dev/null 2>&1; then |
| 85 | + echo "✅ Structured output present!" |
| 86 | + echo "" |
| 87 | + echo "Components found:" |
| 88 | + echo "$RESULT_TEXT" | jq -r '.structured_output.components[] | " - \(.name) in \(.file_path):\(.line_number // 0)"' 2>/dev/null | head -5 |
| 89 | + |
| 90 | + echo "" |
| 91 | + echo "Patterns identified:" |
| 92 | + echo "$RESULT_TEXT" | jq -r '.structured_output.patterns[]' 2>/dev/null | head -3 |
| 93 | + |
| 94 | + echo "" |
| 95 | + COMP_COUNT=$(echo "$RESULT_TEXT" | jq '.structured_output.components | length' 2>/dev/null) |
| 96 | + echo "Total components with file paths: $COMP_COUNT" |
| 97 | + echo "Steps taken: $(echo "$RESULT_TEXT" | jq -r '.steps_taken')" |
| 98 | + else |
| 99 | + echo "⚠️ No structured_output field found" |
| 100 | + echo "Response keys:" |
| 101 | + echo "$RESULT_TEXT" | jq 'keys' 2>/dev/null || echo "$RESULT_TEXT" | head -20 |
| 102 | + fi |
| 103 | +else |
| 104 | + echo "❌ Failed to extract result from response" |
| 105 | + echo "$SEARCH_RESPONSE" | jq '.' 2>/dev/null || echo "$SEARCH_RESPONSE" |
| 106 | +fi |
| 107 | + |
| 108 | +echo "" |
| 109 | +echo "==================================================" |
| 110 | +echo "📋 Full results in: test_http_search_response.json" |
| 111 | +echo "💡 Inspect with: jq '.result[0].content[0].text | fromjson' test_http_search_response.json" |
0 commit comments