File size: 8,095 Bytes
bd180df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# Testing Guide for Deployed Space

## Quick Status Check

Your Space is deployed at: **https://huggingface.co/spaces/ocx2025/basicsearch**

### Check Build Status

1. Visit https://huggingface.co/spaces/ocx2025/basicsearch
2. Look for the build status indicator at the top
3. If building, you'll see "Building..." with logs
4. If running, you'll see "Running" status

### View Build Logs

1. Go to https://huggingface.co/spaces/ocx2025/basicsearch/logs
2. Check for any errors during Docker build
3. Common issues:
   - Missing dependencies
   - Python version mismatch
   - Docker build timeout

## Testing Methods

### Method 1: Automated Test Scripts (Recommended)

#### Using Python Script
```bash
cd /Users/marjorie/Documents/GitHub/xctopus/mcp2/basicsearch

# Run all tests
python test_deployment.py

# Or test a custom URL
python test_deployment.py https://your-space-url.hf.space
```

#### Using Bash Script
```bash
cd /Users/marjorie/Documents/GitHub/xctopus/mcp2/basicsearch

# Run all tests
./test_deployment.sh

# Or test a custom URL
./test_deployment.sh https://your-space-url.hf.space
```

The scripts will test:
- βœ… Health check endpoint
- βœ… Service info endpoint
- βœ… Tools listing
- βœ… YouTube search functionality
- βœ… Error handling

### Method 2: Manual cURL Commands

#### 1. Health Check
```bash
curl https://ocx2025-basicsearch.hf.space/health
```

**Expected Response:**
```json
{"status": "ok"}
```

#### 2. Service Information
```bash
curl https://ocx2025-basicsearch.hf.space/
```

**Expected Response:**
```json
{
  "status": "healthy",
  "service": "basicsearch-mcp-server",
  "tools": ["search_youtube_videos"]
}
```

#### 3. List Available Tools
```bash
curl https://ocx2025-basicsearch.hf.space/tools
```

**Expected Response:**
```json
{
  "tools": [
    {
      "name": "search_youtube_videos",
      "description": "Searches YouTube for videos based on a query.",
      "parameters": {
        "query": "string (required)",
        "max_results": "integer (optional, default: 5)"
      }
    }
  ]
}
```

#### 4. Search YouTube Videos
```bash
curl -X POST https://ocx2025-basicsearch.hf.space/search \
  -H "Content-Type: application/json" \
  -d '{
    "query": "Python programming tutorial",
    "max_results": 3
  }'
```

**Expected Response (if API key is set):**
```json
{
  "results": [
    {
      "title": "Python Tutorial for Beginners",
      "video_id": "abc123xyz",
      "description": "Learn Python programming..."
    },
    ...
  ]
}
```

**Expected Error (if API key NOT set):**
```json
{
  "error": "YOUTUBE_API_KEY environment variable is not set"
}
```

### Method 3: Using Python `requests` Library

```python
import requests
import json

BASE_URL = "https://ocx2025-basicsearch.hf.space"

# Test health
response = requests.get(f"{BASE_URL}/health")
print(f"Health: {response.json()}")

# Test search
payload = {"query": "Python", "max_results": 2}
response = requests.post(f"{BASE_URL}/search", json=payload)
print(f"Search Results: {json.dumps(response.json(), indent=2)}")
```

### Method 4: Using Browser

Simply visit these URLs in your browser:

1. **Health Check:** https://ocx2025-basicsearch.hf.space/health
2. **Service Info:** https://ocx2025-basicsearch.hf.space/
3. **Tools List:** https://ocx2025-basicsearch.hf.space/tools

