bigwolfe commited on
Commit
2e58792
Β·
1 Parent(s): c978d9a
backend/tests/integration/debug_endpoints.py DELETED
@@ -1,169 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Debug script to check which endpoints are working."""
3
-
4
- import requests
5
- import json
6
- from urllib.parse import urljoin
7
-
8
-
9
- def test_endpoint(url, method="GET", headers=None, data=None, timeout=5):
10
- """Test a single endpoint and return detailed results."""
11
- try:
12
- if method.upper() == "GET":
13
- response = requests.get(url, headers=headers, timeout=timeout)
14
- elif method.upper() == "POST":
15
- response = requests.post(url, headers=headers, json=data, timeout=timeout)
16
-
17
- return {
18
- "status": "SUCCESS",
19
- "status_code": response.status_code,
20
- "response": response.text[:500], # Limit response length
21
- "headers": dict(response.headers),
22
- }
23
- except requests.exceptions.ConnectionError:
24
- return {"status": "CONNECTION_ERROR", "error": "Cannot connect to server"}
25
- except requests.exceptions.Timeout:
26
- return {"status": "TIMEOUT", "error": "Request timed out"}
27
- except Exception as e:
28
- return {"status": "ERROR", "error": str(e)}
29
-
30
-
31
- def check_all_endpoints():
32
- """Check all possible endpoints systematically."""
33
-
34
- print("πŸ” Debugging Endpoint Availability")
35
- print("=" * 60)
36
-
37
- # Define test cases
38
- test_cases = [
39
- # FastAPI Server (Port 8000)
40
- {
41
- "name": "FastAPI Health",
42
- "url": "http://localhost:8000/health",
43
- "method": "GET",
44
- },
45
- {"name": "FastAPI Root", "url": "http://localhost:8000/", "method": "GET"},
46
- {
47
- "name": "FastAPI API Root",
48
- "url": "http://localhost:8000/api/",
49
- "method": "GET",
50
- },
51
- # MCP Server (Port 8001)
52
- {"name": "MCP Root", "url": "http://localhost:8001/", "method": "GET"},
53
- {"name": "MCP Endpoint", "url": "http://localhost:8001/mcp", "method": "GET"},
54
- {
55
- "name": "MCP Health (if exists)",
56
- "url": "http://localhost:8001/health",
57
- "method": "GET",
58
- },
59
- # MCP Protocol Tests
60
- {
61
- "name": "MCP Initialize",
62
- "url": "http://localhost:8001/mcp",
63
- "method": "POST",
64
- "headers": {
65
- "Authorization": "Bearer local-dev-token",
66
- "Content-Type": "application/json",
67
- "Accept": "application/json, text/event-stream",
68
- },
69
- "data": {
70
- "jsonrpc": "2.0",
71
- "id": 1,
72
- "method": "initialize",
73
- "params": {
74
- "protocolVersion": "2024-11-05",
75
- "capabilities": {},
76
- "clientInfo": {"name": "debug-client", "version": "1.0.0"},
77
- },
78
- },
79
- },
80
- {
81
- "name": "MCP Tools List",
82
- "url": "http://localhost:8001/mcp",
83
- "method": "POST",
84
- "headers": {
85
- "Authorization": "Bearer local-dev-token",
86
- "Content-Type": "application/json",
87
- "Accept": "application/json, text/event-stream",
88
- },
89
- "data": {"jsonrpc": "2.0", "id": 2, "method": "tools/list"},
90
- },
91
- ]
92
-
93
- results = {}
94
-
95
- for test in test_cases:
96
- print(f"\nπŸ§ͺ Testing: {test['name']}")
97
- print(f" URL: {test['url']}")
98
- print(f" Method: {test['method']}")
99
-
100
- result = test_endpoint(
101
- url=test["url"],
102
- method=test["method"],
103
- headers=test.get("headers"),
104
- data=test.get("data"),
105
- )
106
-
107
- results[test["name"]] = result
108
-
109
- if result["status"] == "SUCCESS":
110
- print(f" βœ… Status: {result['status_code']}")
111
- if result["response"]:
112
- # Try to pretty print JSON
113
- try:
114
- json_resp = json.loads(result["response"])
115
- print(f" πŸ“„ Response: {json.dumps(json_resp, indent=2)[:200]}...")
116
- except:
117
- print(f" πŸ“„ Response: {result['response'][:100]}...")
118
- else:
119
- print(f" ❌ {result['status']}: {result.get('error', 'Unknown error')}")
120
-
121
- print("\n" + "=" * 60)
122
- print("πŸ“Š SUMMARY")
123
- print("=" * 60)
124
-
125
- working = []
126
- not_working = []
127
-
128
- for name, result in results.items():
129
- if result["status"] == "SUCCESS" and result.get("status_code", 0) < 400:
130
- working.append(name)
131
- else:
132
- not_working.append(name)
133
-
134
- print(f"\nβœ… WORKING ({len(working)}):")
135
- for name in working:
136
- status_code = results[name].get("status_code", "N/A")
137
- print(f" - {name} (HTTP {status_code})")
138
-
139
- print(f"\n❌ NOT WORKING ({len(not_working)}):")
140
- for name in not_working:
141
- result = results[name]
142
- if result["status"] == "SUCCESS":
143
- print(f" - {name} (HTTP {result.get('status_code', 'N/A')})")
144
- else:
145
- print(f" - {name} ({result['status']})")
146
-
147
- print(f"\nπŸ”§ RECOMMENDATIONS:")
148
-
149
- # Check if any server is running
150
- fastapi_working = any("FastAPI" in name for name in working)
151
- mcp_working = any("MCP" in name for name in working)
152
-
153
- if not fastapi_working:
154
- print(" - Start FastAPI server: cd backend && python main.py")
155
-
156
- if not mcp_working:
157
- print(
158
- " - Start MCP server: cd backend && MCP_TRANSPORT=http MCP_PORT=8001 python -m src.mcp.server"
159
- )
160
-
161
- if not working:
162
- print(" - Check if any servers are running: netstat -ano | findstr :8000")
163
- print(" - Check if any servers are running: netstat -ano | findstr :8001")
164
-
165
- return results
166
-
167
-
168
- if __name__ == "__main__":
169
- check_all_endpoints()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
debug_endpoints.py DELETED
@@ -1,170 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Debug script to check which endpoints are working."""
3
-
4
- import platform
5
- import requests
6
- import json
7
- from urllib.parse import urljoin
8
-
9
-
10
- def test_endpoint(url, method="GET", headers=None, data=None, timeout=5):
11
- """Test a single endpoint and return detailed results."""
12
- try:
13
- if method.upper() == "GET":
14
- response = requests.get(url, headers=headers, timeout=timeout)
15
- elif method.upper() == "POST":
16
- response = requests.post(url, headers=headers, json=data, timeout=timeout)
17
-
18
- return {
19
- "status": "SUCCESS",
20
- "status_code": response.status_code,
21
- "response": response.text[:500], # Limit response length
22
- "headers": dict(response.headers),
23
- }
24
- except requests.exceptions.ConnectionError:
25
- return {"status": "CONNECTION_ERROR", "error": "Cannot connect to server"}
26
- except requests.exceptions.Timeout:
27
- return {"status": "TIMEOUT", "error": "Request timed out"}
28
- except Exception as e:
29
- return {"status": "ERROR", "error": str(e)}
30
-
31
-
32
- def check_all_endpoints():
33
- """Check all possible endpoints systematically."""
34
-
35
- print("πŸ” Debugging Endpoint Availability")
36
- print("=" * 60)
37
-
38
- # Define test cases
39
- test_cases = [
40
- # FastAPI Server (Port 8000)
41
- {
42
- "name": "FastAPI Health",
43
- "url": "http://localhost:8000/health",
44
- "method": "GET",
45
- },
46
- {"name": "FastAPI Root", "url": "http://localhost:8000/", "method": "GET"},
47
- {
48
- "name": "FastAPI API Root",
49
- "url": "http://localhost:8000/api/",
50
- "method": "GET",
51
- },
52
- # MCP Server (Port 8001)
53
- {"name": "MCP Root", "url": "http://localhost:8001/", "method": "GET"},
54
- {"name": "MCP Endpoint", "url": "http://localhost:8001/mcp", "method": "GET"},
55
- {
56
- "name": "MCP Health (if exists)",
57
- "url": "http://localhost:8001/health",
58
- "method": "GET",
59
- },
60
- # MCP Protocol Tests
61
- {
62
- "name": "MCP Initialize",
63
- "url": "http://localhost:8001/mcp",
64
- "method": "POST",
65
- "headers": {
66
- "Authorization": "Bearer local-dev-token",
67
- "Content-Type": "application/json",
68
- "Accept": "application/json, text/event-stream",
69
- },
70
- "data": {
71
- "jsonrpc": "2.0",
72
- "id": 1,
73
- "method": "initialize",
74
- "params": {
75
- "protocolVersion": "2024-11-05",
76
- "capabilities": {},
77
- "clientInfo": {"name": "debug-client", "version": "1.0.0"},
78
- },
79
- },
80
- },
81
- {
82
- "name": "MCP Tools List",
83
- "url": "http://localhost:8001/mcp",
84
- "method": "POST",
85
- "headers": {
86
- "Authorization": "Bearer local-dev-token",
87
- "Content-Type": "application/json",
88
- "Accept": "application/json, text/event-stream",
89
- },
90
- "data": {"jsonrpc": "2.0", "id": 2, "method": "tools/list"},
91
- },
92
- ]
93
-
94
- results = {}
95
-
96
- for test in test_cases:
97
- print(f"\nπŸ§ͺ Testing: {test['name']}")
98
- print(f" URL: {test['url']}")
99
- print(f" Method: {test['method']}")
100
-
101
- result = test_endpoint(
102
- url=test["url"],
103
- method=test["method"],
104
- headers=test.get("headers"),
105
- data=test.get("data"),
106
- )
107
-
108
- results[test["name"]] = result
109
-
110
- if result["status"] == "SUCCESS":
111
- print(f" βœ… Status: {result['status_code']}")
112
- if result["response"]:
113
- # Try to pretty print JSON
114
- try:
115
- json_resp = json.loads(result["response"])
116
- print(f" πŸ“„ Response: {json.dumps(json_resp, indent=2)[:200]}...")
117
- except:
118
- print(f" πŸ“„ Response: {result['response'][:100]}...")
119
- else:
120
- print(f" ❌ {result['status']}: {result.get('error', 'Unknown error')}")
121
-
122
- print("\n" + "=" * 60)
123
- print("πŸ“Š SUMMARY")
124
- print("=" * 60)
125
-
126
- working = []
127
- not_working = []
128
-
129
- for name, result in results.items():
130
- if result["status"] == "SUCCESS" and result.get("status_code", 0) < 400:
131
- working.append(name)
132
- else:
133
- not_working.append(name)
134
-
135
- print(f"\nβœ… WORKING ({len(working)}):")
136
- for name in working:
137
- status_code = results[name].get("status_code", "N/A")
138
- print(f" - {name} (HTTP {status_code})")
139
-
140
- print(f"\n❌ NOT WORKING ({len(not_working)}):")
141
- for name in not_working:
142
- result = results[name]
143
- if result["status"] == "SUCCESS":
144
- print(f" - {name} (HTTP {result.get('status_code', 'N/A')})")
145
- else:
146
- print(f" - {name} ({result['status']})")
147
-
148
- print(f"\nπŸ”§ RECOMMENDATIONS:")
149
-
150
- # Check if any server is running
151
- fastapi_working = any("FastAPI" in name for name in working)
152
- mcp_working = any("MCP" in name for name in working)
153
-
154
- if not fastapi_working:
155
- print(" - Start FastAPI server: cd backend && python main.py")
156
-
157
- if not mcp_working:
158
- print(
159
- " - Start MCP server: cd backend && MCP_TRANSPORT=http MCP_PORT=8001 python -m src.mcp.server"
160
- )
161
-
162
- if not working:
163
- print(" - Check if any servers are running: netstat -ano | findstr :8000")
164
- print(" - Check if any servers are running: netstat -ano | findstr :8001")
165
-
166
- return results
167
-
168
-
169
- if __name__ == "__main__":
170
- check_all_endpoints()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
debug_mcp_endpoint.py DELETED
@@ -1,45 +0,0 @@
1
-
2
- import asyncio
3
- import logging
4
- from fastapi.testclient import TestClient
5
- from backend.src.api.main import app
6
-
7
- # Configure logging
8
- logging.basicConfig(level=logging.DEBUG)
9
-
10
- def debug_mcp():
11
- client = TestClient(app)
12
-
13
- print("--- Test 1: GET /mcp (No Auth) ---")
14
- try:
15
- response = client.get("/mcp")
16
- print(f"Status: {response.status_code}")
17
- print(f"Body: {response.text}")
18
- except Exception as e:
19
- print(f"Crash: {e}")
20
-
21
- print("\n--- Test 2: POST /mcp (No Auth) - List Tools ---")
22
- # JSON-RPC payload
23
- payload = {
24
- "jsonrpc": "2.0",
25
- "method": "tools/list",
26
- "id": 1
27
- }
28
- try:
29
- response = client.post("/mcp", json=payload)
30
- print(f"Status: {response.status_code}")
31
- print(f"Body: {response.text}")
32
- except Exception as e:
33
- print(f"Crash: {e}")
34
-
35
- print("\n--- Test 3: POST /mcp (With Auth) - List Tools ---")
36
- try:
37
- # Assuming local-dev-token is valid
38
- response = client.post("/mcp", json=payload, headers={"Authorization": "Bearer local-dev-token"})
39
- print(f"Status: {response.status_code}")
40
- print(f"Body: {response.text}")
41
- except Exception as e:
42
- print(f"Crash: {e}")
43
-
44
- if __name__ == "__main__":
45
- debug_mcp()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
generate_jwt_token.py DELETED
@@ -1,38 +0,0 @@
1
- #!/usr/bin/env python3
2
- """Generate a JWT token for testing MCP HTTP transport."""
3
-
4
- import sys
5
- import os
6
-
7
- # Add backend to path
8
- sys.path.insert(0, "./backend")
9
-
10
- from backend.src.services.auth import AuthService
11
- from backend.src.services.config import get_config
12
-
13
-
14
- def generate_token(user_id="local-dev"):
15
- """Generate a JWT token for the specified user."""
16
- try:
17
- config = get_config()
18
- auth_service = AuthService(config=config)
19
-
20
- # Generate JWT token
21
- token = auth_service.create_jwt(user_id)
22
-
23
- print(f"βœ… Generated JWT token for user '{user_id}':")
24
- print(f"Bearer {token}")
25
- print(f"\nπŸ“‹ Copy this to your mcp.json:")
26
- print(f'"Authorization": "Bearer {token}"')
27
-
28
- return token
29
-
30
- except Exception as e:
31
- print(f"❌ Error generating token: {e}")
32
- print("πŸ’‘ Make sure JWT_SECRET_KEY is set in your environment")
33
- return None
34
-
35
-
36
- if __name__ == "__main__":
37
- user_id = sys.argv[1] if len(sys.argv) > 1 else "local-dev"
38
- generate_token(user_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inspect_mcp_tools.py DELETED
@@ -1,24 +0,0 @@
1
-
2
- from backend.src.mcp.server import mcp
3
- import inspect
4
-
5
- def inspect_fastmcp():
6
- print("MCP Object:", mcp)
7
- print("Dir MCP:", dir(mcp))
8
-
9
- # Try to find tools
10
- if hasattr(mcp, 'tools'):
11
- print("Tools attr:", mcp.tools)
12
-
13
- if hasattr(mcp, '_tools'):
14
- print("_tools attr:", mcp._tools)
15
-
16
- if hasattr(mcp, '_mcp_server'):
17
- print("_mcp_server:", mcp._mcp_server)
18
- print("Dir _mcp_server:", dir(mcp._mcp_server))
19
-
20
- if __name__ == "__main__":
21
- try:
22
- inspect_fastmcp()
23
- except Exception as e:
24
- print(f"Error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
inspect_mcp_types.py DELETED
@@ -1,9 +0,0 @@
1
-
2
- from mcp.types import CallToolResult
3
- import inspect
4
-
5
- def inspect_call_tool_result():
6
- print("Fields:", CallToolResult.model_fields.keys())
7
-
8
- if __name__ == "__main__":
9
- inspect_call_tool_result()
 
 
 
 
 
 
 
 
 
 
inspect_tool_manager.py DELETED
@@ -1,23 +0,0 @@
1
-
2
- from backend.src.mcp.server import mcp
3
- import inspect
4
-
5
- def inspect_tool_manager():
6
- tm = mcp._tool_manager
7
- print("Tool Manager:", tm)
8
- print("Dir TM:", dir(tm))
9
-
10
- if hasattr(tm, '_tools'):
11
- print("Tools dict keys:", tm._tools.keys())
12
- # Inspect one tool
13
- if 'read_note' in tm._tools:
14
- tool = tm._tools['read_note']
15
- print("Tool object:", tool)
16
- print("Dir Tool:", dir(tool))
17
- # Check if it has a description or attributes we can patch
18
-
19
- if __name__ == "__main__":
20
- try:
21
- inspect_tool_manager()
22
- except Exception as e:
23
- print(f"Error: {e}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
test_remote_mcp.py DELETED
@@ -1,54 +0,0 @@
1
-
2
- import requests
3
- import json
4
- import sys
5
-
6
- # Use the public HF Space URL
7
- BASE_URL = "https://bigwolfe-document-mcp.hf.space/mcp"
8
-
9
- def test_search_notes():
10
- print("--- Testing tools/call search_notes ---")
11
- payload = {
12
- "jsonrpc": "2.0",
13
- "method": "tools/call",
14
- "params": {
15
- "name": "search_notes",
16
- "arguments": {"query": "API"}
17
- },
18
- "id": 1
19
- }
20
- headers = {
21
- "Content-Type": "application/json",
22
- "Accept": "application/json, text/event-stream"
23
- }
24
-
25
- try:
26
- response = requests.post(BASE_URL, json=payload, headers=headers, timeout=10)
27
- print(f"Status: {response.status_code}")
28
- try:
29
- data = response.json()
30
- # print(json.dumps(data, indent=2))
31
-
32
- res = data.get("result", {})
33
- if "structuredContent" in res:
34
- print("βœ… structuredContent found in result")
35
- print("Keys:", res["structuredContent"].keys())
36
- else:
37
- print("❌ structuredContent NOT found in result")
38
- print(json.dumps(res, indent=2))
39
-
40
- if "_meta" in res:
41
- print("βœ… _meta found in result")
42
- else:
43
- print("❌ _meta NOT found in result")
44
-
45
- except json.JSONDecodeError:
46
- print("Response not JSON:", response.text)
47
-
48
- except Exception as e:
49
- print(f"Request failed: {e}")
50
-
51
- if __name__ == "__main__":
52
- # test_read_note()
53
- test_search_notes()
54
- # test_read_resource()