ocx2025 commited on
Commit
0794bda
·
1 Parent(s): cfebee5
Files changed (8) hide show
  1. .dockerignore +36 -0
  2. DEPLOYMENT.md +175 -0
  3. DEPLOYMENT_SUMMARY.md +271 -0
  4. Dockerfile +32 -0
  5. README.md +59 -4
  6. app.py +84 -0
  7. pyproject.toml +3 -0
  8. uv.lock +20 -0
.dockerignore ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+ *.so
6
+ .Python
7
+ *.egg-info/
8
+ dist/
9
+ build/
10
+ .venv/
11
+ venv/
12
+ ENV/
13
+ .env
14
+ .env.local
15
+
16
+ # IDE
17
+ .vscode/
18
+ .idea/
19
+ *.swp
20
+ *.swo
21
+ *~
22
+
23
+ # OS
24
+ .DS_Store
25
+ Thumbs.db
26
+
27
+ # Git
28
+ .git/
29
+ .gitignore
30
+
31
+ # Documentation
32
+ README.md
33
+
34
+ # UV cache
35
+ .uv/
36
+
DEPLOYMENT.md ADDED
@@ -0,0 +1,175 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Deployment Guide for Hugging Face Spaces
2
+
3
+ ## Overview
4
+ This guide explains how to deploy the Basicsearch MCP server to Hugging Face Spaces using Docker.
5
+
6
+ ## Prerequisites
7
+ 1. A Hugging Face account
8
+ 2. A YouTube Data API v3 key from [Google Cloud Console](https://console.cloud.google.com/)
9
+
10
+ ## Deployment Steps
11
+
12
+ ### 1. Create a New Space
13
+ 1. Go to [Hugging Face Spaces](https://huggingface.co/spaces)
14
+ 2. Click "Create new Space"
15
+ 3. Choose a name for your space
16
+ 4. Select "Docker" as the SDK
17
+ 5. Click "Create Space"
18
+
19
+ ### 2. Upload Your Code
20
+ You can either:
21
+
22
+ **Option A: Use Git (Recommended)**
23
+ ```bash
24
+ # Clone your space
25
+ git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
26
+ cd YOUR_SPACE_NAME
27
+
28
+ # Copy files from this directory
29
+ cp /path/to/basicsearch/* .
30
+
31
+ # Commit and push
32
+ git add .
33
+ git commit -m "Initial deployment"
34
+ git push
35
+ ```
36
+
37
+ **Option B: Upload via Web Interface**
38
+ - Upload the following files:
39
+ - `Dockerfile`
40
+ - `app.py`
41
+ - `server.py`
42
+ - `pyproject.toml`
43
+ - `uv.lock`
44
+ - `README.md`
45
+
46
+ ### 3. Configure Environment Variables
47
+ 1. Go to your Space settings
48
+ 2. Navigate to "Repository secrets"
49
+ 3. Add a new secret:
50
+ - Name: `YOUTUBE_API_KEY`
51
+ - Value: Your YouTube API key
52
+
53
+ ### 4. Wait for Build
54
+ - Hugging Face will automatically detect the Dockerfile and build your container
55
+ - This may take a few minutes
56
+ - You can monitor the build logs in the "Settings" → "Logs" section
57
+
58
+ ## Testing Your Deployment
59
+
60
+ Once deployed, your Space will be available at:
61
+ ```
62
+ https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
63
+ ```
64
+
65
+ ### Available Endpoints
66
+
67
+ 1. **Health Check**
68
+ ```bash
69
+ curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/health
70
+ ```
71
+
72
+ 2. **Service Info**
73
+ ```bash
74
+ curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/
75
+ ```
76
+
77
+ 3. **List Tools**
78
+ ```bash
79
+ curl https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/tools
80
+ ```
81
+
82
+ 4. **Search YouTube Videos**
83
+ ```bash
84
+ curl -X POST https://YOUR_USERNAME-YOUR_SPACE_NAME.hf.space/search \
85
+ -H "Content-Type: application/json" \
86
+ -d '{"query": "Python tutorial", "max_results": 5}'
87
+ ```
88
+
89
+ ## Architecture
90
+
91
+ ### Components
92
+ 1. **server.py**: Core MCP server with YouTube search functionality
93
+ 2. **app.py**: FastAPI HTTP wrapper for web deployment
94
+ 3. **Dockerfile**: Container definition for deployment
95
+
96
+ ### Port Configuration
97
+ - The server runs on port 7860 (Hugging Face Spaces default)
98
+ - This is configured via the `PORT` environment variable
99
+
100
+ ## Troubleshooting
101
+
102
+ ### Build Fails
103
+ - Check the build logs in Settings → Logs
104
+ - Ensure all files are uploaded correctly
105
+ - Verify the Dockerfile syntax
106
+
107
+ ### API Key Issues
108
+ - Ensure `YOUTUBE_API_KEY` is set in Repository secrets
109
+ - The key must have YouTube Data API v3 enabled
110
+ - Check quota limits in Google Cloud Console
111
+
112
+ ### Connection Issues
113
+ - Spaces may take a few minutes to start after deployment
114
+ - Check if the Space is in "Running" state
115
+ - Review application logs for errors
116
+
117
+ ## Local Testing
118
+
119
+ Before deploying, test locally:
120
+
121
+ ```bash
122
+ # Build the Docker image
123
+ docker build -t basicsearch-mcp .
124
+
125
+ # Run the container
126
+ docker run -p 7860:7860 -e YOUTUBE_API_KEY=your_key_here basicsearch-mcp
127
+
128
+ # Test the endpoint
129
+ curl http://localhost:7860/health
130
+ ```
131
+
132
+ ## Monitoring
133
+
134
+ ### Health Checks
135
+ The Docker container includes automatic health checks that run every 30 seconds.
136
+
137
+ ### Logs
138
+ View logs in your Space's Settings → Logs section to monitor:
139
+ - API requests
140
+ - Error messages
141
+ - Performance metrics
142
+
143
+ ## Updating Your Deployment
144
+
145
+ To update your Space:
146
+ ```bash
147
+ # Make your changes locally
148
+ # Commit and push
149
+ git add .
150
+ git commit -m "Update description"
151
+ git push
152
+ ```
153
+
154
+ Hugging Face will automatically rebuild and redeploy your Space.
155
+
156
+ ## Cost Considerations
157
+
158
+ - Hugging Face Spaces offers free tier for public spaces
159
+ - YouTube Data API has daily quota limits (10,000 units/day by default)
160
+ - Each search request costs approximately 100 units
161
+
162
+ ## Security Best Practices
163
+
164
+ 1. **Never commit API keys** to your repository
165
+ 2. Use Hugging Face Repository secrets for sensitive data
166
+ 3. Consider implementing rate limiting in production
167
+ 4. Monitor API usage in Google Cloud Console
168
+
169
+ ## Additional Resources
170
+
171
+ - [Hugging Face Spaces Documentation](https://huggingface.co/docs/hub/spaces)
172
+ - [Docker Documentation](https://docs.docker.com/)
173
+ - [YouTube Data API Documentation](https://developers.google.com/youtube/v3)
174
+ - [FastMCP Documentation](https://github.com/jlowin/fastmcp)
175
+
DEPLOYMENT_SUMMARY.md ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Deployment Summary
2
+
3
+ ## What Was Created
4
+
5
+ Your MCP server is now ready for deployment to Hugging Face Spaces! Here's what was set up:
6
+
7
+ ### Core Files
8
+
9
+ 1. **Dockerfile**
10
+ - Multi-stage build using Python 3.13 slim
11
+ - Uses `uv` for fast dependency management
12
+ - Includes health checks
13
+ - Configured for Hugging Face Spaces (port 7860)
14
+
15
+ 2. **app.py** (NEW)
16
+ - FastAPI HTTP wrapper for the MCP server
17
+ - Provides REST endpoints for web access
18
+ - Endpoints:
19
+ - `GET /` - Service information
20
+ - `GET /health` - Health check
21
+ - `GET /tools` - List available MCP tools
22
+ - `POST /search` - Direct YouTube search endpoint
23
+
24
+ 3. **.dockerignore**
25
+ - Optimizes Docker build by excluding unnecessary files
26
+ - Excludes Python cache, virtual environments, and .env files
27
+
28
+ 4. **pyproject.toml** (UPDATED)
29
+ - Added FastAPI for HTTP server
30
+ - Added uvicorn for ASGI server
31
+ - Added requests for health checks
32
+ - All dependencies properly versioned
33
+
34
+ ### Documentation
35
+
36
+ 1. **README.md** (UPDATED)
37
+ - Updated with Docker SDK configuration
38
+ - Added local development instructions for both MCP and HTTP modes
39
+ - Added environment variable documentation
40
+ - Added deployment instructions
41
+
42
+ 2. **DEPLOYMENT.md** (NEW)
43
+ - Comprehensive deployment guide for Hugging Face Spaces
44
+ - Step-by-step instructions
45
+ - Testing examples with curl commands
46
+ - Troubleshooting section
47
+ - Security best practices
48
+
49
+ ## Quick Start
50
+
51
+ ### Local Testing (HTTP Mode)
52
+
53
+ ```bash
54
+ # 1. Install dependencies
55
+ cd /Users/marjorie/Documents/GitHub/xctopus/mcp2/basicsearch
56
+ uv sync
57
+
58
+ # 2. Create .env file
59
+ echo "YOUTUBE_API_KEY=your_key_here" > .env
60
+
61
+ # 3. Run the HTTP server
62
+ uv run python app.py
63
+
64
+ # 4. Test in another terminal
65
+ curl http://localhost:7860/health
66
+ curl -X POST http://localhost:7860/search \
67
+ -H "Content-Type: application/json" \
68
+ -d '{"query": "Python programming", "max_results": 3}'
69
+ ```
70
+
71
+ ### Docker Testing (Recommended before deployment)
72
+
73
+ ```bash
74
+ # 1. Build the image
75
+ cd /Users/marjorie/Documents/GitHub/xctopus/mcp2/basicsearch
76
+ docker build -t basicsearch-mcp .
77
+
78
+ # 2. Run the container
79
+ docker run -p 7860:7860 \
80
+ -e YOUTUBE_API_KEY=your_key_here \
81
+ basicsearch-mcp
82
+
83
+ # 3. Test
84
+ curl http://localhost:7860/health
85
+ ```
86
+
87
+ ### Deploy to Hugging Face Spaces
88
+
89
+ ```bash
90
+ # 1. Create a new Space on Hugging Face (select Docker SDK)
91
+
92
+ # 2. Clone your space
93
+ git clone https://huggingface.co/spaces/YOUR_USERNAME/YOUR_SPACE_NAME
94
+ cd YOUR_SPACE_NAME
95
+
96
+ # 3. Copy files
97
+ cp /Users/marjorie/Documents/GitHub/xctopus/mcp2/basicsearch/Dockerfile .
98
+ cp /Users/marjorie/Documents/GitHub/xctopus/mcp2/basicsearch/app.py .
99
+ cp /Users/marjorie/Documents/GitHub/xctopus/mcp2/basicsearch/server.py .
100
+ cp /Users/marjorie/Documents/GitHub/xctopus/mcp2/basicsearch/pyproject.toml .
101
+ cp /Users/marjorie/Documents/GitHub/xctopus/mcp2/basicsearch/uv.lock .
102
+ cp /Users/marjorie/Documents/GitHub/xctopus/mcp2/basicsearch/README.md .
103
+ cp /Users/marjorie/Documents/GitHub/xctopus/mcp2/basicsearch/.dockerignore .
104
+
105
+ # 4. Commit and push
106
+ git add .
107
+ git commit -m "Initial deployment"
108
+ git push
109
+
110
+ # 5. Set YOUTUBE_API_KEY in Space settings (Repository secrets)
111
+ ```
112
+
113
+ ## Architecture Overview
114
+
115
+ ```
116
+ ┌─────────────────────────────────────────┐
117
+ │ Hugging Face Space │
118
+ │ ┌───────────────────────────────────┐ │
119
+ │ │ Docker Container │ │
120
+ │ │ ┌─────────────────────────────┐ │ │
121
+ │ │ │ app.py (FastAPI) │ │ │
122
+ │ │ │ Port: 7860 │ │ │
123
+ │ │ │ │ │ │
124
+ │ │ │ ┌───────────────────────┐ │ │ │
125
+ │ │ │ │ server.py (MCP) │ │ │ │
126
+ │ │ │ │ - search_youtube_ │ │ │ │
127
+ │ │ │ │ videos tool │ │ │ │
128
+ │ │ │ └───────────────────────┘ │ │ │
129
+ │ │ └─────────────────────────────┘ │ │
130
+ │ └───────────────────────────────────┘ │
131
+ └─────────────────────────────────────────┘
132
+
133
+ YouTube API v3
134
+ ```
135
+
136
+ ## File Structure
137
+
138
+ ```
139
+ basicsearch/
140
+ ├── Dockerfile # Container definition
141
+ ├── .dockerignore # Build optimization
142
+ ├── app.py # HTTP wrapper (FastAPI)
143
+ ├── server.py # MCP server (FastMCP)
144
+ ├── pyproject.toml # Dependencies
145
+ ├── uv.lock # Locked dependencies
146
+ ├── README.md # Main documentation
147
+ ├── DEPLOYMENT.md # Deployment guide
148
+ └── DEPLOYMENT_SUMMARY.md # This file
149
+ ```
150
+
151
+ ## Environment Variables
152
+
153
+ | Variable | Required | Description | Where to Set |
154
+ |----------|----------|-------------|--------------|
155
+ | `YOUTUBE_API_KEY` | Yes | YouTube Data API v3 key | HF Space secrets or .env locally |
156
+ | `PORT` | No | HTTP port (default: 7860) | Auto-set by HF Spaces |
157
+
158
+ ## API Endpoints
159
+
160
+ ### GET /
161
+ Returns service information and available tools.
162
+
163
+ **Response:**
164
+ ```json
165
+ {
166
+ "status": "healthy",
167
+ "service": "basicsearch-mcp-server",
168
+ "tools": ["search_youtube_videos"]
169
+ }
170
+ ```
171
+
172
+ ### GET /health
173
+ Health check endpoint.
174
+
175
+ **Response:**
176
+ ```json
177
+ {
178
+ "status": "ok"
179
+ }
180
+ ```
181
+
182
+ ### GET /tools
183
+ Lists all available MCP tools.
184
+
185
+ **Response:**
186
+ ```json
187
+ {
188
+ "tools": [
189
+ {
190
+ "name": "search_youtube_videos",
191
+ "description": "Searches YouTube for videos based on a query.",
192
+ "parameters": {
193
+ "query": "string (required)",
194
+ "max_results": "integer (optional, default: 5)"
195
+ }
196
+ }
197
+ ]
198
+ }
199
+ ```
200
+
201
+ ### POST /search
202
+ Search YouTube videos directly.
203
+
204
+ **Request:**
205
+ ```json
206
+ {
207
+ "query": "Python tutorial",
208
+ "max_results": 5
209
+ }
210
+ ```
211
+
212
+ **Response:**
213
+ ```json
214
+ {
215
+ "results": [
216
+ {
217
+ "title": "Video Title",
218
+ "video_id": "abc123",
219
+ "description": "Video description..."
220
+ }
221
+ ]
222
+ }
223
+ ```
224
+
225
+ ## Next Steps
226
+
227
+ 1. ✅ Dependencies installed and synced
228
+ 2. ✅ Docker configuration ready
229
+ 3. ✅ HTTP wrapper created
230
+ 4. ✅ Documentation complete
231
+
232
+ **TODO:**
233
+ - [ ] Test locally with `uv run python app.py`
234
+ - [ ] Test Docker build with `docker build -t basicsearch-mcp .`
235
+ - [ ] Get YouTube API key from Google Cloud Console
236
+ - [ ] Create Hugging Face Space
237
+ - [ ] Deploy to Hugging Face
238
+ - [ ] Set YOUTUBE_API_KEY in Space secrets
239
+ - [ ] Test deployed endpoints
240
+
241
+ ## Troubleshooting
242
+
243
+ ### Common Issues
244
+
245
+ 1. **ModuleNotFoundError: No module named 'googleapiclient'**
246
+ - Run `uv sync` to install dependencies
247
+ - Use `uv run python app.py` instead of `python app.py`
248
+
249
+ 2. **YouTube API Key not found**
250
+ - Create a `.env` file locally with `YOUTUBE_API_KEY=your_key`
251
+ - On HF Spaces, set it in Repository secrets
252
+
253
+ 3. **Docker build fails**
254
+ - Ensure all files are present (check list above)
255
+ - Verify `.dockerignore` is in place
256
+ - Check Docker logs for specific errors
257
+
258
+ ## Resources
259
+
260
+ - [Hugging Face Spaces Documentation](https://huggingface.co/docs/hub/spaces)
261
+ - [Get YouTube API Key](https://console.cloud.google.com/)
262
+ - [FastMCP Documentation](https://github.com/jlowin/fastmcp)
263
+ - [Docker Documentation](https://docs.docker.com/)
264
+
265
+ ## Support
266
+
267
+ For issues or questions:
268
+ 1. Check `DEPLOYMENT.md` for detailed troubleshooting
269
+ 2. Review Docker logs: `docker logs <container_id>`
270
+ 3. Check HF Space logs in Settings → Logs
271
+
Dockerfile ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Use Python 3.13 slim image as base
2
+ FROM python:3.13-slim
3
+
4
+ # Set working directory
5
+ WORKDIR /app
6
+
7
+ # Install uv for fast dependency management
8
+ COPY --from=ghcr.io/astral-sh/uv:latest /uv /usr/local/bin/uv
9
+
10
+ # Set environment variables
11
+ ENV PYTHONUNBUFFERED=1 \
12
+ PYTHONDONTWRITEBYTECODE=1 \
13
+ UV_SYSTEM_PYTHON=1 \
14
+ PORT=7860
15
+
16
+ # Copy project files
17
+ COPY pyproject.toml uv.lock* ./
18
+ COPY server.py app.py ./
19
+
20
+ # Install dependencies using uv
21
+ RUN uv pip install --system -r pyproject.toml
22
+
23
+ # Expose port for HTTP server
24
+ EXPOSE 7860
25
+
26
+ # Health check
27
+ HEALTHCHECK --interval=30s --timeout=10s --start-period=5s --retries=3 \
28
+ CMD python -c "import requests; requests.get('http://localhost:7860/health')" || exit 1
29
+
30
+ # Run the FastAPI app
31
+ CMD ["python", "app.py"]
32
+
README.md CHANGED
@@ -3,11 +3,66 @@ title: Basicsearch
3
  emoji: 🦀
4
  colorFrom: purple
5
  colorTo: indigo
6
- sdk: gradio
7
- sdk_version: 5.49.1
8
- app_file: app.py
9
  pinned: false
10
- short_description: Obtaining information to feed the model
11
  ---
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
3
  emoji: 🦀
4
  colorFrom: purple
5
  colorTo: indigo
6
+ sdk: docker
7
+ app_port: 7860
 
8
  pinned: false
9
+ short_description: MCP server for YouTube video search
10
  ---
11
 
12
+ # Basicsearch MCP Server
13
+
14
+ This is an MCP (Model Context Protocol) server that provides YouTube video search functionality.
15
+
16
+ ## Features
17
+
18
+ - Search YouTube videos using the YouTube Data API v3
19
+ - Returns video titles, IDs, and descriptions
20
+
21
+ ## Configuration
22
+
23
+ ### Environment Variables
24
+ - `YOUTUBE_API_KEY`: Your YouTube Data API v3 key (required)
25
+ - `PORT`: HTTP server port (optional, default: 7860)
26
+
27
+ ### Local Setup
28
+ Create a `.env` file in the project root:
29
+ ```bash
30
+ YOUTUBE_API_KEY=your_youtube_api_key_here
31
+ ```
32
+
33
+ ### Hugging Face Spaces
34
+ Set the `YOUTUBE_API_KEY` in your Space's Repository secrets (Settings → Repository secrets)
35
+
36
+ ## Local Development
37
+
38
+ ### MCP Server (STDIO)
39
+ ```bash
40
+ # Install dependencies
41
+ uv sync
42
+
43
+ # Run the server in development mode
44
+ uv run mcp dev server.py
45
+ ```
46
+
47
+ ### HTTP Server (for testing Hugging Face deployment)
48
+ ```bash
49
+ # Install dependencies
50
+ uv sync
51
+
52
+ # Run the HTTP wrapper
53
+ uv run python app.py
54
+ ```
55
+
56
+ Then visit `http://localhost:7860` for the health check or use the following endpoints:
57
+ - `GET /` - Service info
58
+ - `GET /health` - Health check
59
+ - `GET /tools` - List available tools
60
+ - `POST /search` - Search YouTube videos (JSON body: `{"query": "your search", "max_results": 5}`)
61
+
62
+ ## Deployment to Hugging Face Spaces
63
+
64
+ 1. Push this repository to Hugging Face Spaces
65
+ 2. Set the `YOUTUBE_API_KEY` environment variable in your Space settings
66
+ 3. The Dockerfile will automatically be used to build and deploy the server
67
+
68
  Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ HTTP wrapper for MCP server deployment on Hugging Face Spaces.
3
+ """
4
+ from fastapi import FastAPI, Request
5
+ from fastapi.responses import JSONResponse, StreamingResponse
6
+ import uvicorn
7
+ import os
8
+ from dotenv import load_dotenv
9
+ from server import mcp
10
+
11
+ # Load environment variables from .env file
12
+ load_dotenv()
13
+
14
+ # Create FastAPI app
15
+ app = FastAPI(
16
+ title="Basicsearch MCP Server",
17
+ description="YouTube video search MCP server"
18
+ )
19
+
20
+ @app.get("/")
21
+ async def root():
22
+ """Health check endpoint"""
23
+ return {
24
+ "status": "healthy",
25
+ "service": "basicsearch-mcp-server",
26
+ "tools": ["search_youtube_videos"]
27
+ }
28
+
29
+ @app.get("/health")
30
+ async def health():
31
+ """Health check endpoint"""
32
+ return {"status": "ok"}
33
+
34
+ @app.post("/sse")
35
+ async def sse_endpoint(request: Request):
36
+ """SSE endpoint for MCP protocol"""
37
+ # This endpoint would handle SSE connections for MCP
38
+ # For now, return a basic response
39
+ return {"message": "SSE endpoint for MCP protocol"}
40
+
41
+ @app.get("/tools")
42
+ async def list_tools():
43
+ """List available tools"""
44
+ return {
45
+ "tools": [
46
+ {
47
+ "name": "search_youtube_videos",
48
+ "description": "Searches YouTube for videos based on a query.",
49
+ "parameters": {
50
+ "query": "string (required)",
51
+ "max_results": "integer (optional, default: 5)"
52
+ }
53
+ }
54
+ ]
55
+ }
56
+
57
+ @app.post("/search")
58
+ async def search_youtube(request: Request):
59
+ """Direct HTTP endpoint for YouTube search"""
60
+ from server import search_youtube_videos
61
+
62
+ data = await request.json()
63
+ query = data.get("query")
64
+ max_results = data.get("max_results", 5)
65
+
66
+ if not query:
67
+ return JSONResponse(
68
+ status_code=400,
69
+ content={"error": "Query parameter is required"}
70
+ )
71
+
72
+ try:
73
+ results = search_youtube_videos(query, max_results)
74
+ return {"results": results}
75
+ except Exception as e:
76
+ return JSONResponse(
77
+ status_code=500,
78
+ content={"error": str(e)}
79
+ )
80
+
81
+ if __name__ == "__main__":
82
+ port = int(os.environ.get("PORT", 7860))
83
+ uvicorn.run(app, host="0.0.0.0", port=port)
84
+
pyproject.toml CHANGED
@@ -5,8 +5,11 @@ description = "Add your description here"
5
  readme = "README.md"
6
  requires-python = ">=3.13"
7
  dependencies = [
 
8
  "fastmcp>=2.12.4",
9
  "google-api-python-client>=2.184.0",
10
  "mcp[cli]>=1.16.0",
11
  "python-dotenv>=1.1.1",
 
 
12
  ]
 
5
  readme = "README.md"
6
  requires-python = ">=3.13"
7
  dependencies = [
8
+ "fastapi>=0.115.0",
9
  "fastmcp>=2.12.4",
10
  "google-api-python-client>=2.184.0",
11
  "mcp[cli]>=1.16.0",
12
  "python-dotenv>=1.1.1",
13
+ "requests>=2.32.0",
14
+ "uvicorn>=0.32.0",
15
  ]
uv.lock CHANGED
@@ -280,6 +280,20 @@ wheels = [
280
  { url = "https://files.pythonhosted.org/packages/36/f4/c6e662dade71f56cd2f3735141b265c3c79293c109549c1e6933b0651ffc/exceptiongroup-1.3.0-py3-none-any.whl", hash = "sha256:4d111e6e0c13d0644cad6ddaa7ed0261a0b36971f6d23e7ec9b4b9097da78a10", size = 16674, upload-time = "2025-05-10T17:42:49.33Z" },
281
  ]
282
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
283
  [[package]]
284
  name = "fastmcp"
285
  version = "2.12.4"
@@ -614,18 +628,24 @@ name = "mcp-xctopus"
614
  version = "0.1.0"
615
  source = { virtual = "." }
616
  dependencies = [
 
617
  { name = "fastmcp" },
618
  { name = "google-api-python-client" },
619
  { name = "mcp", extra = ["cli"] },
620
  { name = "python-dotenv" },
 
 
621
  ]
622
 
623
  [package.metadata]
624
  requires-dist = [
 
625
  { name = "fastmcp", specifier = ">=2.12.4" },
626
  { name = "google-api-python-client", specifier = ">=2.184.0" },
627
  { name = "mcp", extras = ["cli"], specifier = ">=1.16.0" },
628
  { name = "python-dotenv", specifier = ">=1.1.1" },
 
 
629
  ]
630
 
631
  [[package]]
 
280
  { url = "https://files.pythonhosted.org/packages/36/f4/c6e662dade71f56cd2f3735141b265c3c79293c109549c1e6933b0651ffc/exceptiongroup-1.3.0-py3-none-any.whl", hash = "sha256:4d111e6e0c13d0644cad6ddaa7ed0261a0b36971f6d23e7ec9b4b9097da78a10", size = 16674, upload-time = "2025-05-10T17:42:49.33Z" },
281
  ]
282
 
283
+ [[package]]
284
+ name = "fastapi"
285
+ version = "0.118.3"
286
+ source = { registry = "https://pypi.org/simple" }
287
+ dependencies = [
288
+ { name = "pydantic" },
289
+ { name = "starlette" },
290
+ { name = "typing-extensions" },
291
+ ]
292
+ sdist = { url = "https://files.pythonhosted.org/packages/44/e0/b2c4c5fed29587f0c0c56cec9b59f2c3ca58fd40e6c96d9a788219662a35/fastapi-0.118.3.tar.gz", hash = "sha256:5bf36d9bb0cd999e1aefcad74985a6d6a1fc3a35423d497f9e1317734633411d", size = 312055, upload-time = "2025-10-10T10:40:18.15Z" }
293
+ wheels = [
294
+ { url = "https://files.pythonhosted.org/packages/24/04/2f9e8a965f4214883258a6f716fea324d1b81e97bce6346cfbafffe6b86c/fastapi-0.118.3-py3-none-any.whl", hash = "sha256:8b9673dc083b4b9d3d295d49ba1c0a2abbfb293d34ba210fd9b0a90d5f39981e", size = 97957, upload-time = "2025-10-10T10:40:16.118Z" },
295
+ ]
296
+
297
  [[package]]
298
  name = "fastmcp"
299
  version = "2.12.4"
 
628
  version = "0.1.0"
629
  source = { virtual = "." }
630
  dependencies = [
631
+ { name = "fastapi" },
632
  { name = "fastmcp" },
633
  { name = "google-api-python-client" },
634
  { name = "mcp", extra = ["cli"] },
635
  { name = "python-dotenv" },
636
+ { name = "requests" },
637
+ { name = "uvicorn" },
638
  ]
639
 
640
  [package.metadata]
641
  requires-dist = [
642
+ { name = "fastapi", specifier = ">=0.115.0" },
643
  { name = "fastmcp", specifier = ">=2.12.4" },
644
  { name = "google-api-python-client", specifier = ">=2.184.0" },
645
  { name = "mcp", extras = ["cli"], specifier = ">=1.16.0" },
646
  { name = "python-dotenv", specifier = ">=1.1.1" },
647
+ { name = "requests", specifier = ">=2.32.0" },
648
+ { name = "uvicorn", specifier = ">=0.32.0" },
649
  ]
650
 
651
  [[package]]