For POST requests, use a browser extension like:
- [Postman](https://www.postman.com/)
- [Thunder Client](https://www.thunderclient.com/) (VS Code extension)
- [REST Client](https://marketplace.visualstudio.com/items?itemName=humao.rest-client) (VS Code extension)

## Troubleshooting

### Space Returns 404
**Cause:** Space is still building or failed to start
**Solution:**
1. Check build logs at https://huggingface.co/spaces/ocx2025/basicsearch/logs
2. Wait for build to complete (can take 5-10 minutes)
3. Look for error messages in logs

### API Key Error
**Cause:** `YOUTUBE_API_KEY` not set or invalid
**Solution:**
1. Go to https://huggingface.co/spaces/ocx2025/basicsearch/settings
2. Click "Repository secrets"
3. Add secret: Name=`YOUTUBE_API_KEY`, Value=`your_actual_key`
4. Restart the Space

### Build Timeout
**Cause:** Docker build taking too long
**Solution:**
1. Check Dockerfile for optimization opportunities
2. Verify all dependencies are necessary
3. Consider using a lighter base image

### Connection Timeout
**Cause:** Space is sleeping (free tier) or overloaded
**Solution:**
1. Visit the Space page to wake it up
2. Wait a few seconds and retry
3. Check Space status

### Rate Limiting
**Cause:** Too many requests to YouTube API
**Solution:**
1. Check your Google Cloud Console quota
2. Default is 10,000 units/day
3. Each search costs ~100 units

## Monitoring

### Real-time Logs
```bash
# Using curl to monitor health
watch -n 5 'curl -s https://ocx2025-basicsearch.hf.space/health'
```

### Check Space Status
```bash
# Simple status check
curl -s -o /dev/null -w "HTTP Status: %{http_code}\n" \
  https://ocx2025-basicsearch.hf.space/health
```

### Continuous Testing
```bash
# Run tests every minute
while true; do
  echo "Testing at $(date)"
  python test_deployment.py
  sleep 60
done
```

## Performance Testing

### Load Test with Apache Bench
```bash
# Test 100 requests with 10 concurrent connections
ab -n 100 -c 10 https://ocx2025-basicsearch.hf.space/health
```

### Load Test with Python
```python
import time
import requests
from concurrent.futures import ThreadPoolExecutor

def test_endpoint():
    start = time.time()
    response = requests.get("https://ocx2025-basicsearch.hf.space/health")
    end = time.time()
    return response.status_code, end - start

# Run 50 concurrent requests
with ThreadPoolExecutor(max_workers=10) as executor:
    results = list(executor.map(lambda _: test_endpoint(), range(50)))

successful = sum(1 for status, _ in results if status == 200)
avg_time = sum(t for _, t in results) / len(results)

print(f"Successful: {successful}/50")
print(f"Average response time: {avg_time:.3f}s")
```

## Expected Response Times

| Endpoint | Expected Time |
|----------|--------------|
| `/health` | < 100ms |
| `/` | < 100ms |
| `/tools` | < 100ms |
| `/search` | 500ms - 2s (depends on YouTube API) |

## Security Testing

### Test Invalid Input
```bash
# Test with missing query
curl -X POST https://ocx2025-basicsearch.hf.space/search \
  -H "Content-Type: application/json" \
  -d '{}'

# Test with invalid JSON
curl -X POST https://ocx2025-basicsearch.hf.space/search \
  -H "Content-Type: application/json" \
  -d 'invalid json'

# Test with excessive max_results
curl -X POST https://ocx2025-basicsearch.hf.space/search \
  -H "Content-Type: application/json" \
  -d '{"query": "test", "max_results": 1000}'
```

## Integration Testing

### Test in Claude Desktop

If using with Claude Desktop, add to your MCP settings:

```json
{
  "mcpServers": {
    "basicsearch": {
      "url": "https://ocx2025-basicsearch.hf.space"
    }
  }
}
```

### Test with Python SDK

```python
from mcp import ClientSession
from mcp.client.stdio import stdio_client

# Connect to your MCP server
async with stdio_client() as (read, write):
    async with ClientSession(read, write) as session:
        # Initialize
        await session.initialize()
        
        # Call search tool
        result = await session.call_tool(
            "search_youtube_videos",
            arguments={"query": "Python", "max_results": 3}
        )
        print(result)
```

## Next Steps

1. βœ… Run automated test script: `python test_deployment.py`
2. βœ… Check build logs if tests fail
3. βœ… Set YOUTUBE_API_KEY if not already set
4. βœ… Monitor Space status
5. βœ… Test all endpoints manually
6. βœ… Perform load testing if needed
7. βœ… Integrate with your applications

## Useful Links

- **Your Space:** https://huggingface.co/spaces/ocx2025/basicsearch
- **Logs:** https://huggingface.co/spaces/ocx2025/basicsearch/logs
- **Settings:** https://huggingface.co/spaces/ocx2025/basicsearch/settings
- **HF Spaces Docs:** https://huggingface.co/docs/hub/spaces
- **YouTube API Console:** https://console.cloud.google.com/apis/dashboard