muzakkirhussain011 commited on
Commit
6e7d9eb
Β·
1 Parent(s): 4b2aa2f

Add application files

Browse files
Files changed (2) hide show
  1. MCP_HACKATHON_GUIDE.md +376 -0
  2. requirements.txt +1 -21
MCP_HACKATHON_GUIDE.md ADDED
@@ -0,0 +1,376 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # MCP Servers for Hugging Face Spaces - Hackathon Guide
2
+
3
+ ## What You Actually Need
4
+
5
+ This is a **Hugging Face Space** for an **MCP hackathon**. The MCP servers should:
6
+
7
+ 1. βœ… **Work with AI agents** (primary goal)
8
+ 2. βœ… **Be simple and deployable** on HF Spaces
9
+ 3. βœ… **Provide useful functionality** to AI
10
+ 4. ❌ **NOT be over-engineered** with enterprise features
11
+
12
+ ---
13
+
14
+ ## What's Currently Working
15
+
16
+ ### βœ… 4 MCP Servers (In-Memory Mode)
17
+
18
+ Your existing MCP servers are **already functional** and work great for HF Spaces:
19
+
20
+ 1. **Search Server** (port 9001) - Web search via Serper API
21
+ 2. **Email Server** (port 9002) - Email thread management
22
+ 3. **Calendar Server** (port 9003) - Meeting scheduling
23
+ 4. **Store Server** (port 9004) - Data persistence
24
+
25
+ **Location:** `mcp/servers/` and `mcp/in_memory_services.py`
26
+
27
+ ### βœ… In-Memory Mode (Perfect for HF Spaces)
28
+
29
+ The `USE_IN_MEMORY_MCP=true` setting (default) means:
30
+ - βœ… No separate server processes needed
31
+ - βœ… Everything runs in single Gradio app
32
+ - βœ… No port binding issues
33
+ - βœ… Works perfectly in HF Spaces sandbox
34
+
35
+ ---
36
+
37
+ ## What I Added (That You Can Use)
38
+
39
+ ### 1. SQLite Database (Optional Upgrade)
40
+
41
+ **If you want better data persistence:**
42
+
43
+ ```python
44
+ # Instead of JSON files, use SQLite
45
+ from mcp.database import init_database, DatabaseStoreService
46
+
47
+ # Initialize once
48
+ await init_database()
49
+
50
+ # Use in your code
51
+ store = DatabaseStoreService()
52
+ await store.save_prospect(prospect_data)
53
+ prospects = await store.list_prospects()
54
+ ```
55
+
56
+ **Benefits:**
57
+ - βœ… Faster queries (10-100x)
58
+ - βœ… Proper relationships
59
+ - βœ… No file corruption
60
+ - βœ… Still works in HF Spaces (SQLite is file-based)
61
+
62
+ **Config:**
63
+ ```bash
64
+ DATABASE_URL=sqlite+aiosqlite:///./data/cx_agent.db
65
+ ```
66
+
67
+ ### 2. Simple Authentication (Optional)
68
+
69
+ **If you want to protect your MCP endpoints:**
70
+
71
+ ```python
72
+ from mcp.auth import APIKeyManager
73
+
74
+ # Generate an API key
75
+ manager = APIKeyManager()
76
+ key, _ = manager.create_key("My App")
77
+ print(f"API Key: {key}")
78
+
79
+ # Validate requests
80
+ api_key = manager.validate_key(request_key)
81
+ if not api_key:
82
+ return {"error": "Unauthorized"}
83
+ ```
84
+
85
+ **Config:**
86
+ ```bash
87
+ MCP_API_KEY=mcp_your_key_here
88
+ ```
89
+
90
+ ---
91
+
92
+ ## What You Should IGNORE
93
+
94
+ ### ❌ Don't Use These (Over-engineered)
95
+
96
+ 1. **PostgreSQL** - You don't need it in HF Spaces
97
+ 2. **Redis** - Overkill for a hackathon
98
+ 3. **Celery** - Not needed
99
+ 4. **Prometheus/Grafana** - HF has monitoring
100
+ 5. **Alembic migrations** - Just use SQLite directly
101
+ 6. **Rate limiting** - Not needed for hackathon
102
+ 7. **RBAC/Audit logs** - Over-engineered
103
+
104
+ ### Just Use What You Have
105
+
106
+ Your **current in-memory MCP servers are perfect** for the hackathon!
107
+
108
+ ---
109
+
110
+ ## Recommended Setup for HF Spaces
111
+
112
+ ### Keep It Simple
113
+
114
+ ```python
115
+ # app.py (your existing Gradio app)
116
+ import os
117
+ os.environ["USE_IN_MEMORY_MCP"] = "true" # Use in-memory mode
118
+
119
+ from mcp.registry import get_mcp_registry
120
+ from app.orchestrator import Orchestrator
121
+
122
+ # Create MCP registry (in-memory mode)
123
+ registry = get_mcp_registry()
124
+
125
+ # Create orchestrator
126
+ orchestrator = Orchestrator(registry)
127
+
128
+ # Your Gradio interface
129
+ def run_pipeline(company_name, num_prospects):
130
+ async for event in orchestrator.run_pipeline(company_name, num_prospects):
131
+ yield event
132
+
133
+ # Gradio UI
134
+ import gradio as gr
135
+ demo = gr.Interface(fn=run_pipeline, ...)
136
+ demo.launch()
137
+ ```
138
+
139
+ ### Required Environment Variables
140
+
141
+ ```bash
142
+ # API Keys
143
+ HF_API_TOKEN=your_huggingface_token
144
+ SERPER_API_KEY=your_serper_key
145
+
146
+ # MCP Mode (in-memory)
147
+ USE_IN_MEMORY_MCP=true
148
+ ```
149
+
150
+ ---
151
+
152
+ ## How AI Agents Use Your MCP Servers
153
+
154
+ The AI agents call your MCP servers through the registry:
155
+
156
+ ```python
157
+ # In your agent code
158
+ class Enricher:
159
+ def __init__(self, mcp_registry):
160
+ self.search = mcp_registry.search # Search MCP
161
+ self.store = mcp_registry.store # Store MCP
162
+
163
+ async def run(self, prospect):
164
+ # Use MCP search
165
+ results = await self.search.query(f"{prospect.company_name} news")
166
+
167
+ # Store facts
168
+ for result in results:
169
+ await self.store.save_fact({
170
+ "id": f"fact_{uuid.uuid4()}",
171
+ "company_id": prospect.company_id,
172
+ "fact_type": "news",
173
+ "content": result["text"],
174
+ "source_url": result.get("url")
175
+ })
176
+ ```
177
+
178
+ ---
179
+
180
+ ## Quick Fixes for Your Build
181
+
182
+ ### 1. Use Simplified requirements.txt
183
+
184
+ ```txt
185
+ # Gradio Interface (REQUIRED)
186
+ gradio==5.5.0
187
+
188
+ # HTTP and Web
189
+ requests>=2.31.0
190
+ aiohttp>=3.9.1
191
+
192
+ # Web Scraping (REQUIRED)
193
+ beautifulsoup4>=4.12.0
194
+ lxml>=4.9.0
195
+
196
+ # Data handling
197
+ python-dotenv>=1.0.0
198
+ pandas>=2.1.4
199
+ email-validator>=2.1.0
200
+
201
+ # Vector Store and Embeddings
202
+ sentence-transformers>=2.3.1
203
+ faiss-cpu>=1.7.4
204
+ numpy>=1.24.3,<2.0.0
205
+
206
+ # Database (Optional - only if you want SQLite upgrade)
207
+ sqlalchemy>=2.0.0
208
+ aiosqlite>=0.19.0
209
+
210
+ # HuggingFace dependencies
211
+ huggingface-hub>=0.34.0,<1.0
212
+ ```
213
+
214
+ ### 2. Remove Enterprise Features
215
+
216
+ You can **delete** or **ignore** these files if you don't need them:
217
+
218
+ ```bash
219
+ # Optional - only if you want SQLite
220
+ mcp/database/models.py
221
+ mcp/database/engine.py
222
+ mcp/database/repositories.py
223
+ mcp/database/store_service.py
224
+
225
+ # Not needed for HF Spaces
226
+ mcp/auth/
227
+ mcp/observability/
228
+ alembic.ini
229
+ migrations/
230
+ ```
231
+
232
+ ### 3. Just Use What Works
233
+
234
+ Your existing code in:
235
+ - `mcp/in_memory_services.py` βœ… **Keep this!**
236
+ - `mcp/registry.py` βœ… **Keep this!**
237
+ - `mcp/servers/*.py` βœ… **Keep this!**
238
+
239
+ These are **perfect for HF Spaces** and work great with AI agents.
240
+
241
+ ---
242
+
243
+ ## What Makes Good MCP Servers for AI
244
+
245
+ Focus on making your MCP servers **useful for AI agents**:
246
+
247
+ ### βœ… Good MCP Features
248
+
249
+ 1. **Search** - Let AI find information
250
+ ```python
251
+ results = await mcp.search.query("company news")
252
+ ```
253
+
254
+ 2. **Store** - Let AI persist data
255
+ ```python
256
+ await mcp.store.save_prospect(prospect)
257
+ prospects = await mcp.store.list_prospects()
258
+ ```
259
+
260
+ 3. **Email** - Let AI track conversations
261
+ ```python
262
+ thread_id = await mcp.email.send(to, subject, body)
263
+ thread = await mcp.email.get_thread(prospect_id)
264
+ ```
265
+
266
+ 4. **Calendar** - Let AI schedule meetings
267
+ ```python
268
+ slots = await mcp.calendar.suggest_slots()
269
+ ics = await mcp.calendar.generate_ics(slot)
270
+ ```
271
+
272
+ ### ❌ Don't Overcomplicate
273
+
274
+ - ❌ Don't add authentication if it's just for demo
275
+ - ❌ Don't use PostgreSQL for a hackathon
276
+ - ❌ Don't add complex rate limiting
277
+ - ❌ Don't over-engineer with enterprise patterns
278
+
279
+ ---
280
+
281
+ ## Deployment to HF Spaces
282
+
283
+ ### Current Setup (Works Great!)
284
+
285
+ ```yaml
286
+ # Your space.yaml or config
287
+ title: CX AI Agent
288
+ emoji: πŸ€–
289
+ colorFrom: blue
290
+ colorTo: green
291
+ sdk: gradio
292
+ sdk_version: 5.5.0
293
+ app_file: app.py
294
+ pinned: false
295
+ ```
296
+
297
+ ### Environment Variables in HF Spaces
298
+
299
+ Go to Settings β†’ Variables:
300
+
301
+ ```bash
302
+ HF_API_TOKEN=your_token
303
+ SERPER_API_KEY=your_serper_key
304
+ USE_IN_MEMORY_MCP=true
305
+ ```
306
+
307
+ ---
308
+
309
+ ## Testing Your MCP Servers
310
+
311
+ ### Test In-Memory Mode
312
+
313
+ ```python
314
+ import asyncio
315
+ from mcp.registry import get_mcp_registry
316
+
317
+ async def test():
318
+ registry = get_mcp_registry()
319
+
320
+ # Test search
321
+ results = await registry.search.query("Shopify news")
322
+ print(f"Found {len(results)} results")
323
+
324
+ # Test store
325
+ await registry.store.save_prospect({
326
+ "id": "test_123",
327
+ "company_id": "shopify",
328
+ "status": "new"
329
+ })
330
+ prospects = await registry.store.list_prospects()
331
+ print(f"Stored {len(prospects)} prospects")
332
+
333
+ asyncio.run(test())
334
+ ```
335
+
336
+ ---
337
+
338
+ ## Summary
339
+
340
+ ### βœ… What to Keep
341
+
342
+ 1. **In-memory MCP servers** - Perfect for HF Spaces
343
+ 2. **Simple requirements.txt** - No over-engineered dependencies
344
+ 3. **Existing agent pipeline** - Works great with MCP
345
+
346
+ ### ❌ What to Remove/Ignore
347
+
348
+ 1. Enterprise database features (unless you want SQLite)
349
+ 2. Authentication (unless you need it)
350
+ 3. Observability/metrics (HF has this)
351
+ 4. Complex deployment configs
352
+
353
+ ### 🎯 Focus On
354
+
355
+ Making your MCP servers **useful for AI agents**:
356
+ - Good search results
357
+ - Reliable data storage
358
+ - Clear email tracking
359
+ - Simple calendar management
360
+
361
+ That's it! Keep it simple, keep it functional, and focus on the **AI agent capabilities**.
362
+
363
+ ---
364
+
365
+ ## Need Help?
366
+
367
+ If you have issues:
368
+
369
+ 1. **Check logs** in HF Spaces console
370
+ 2. **Test locally** first: `gradio app.py`
371
+ 3. **Use in-memory mode**: `USE_IN_MEMORY_MCP=true`
372
+ 4. **Keep requirements simple**: Only what you need
373
+
374
+ Your **current implementation is already good** for the hackathon! The enterprise upgrades are optional enhancements, not requirements.
375
+
376
+ Good luck with the hackathon! πŸš€
requirements.txt CHANGED
@@ -19,29 +19,9 @@ sentence-transformers>=2.3.1
19
  faiss-cpu>=1.7.4
20
  numpy>=1.24.3,<2.0.0
21
 
22
- # Enterprise database support
23
  sqlalchemy>=2.0.0
24
  aiosqlite>=0.19.0
25
- alembic>=1.13.0
26
- asyncpg>=0.29.0
27
-
28
- # Logging and Observability
29
- structlog>=24.1.0
30
- prometheus-client>=0.19.0
31
-
32
- # Security and Encryption
33
- cryptography>=42.0.0
34
- pyjwt>=2.8.0
35
-
36
- # Rate Limiting and Validation
37
- aiohttp-ratelimit>=0.7.0
38
- pydantic>=2.0.0
39
-
40
- # Caching (optional but recommended)
41
- redis>=5.0.0
42
-
43
- # Background Jobs (optional)
44
- celery>=5.3.0
45
 
46
  # HuggingFace dependencies
47
  huggingface-hub>=0.34.0,<1.0
 
19
  faiss-cpu>=1.7.4
20
  numpy>=1.24.3,<2.0.0
21
 
22
+ # Database support (SQLite for HF Spaces)
23
  sqlalchemy>=2.0.0
24
  aiosqlite>=0.19.0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  # HuggingFace dependencies
27
  huggingface-hub>=0.34.0,<1.0