AdarshRajDS commited on
Commit
4830fdf
·
1 Parent(s): cf30ded

fix: add HF Spaces README configuration

Browse files
Files changed (1) hide show
  1. README.md +21 -369
README.md CHANGED
@@ -1,380 +1,32 @@
1
- # 🎙️ MCP Voice Agent
2
-
3
- > **Production-grade, fully free** MCP-powered agentic voice assistant.
4
- > Built with **uv**, **LangChain**, **Groq** (free LLM + STT), **Edge-TTS** (free TTS),
5
- > **ChromaDB** (free RAG), and hosted on **Hugging Face Spaces** (free cloud).
6
-
7
- [![CI](https://github.com/YOUR-USERNAME/mcp-voice-agent/actions/workflows/ci.yml/badge.svg)](https://github.com/YOUR-USERNAME/mcp-voice-agent/actions)
8
- [![Python 3.11+](https://img.shields.io/badge/python-3.11+-blue.svg)](https://www.python.org/)
9
- [![uv](https://img.shields.io/badge/managed%20by-uv-7c3aed.svg)](https://github.com/astral-sh/uv)
10
- [![LangChain](https://img.shields.io/badge/LangChain-0.3-1c3c3c.svg)](https://langchain.com)
11
- [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
12
-
13
- ---
14
-
15
- ## 📖 Overview
16
-
17
- This project reimplements the [OpenAI MCP-Powered Voice Agents Cookbook](https://developers.openai.com/cookbook/examples/partners/mcp_powered_voice_agents/mcp_powered_agents_cookbook.ipynb) using **entirely free components** — no OpenAI API key required.
18
-
19
- ### Architecture
20
-
21
- ```
22
- ┌─────────────────────────────────────────────────────────────────┐
23
- │ User's Machine │
24
- │ │
25
- │ 🎤 Microphone │
26
- │ │ │
27
- │ ▼ │
28
- │ ┌─────────────┐ ┌──────────────────────────────────────┐ │
29
- │ │ AudioRecorder│────▶│ Groq Whisper STT (free) │ │
30
- │ └─────────────┘ └──────────────┬───────────────────────┘ │
31
- │ │ transcribed text │
32
- │ ▼ │
33
- │ ┌────────────────────────┐ │
34
- │ │ LangChain ReAct Agent │ │
35
- │ │ (Groq llama-3.3-70b) │ │
36
- │ └────────────┬───────────┘ │
37
- │ │ tool calls │
38
- │ ┌─────────────────┼──────────────────┐ │
39
- │ ▼ ▼ ▼ │
40
- │ ┌────────────┐ ┌──────────────┐ ┌────────────┐ │
41
- │ │ rag_search │ │ web_search │ │sqlite_query│ │
42
- │ │ (ChromaDB) │ │(DuckDuckGo) │ │ (SQLite) │ │
43
- │ └──────┬─────┘ └──────┬───────┘ └─────┬──────┘ │
44
- │ │ │ │ │
45
- │ ┌──────┴────────────────┴──────────────────┘ │
46
- │ │ MCP Server (FastMCP / SSE) │
47
- │ │ Hosted FREE on Hugging Face Spaces 🤗 │
48
- │ └───────────────────────────────────────────────────┘
49
- │ │ synthesised text │
50
- │ ▼ │
51
- │ ┌────────────────────────┐ │
52
- │ │ Edge-TTS (free) │ │
53
- │ │ Microsoft Neural TTS │ │
54
- │ └────────────┬───────────┘ │
55
- │ │ audio bytes │
56
- │ ▼ │
57
- │ 🔊 Speaker │
58
- └─────────────────────────────────────────────────────────────────┘
59
- ```
60
-
61
- ### Free Component Map
62
-
63
- | Function | Original (Paid) | This Repo (Free) |
64
- |---|---|---|
65
- | LLM (reasoning) | GPT-4.1-mini | **Groq** — `llama-3.3-70b-versatile` |
66
- | STT (voice → text) | `gpt-4o-transcribe` | **Groq Whisper** — `whisper-large-v3-turbo` |
67
- | TTS (text → voice) | `gpt-4o-mini-tts` | **Edge-TTS** — Microsoft Neural (no key) |
68
- | Vector store / RAG | OpenAI Vector Stores | **ChromaDB** (local) + sentence-transformers |
69
- | Web search | OpenAI web_search tool | **DuckDuckGo** (no key) |
70
- | Agent framework | OpenAI Agents SDK | **LangChain** ReAct agent |
71
- | MCP server | Local only | **Hugging Face Spaces** (free Docker) |
72
- | Package manager | pip | **uv** (fast, lockfile-based) |
73
-
74
- ---
75
-
76
- ## 🚀 Quickstart
77
-
78
- ### Prerequisites
79
-
80
- | Tool | Install |
81
- |---|---|
82
- | Python 3.11+ | [python.org](https://python.org) |
83
- | **uv** | `curl -LsSf https://astral.sh/uv/install.sh \| sh` |
84
- | ffmpeg (audio) | macOS: `brew install ffmpeg` · Linux: `apt install ffmpeg` |
85
- | Groq API key | [console.groq.com](https://console.groq.com) (free, takes 30 seconds) |
86
-
87
- ### 1. Clone & install
88
-
89
- ```bash
90
- git clone https://github.com/YOUR-USERNAME/mcp-voice-agent.git
91
- cd mcp-voice-agent
92
-
93
- # uv creates the virtualenv and installs all deps from pyproject.toml
94
- uv sync
95
- ```
96
-
97
- ### 2. Configure environment
98
-
99
- ```bash
100
- cp .env.example .env
101
- # Edit .env — the only required value is GROQ_API_KEY
102
- ```
103
-
104
- ### 3. Seed data
105
-
106
- ```bash
107
- # Index your documents into ChromaDB
108
- uv run index-docs
109
-
110
- # (Optional) Seed SQLite with plan pricing data
111
- uv run python scripts/seed_sqlite.py
112
- ```
113
-
114
- ### 4. Start the MCP server
115
-
116
- ```bash
117
- # Terminal 1
118
- uv run mcp-server
119
- # → Server running at http://localhost:8000/sse
120
- ```
121
-
122
- ### 5. Start the voice assistant
123
-
124
- ```bash
125
- # Terminal 2
126
- uv run voice-agent
127
- # → Speak into your microphone!
128
- ```
129
-
130
- Or use the convenience scripts:
131
-
132
- ```bash
133
- chmod +x scripts/*.sh
134
- ./scripts/start_server.sh # terminal 1
135
- ./scripts/start_agent.sh # terminal 2
136
- ```
137
-
138
- ---
139
-
140
- ## 📁 Project Structure
141
-
142
- ```
143
- mcp-voice-agent/
144
-
145
- ├── src/ # All application source code
146
- │ ├── config.py # Centralised Pydantic settings (reads .env)
147
- │ ├── logger.py # Structured logging (structlog)
148
- │ │
149
- │ ├── agents/
150
- │ │ ├── planner.py # LangChain ReAct agent + Groq LLM
151
- │ │ └── voice_agent.py # Main conversation loop (CLI entry point)
152
- │ │
153
- │ ├── mcp_servers/
154
- │ │ └── search_server.py # FastMCP server: rag_search, web_search, health_check
155
- │ │
156
- │ ├── rag/
157
- │ │ └── indexer.py # Document loading, chunking, ChromaDB indexing
158
- │ │
159
- │ ├── voice/
160
- │ │ └── pipeline.py # STT (Groq Whisper) + TTS (Edge-TTS) + audio I/O
161
- │ │
162
- │ └── tools/ # (Extendable) standalone tool utilities
163
-
164
- ├── tests/
165
- │ ├── conftest.py # Shared fixtures (mocked env vars)
166
- │ ├── unit/
167
- │ │ ├── test_planner.py # Agent unit tests (mocked LLM/tools)
168
- │ │ └── test_indexer.py # RAG indexer unit tests
169
- │ └── integration/
170
- │ └── test_mcp_server.py # MCP tool integration tests
171
-
172
- ├── data/
173
- │ ├── sample_files/ # Drop your .txt / .md / .pdf docs here
174
- │ └── chroma_db/ # ChromaDB persisted index (git-ignored)
175
-
176
- ├── scripts/
177
- │ ├── start_server.sh # One-command server startup
178
- │ ├── start_agent.sh # One-command agent startup
179
- │ └── seed_sqlite.py # Seed SQLite with plan data
180
-
181
- ├── docs/ # MkDocs documentation
182
-
183
- ├── .github/
184
- │ └── workflows/
185
- │ └── ci.yml # GitHub Actions: lint → typecheck → test → deploy to HF
186
-
187
- ├── Dockerfile # For Hugging Face Spaces (port 7860, non-root)
188
- ├── pyproject.toml # uv-managed deps, ruff, mypy, pytest config
189
- ├── .python-version # Pins Python 3.11
190
- ├── .env.example # Template — copy to .env
191
- ├── .pre-commit-config.yaml # ruff + mypy + safety hooks
192
- ├── Makefile # Developer convenience commands
193
- └── README.md
194
- ```
195
-
196
  ---
197
-
198
- ## Deploy MCP Server to Hugging Face Spaces (Free)
199
-
200
- The MCP server (RAG + web search tools) runs as a free Docker Space on Hugging Face, giving you a persistent public SSE endpoint your local voice agent can call from anywhere.
201
-
202
- ### Step 1 — Create a Space
203
-
204
- 1. Go to [huggingface.co/spaces](https://huggingface.co/spaces)
205
- 2. Click **New Space**
206
- 3. Name it `mcp-voice-agent`
207
- 4. Select **Docker** as the SDK
208
- 5. Set visibility to **Public** (required for free tier) or **Private** (PRO)
209
-
210
- ### Step 2 — Set secrets
211
-
212
- In your Space → **Settings → Variables and Secrets**:
213
-
214
- | Secret name | Value |
215
- |---|---|
216
- | `GROQ_API_KEY` | Your Groq API key |
217
-
218
- ### Step 3 — Push via Git
219
-
220
- ```bash
221
- # Add the HF remote (replace YOUR-HF-USERNAME)
222
- git remote add hf https://huggingface.co/spaces/YOUR-HF-USERNAME/mcp-voice-agent
223
-
224
- # Push — HF Spaces auto-builds the Docker image
225
- git push hf main
226
- ```
227
-
228
- Your MCP server will be live at:
229
-
230
- ```
231
- https://YOUR-HF-USERNAME-mcp-voice-agent.hf.space/sse
232
- ```
233
-
234
- ### Step 4 — Point your local voice agent at HF
235
-
236
- ```bash
237
- # Use the hosted MCP server instead of localhost
238
- MCP_SERVER_URL=https://YOUR-HF-USERNAME-mcp-voice-agent.hf.space/sse \
239
- ./scripts/start_agent.sh
240
- ```
241
-
242
- Or set it permanently in your `.env`:
243
-
244
- ```ini
245
- MCP_SERVER_HOST=YOUR-HF-USERNAME-mcp-voice-agent.hf.space
246
- MCP_SERVER_PORT=443
247
- ```
248
-
249
- ### Automated Deploy via GitHub Actions
250
-
251
- The included CI workflow (`.github/workflows/ci.yml`) automatically deploys to HF Spaces on every push to `main` — after lint, typecheck, and tests pass.
252
-
253
- Set these GitHub repository secrets:
254
-
255
- | Secret | Description |
256
- |---|---|
257
- | `GROQ_API_KEY` | For integration tests |
258
- | `HF_TOKEN` | Hugging Face write token ([settings](https://huggingface.co/settings/tokens)) |
259
-
260
- Then update the deploy step in `ci.yml`:
261
-
262
- ```yaml
263
- git remote add hf https://YOUR-HF-USERNAME:${HF_TOKEN}@huggingface.co/spaces/YOUR-HF-USERNAME/mcp-voice-agent
264
- ```
265
-
266
  ---
267
 
268
- ## 🛠️ Development
269
-
270
- ### Common commands (via Makefile)
271
-
272
- ```bash
273
- make install-dev # Install all deps including dev extras
274
- make lint # Ruff linting
275
- make format # Ruff auto-format
276
- make typecheck # mypy strict type checking
277
- make test # All tests with coverage report
278
- make test-unit # Unit tests only
279
- make test-int # Integration tests only
280
- make index-docs # Re-index documents into ChromaDB
281
- make start-server # Start MCP server
282
- make start-agent # Start voice agent
283
- make docker-build # Build Docker image
284
- make docker-run # Run Docker image locally (mirrors HF Spaces env)
285
- make clean # Remove all build/cache artifacts
286
- ```
287
-
288
- ### Adding your own documents
289
-
290
- Drop `.txt`, `.md`, or `.pdf` files into `data/sample_files/`, then re-index:
291
 
292
- ```bash
293
- uv run index-docs --force # --force clears the existing index first
294
- ```
295
 
296
- ### Extending with new MCP tools
 
 
 
 
 
297
 
298
- Add a new `@mcp.tool()` function to `src/mcp_servers/search_server.py`:
299
 
300
- ```python
301
- @mcp.tool()
302
- def my_new_tool(query: str) -> str:
303
- """Describe what this tool does — the LLM reads this description."""
304
- ...
305
  ```
306
-
307
- Then register a LangChain wrapper in `src/agents/planner.py` inside `build_langchain_tools()`.
308
-
309
- ### Swapping the LLM
310
-
311
- Edit `.env`:
312
-
313
- ```ini
314
- # Groq free-tier options (as of 2026):
315
- LLM_MODEL=llama-3.3-70b-versatile # best reasoning
316
- LLM_MODEL=gemma2-9b-it # fastest, lowest latency
317
- LLM_MODEL=mixtral-8x7b-32768 # large context window
318
- ```
319
-
320
- No code changes needed — `ChatGroq` picks up the model from settings.
321
-
322
- ### Swapping the TTS voice
323
-
324
- ```ini
325
- # In .env — run `edge-tts --list-voices` to see all options
326
- TTS_VOICE=en-GB-SoniaNeural # British English
327
- TTS_VOICE=en-AU-NatashaNeural # Australian English
328
- TTS_VOICE=de-DE-KatjaNeural # German
329
- ```
330
-
331
- ---
332
-
333
- ## ⚙️ Configuration Reference
334
-
335
- All configuration is in `.env` (see `.env.example`). Every value is validated by Pydantic on startup — bad values fail fast with a clear error message.
336
-
337
- | Variable | Default | Description |
338
- |---|---|---|
339
- | `GROQ_API_KEY` | **required** | Groq API key (free at console.groq.com) |
340
- | `LLM_MODEL` | `llama-3.3-70b-versatile` | Groq chat model |
341
- | `STT_MODEL` | `whisper-large-v3-turbo` | Groq Whisper model |
342
- | `TTS_VOICE` | `en-US-JennyNeural` | Edge-TTS voice |
343
- | `EMBEDDING_MODEL` | `all-MiniLM-L6-v2` | Sentence-transformer model (local) |
344
- | `DOCS_DIR` | `./data/sample_files` | Directory of documents to index |
345
- | `CHROMA_PERSIST_DIR` | `./data/chroma_db` | ChromaDB storage path |
346
- | `MCP_SERVER_PORT` | `8000` | MCP server port (7860 on HF Spaces) |
347
- | `MCP_TRANSPORT` | `sse` | `sse` for network, `stdio` for subprocess |
348
- | `APP_ENV` | `development` | `development` or `production` |
349
- | `LOG_FORMAT` | `console` | `console` (pretty) or `json` (structured) |
350
-
351
- ---
352
-
353
- ## 🧪 Testing
354
-
355
- ```bash
356
- uv run pytest # all tests
357
- uv run pytest tests/unit/ # unit only (no network, no API keys)
358
- uv run pytest -v --tb=long # verbose output
359
  ```
360
 
361
- The test suite uses mocks for all external calls (Groq API, ChromaDB, DuckDuckGo), so tests run fully offline and require no API keys.
362
-
363
- ---
364
-
365
- ## 📜 License
366
-
367
- MIT — see [LICENSE](LICENSE).
368
-
369
- ---
370
-
371
- ## 🙏 Acknowledgements
372
 
373
- - [OpenAI MCP Voice Agents Cookbook](https://developers.openai.com/cookbook/examples/partners/mcp_powered_voice_agents/mcp_powered_agents_cookbook.ipynb) — original inspiration
374
- - [Groq](https://groq.com)fast, free LLM + Whisper inference
375
- - [LangChain](https://langchain.com)agent orchestration
376
- - [FastMCP](https://github.com/jlowin/fastmcp) — ergonomic MCP server framework
377
- - [Edge-TTS](https://github.com/rany2/edge-tts) — free Microsoft neural TTS
378
- - [ChromaDB](https://www.trychroma.com) — local vector database
379
- - [Hugging Face Spaces](https://huggingface.co/spaces) — free cloud hosting
380
- - [uv](https://github.com/astral-sh/uv) — blazing-fast Python package manager
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
+ title: MCP Voice Agent
3
+ emoji: 🎙
4
+ colorFrom: blue
5
+ colorTo: purple
6
+ sdk: docker
7
+ pinned: false
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  ---
9
 
10
+ # MCP Voice Agent
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
+ Production-grade MCP-powered voice assistant using free LLMs.
 
 
13
 
14
+ - **LLM**: Groq `llama-3.3-70b-versatile`
15
+ - **STT**: Groq Whisper
16
+ - **TTS**: Edge-TTS
17
+ - **RAG**: ChromaDB + sentence-transformers
18
+ - **Web Search**: DuckDuckGo
19
+ - **MCP Server**: FastMCP (SSE transport)
20
 
21
+ ## MCP Server Endpoint
22
 
23
+ Once running, the MCP SSE endpoint is available at:
 
 
 
 
24
  ```
25
+ https://adarshds-mcp-voice-agent.hf.space/sse
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  ```
27
 
28
+ ## Tools Available
 
 
 
 
 
 
 
 
 
 
29
 
30
+ - `rag_search` search internal insurance documents
31
+ - `web_search`search the web via DuckDuckGo
32
+ - `health_check`check server status