File size: 5,700 Bytes
3777688
 
 
b9a4f82
3777688
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#!/usr/bin/env python3
"""Debug script to check which endpoints are working."""

import platform
import requests
import json
from urllib.parse import urljoin


def test_endpoint(url, method="GET", headers=None, data=None, timeout=5):
    """Test a single endpoint and return detailed results."""
    try:
        if method.upper() == "GET":
            response = requests.get(url, headers=headers, timeout=timeout)
        elif method.upper() == "POST":
            response = requests.post(url, headers=headers, json=data, timeout=timeout)

        return {
            "status": "SUCCESS",
            "status_code": response.status_code,
            "response": response.text[:500],  # Limit response length
            "headers": dict(response.headers),
        }
    except requests.exceptions.ConnectionError:
        return {"status": "CONNECTION_ERROR", "error": "Cannot connect to server"}
    except requests.exceptions.Timeout:
        return {"status": "TIMEOUT", "error": "Request timed out"}
    except Exception as e:
        return {"status": "ERROR", "error": str(e)}


def check_all_endpoints():
    """Check all possible endpoints systematically."""

    print("πŸ” Debugging Endpoint Availability")
    print("=" * 60)

    # Define test cases
    test_cases = [
        # FastAPI Server (Port 8000)
        {
            "name": "FastAPI Health",
            "url": "http://localhost:8000/health",
            "method": "GET",
        },
        {"name": "FastAPI Root", "url": "http://localhost:8000/", "method": "GET"},
        {
            "name": "FastAPI API Root",
            "url": "http://localhost:8000/api/",
            "method": "GET",
        },
        # MCP Server (Port 8001)
        {"name": "MCP Root", "url": "http://localhost:8001/", "method": "GET"},
        {"name": "MCP Endpoint", "url": "http://localhost:8001/mcp", "method": "GET"},
        {
            "name": "MCP Health (if exists)",
            "url": "http://localhost:8001/health",
            "method": "GET",
        },
        # MCP Protocol Tests
        {
            "name": "MCP Initialize",
            "url": "http://localhost:8001/mcp",
            "method": "POST",
            "headers": {
                "Authorization": "Bearer local-dev-token",
                "Content-Type": "application/json",
                "Accept": "application/json, text/event-stream",
            },
            "data": {
                "jsonrpc": "2.0",
                "id": 1,
                "method": "initialize",
                "params": {
                    "protocolVersion": "2024-11-05",
                    "capabilities": {},
                    "clientInfo": {"name": "debug-client", "version": "1.0.0"},
                },
            },
        },
        {
            "name": "MCP Tools List",
            "url": "http://localhost:8001/mcp",
            "method": "POST",
            "headers": {
                "Authorization": "Bearer local-dev-token",
                "Content-Type": "application/json",
                "Accept": "application/json, text/event-stream",
            },
            "data": {"jsonrpc": "2.0", "id": 2, "method": "tools/list"},
        },
    ]

    results = {}

    for test in test_cases:
        print(f"\nπŸ§ͺ Testing: {test['name']}")
        print(f"   URL: {test['url']}")
        print(f"   Method: {test['method']}")

        result = test_endpoint(
            url=test["url"],
            method=test["method"],
            headers=test.get("headers"),
            data=test.get("data"),
        )

        results[test["name"]] = result

        if result["status"] == "SUCCESS":
            print(f"   βœ… Status: {result['status_code']}")
            if result["response"]:
                # Try to pretty print JSON
                try:
                    json_resp = json.loads(result["response"])
                    print(f"   πŸ“„ Response: {json.dumps(json_resp, indent=2)[:200]}...")
                except:
                    print(f"   πŸ“„ Response: {result['response'][:100]}...")
        else:
            print(f"   ❌ {result['status']}: {result.get('error', 'Unknown error')}")

    print("\n" + "=" * 60)
    print("πŸ“Š SUMMARY")
    print("=" * 60)

    working = []
    not_working = []

    for name, result in results.items():
        if result["status"] == "SUCCESS" and result.get("status_code", 0) < 400:
            working.append(name)
        else:
            not_working.append(name)

    print(f"\nβœ… WORKING ({len(working)}):")
    for name in working:
        status_code = results[name].get("status_code", "N/A")
        print(f"   - {name} (HTTP {status_code})")

    print(f"\n❌ NOT WORKING ({len(not_working)}):")
    for name in not_working:
        result = results[name]
        if result["status"] == "SUCCESS":
            print(f"   - {name} (HTTP {result.get('status_code', 'N/A')})")
        else:
            print(f"   - {name} ({result['status']})")

    print(f"\nπŸ”§ RECOMMENDATIONS:")

    # Check if any server is running
    fastapi_working = any("FastAPI" in name for name in working)
    mcp_working = any("MCP" in name for name in working)

    if not fastapi_working:
        print("   - Start FastAPI server: cd backend && python main.py")

    if not mcp_working:
        print(
            "   - Start MCP server: cd backend && MCP_TRANSPORT=http MCP_PORT=8001 python -m src.mcp.server"
        )

    if not working:
        print("   - Check if any servers are running: netstat -ano | findstr :8000")
        print("   - Check if any servers are running: netstat -ano | findstr :8001")

    return results


if __name__ == "__main__":
    check_all_endpoints()