File size: 25,974 Bytes
46bc2e2
9e8081f
 
46bc2e2
 
 
caabec8
9e8081f
 
46bc2e2
 
be5ee6d
dd53022
5ef3828
 
 
 
 
dd53022
 
5ef3828
dd53022
be5ee6d
cdf4f90
 
 
be5ee6d
dd53022
 
 
 
5ef3828
dd53022
cdf4f90
 
be5ee6d
5ef3828
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
02805c2
dd53022
02805c2
dd53022
cdf4f90
dd53022
cdf4f90
 
 
 
 
02805c2
5ef3828
 
 
02805c2
5ef3828
 
dd53022
5ef3828
dd53022
 
 
 
 
 
 
 
 
5ef3828
dd53022
 
 
 
 
 
 
 
5ef3828
dd53022
5ef3828
 
dd53022
 
5ef3828
dd53022
 
5ef3828
dd53022
 
5ef3828
 
 
dd53022
 
 
5ef3828
 
cdf4f90
 
 
 
 
 
 
 
 
 
 
 
dd53022
cdf4f90
dd53022
cdf4f90
dd53022
cdf4f90
5ef3828
 
cdf4f90
5ef3828
 
cdf4f90
 
 
dd53022
cdf4f90
 
 
 
 
 
 
 
 
 
5ef3828
cdf4f90
 
5ef3828
cdf4f90
dd53022
cdf4f90
5ef3828
 
 
cdf4f90
 
 
 
5ef3828
 
cdf4f90
5ef3828
cdf4f90
 
5ef3828
 
 
 
 
cdf4f90
5ef3828
 
 
 
 
 
 
 
 
 
 
02805c2
5ef3828
cdf4f90
 
 
 
 
5ef3828
 
 
 
02805c2
 
 
5ef3828
 
be5ee6d
dd53022
be5ee6d
cdf4f90
be5ee6d
 
cdf4f90
be5ee6d
 
cdf4f90
 
5ef3828
 
 
dd53022
5ef3828
 
 
 
cdf4f90
dd53022
 
 
cdf4f90
 
 
 
 
 
 
 
 
 
 
 
5ef3828
 
 
 
cdf4f90
 
 
5ef3828
 
cdf4f90
dd53022
cdf4f90
 
dd53022
cdf4f90
 
 
 
 
 
 
 
 
 
 
 
 
 
5ef3828
 
 
cdf4f90
5ef3828
 
 
cdf4f90
 
 
 
 
 
 
 
dd53022
be5ee6d
cdf4f90
 
 
dd53022
 
cdf4f90
 
 
 
 
 
 
 
 
 
 
 
5ef3828
cdf4f90
 
 
be5ee6d
5ef3828
 
dd53022
 
5ef3828
 
be5ee6d
 
5ef3828
 
 
be5ee6d
dd53022
be5ee6d
 
 
 
 
dd53022
be5ee6d
 
 
 
 
dd53022
be5ee6d
 
 
 
 
dd53022
be5ee6d
 
 
 
 
 
 
 
dd53022
 
 
 
 
 
 
 
 
 
 
 
5ef3828
dd53022
5ef3828
 
 
 
dd53022
be5ee6d
 
 
5ef3828
 
 
 
 
dd53022
be5ee6d
cdf4f90
 
 
 
 
 
be5ee6d
cdf4f90
5ef3828
dd53022
 
cdf4f90
 
 
 
 
02805c2
cdf4f90
02805c2
5ef3828
 
be5ee6d
 
5ef3828
 
dd53022
 
 
 
 
 
 
 
 
5ef3828
 
 
dd53022
 
5ef3828
 
 
be5ee6d
dd53022
cdf4f90
 
 
dd53022
cdf4f90
 
 
dd53022
be5ee6d
 
dd53022
 
 
 
 
 
 
5ef3828
 
dd53022
 
 
 
cdf4f90
 
 
 
 
dd53022
cdf4f90
 
 
be5ee6d
cdf4f90
dd53022
cdf4f90
 
 
 
 
 
5ef3828
 
 
cdf4f90
 
5ef3828
 
 
cdf4f90
 
 
 
 
 
 
 
 
dd53022
cdf4f90
dd53022
 
cdf4f90
 
 
dd53022
 
 
 
be5ee6d
02805c2
5ef3828
dd53022
02805c2
5ef3828
 
 
be5ee6d
 
5ef3828
 
 
be5ee6d
cdf4f90
 
 
 
dd53022
 
 
5ef3828
be5ee6d
cdf4f90
 
 
02805c2
5ef3828
 
 
02805c2
 
5ef3828
 
02805c2
5ef3828
cdf4f90
 
 
 
 
dd53022
cdf4f90
5ef3828
cdf4f90
dd53022
cdf4f90
5ef3828
 
dd53022
 
5ef3828
 
dd53022
 
5ef3828
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
dd53022
be5ee6d
 
 
 
5ef3828
 
 
 
 
 
 
 
 
 
 
 
02805c2
 
 
 
5ef3828
 
be5ee6d
5ef3828
 
be5ee6d
5ef3828
 
 
be5ee6d
 
 
5ef3828
 
 
 
 
9e8081f
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
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
---
title: Universal AI Hub - Public Demo (no keys)
emoji: πŸ‘
colorFrom: indigo
colorTo: red
sdk: docker
pinned: true
license: agpl-3.0
short_description: aka- a clean, secure starting point for your own projects
---



# Universal AI Hub πŸ›‘οΈ
> 🚧 **Status:** Under active development. Built strictly for private spaces with hardened anti-spam and anti-scammer guardrails. Use at your own discretion.


aka: a clean, secure starting point for your own projects.
Pick the description that fits your use case. They're all correct.

> A **the-thing** that actually thinks about security.
> Built on [PyFundaments](PyFundaments.md) β€” running on **simpleCity**.

```
No key β†’ no tool β†’ no crash β†’ no exposed secrets
```

> [!WARNING]
> Most MCP servers are prompts dressed up as servers. This one has a real architecture.

> [!IMPORTANT]
> This project is under active development β€” always use the latest release from [Codey Lab](https://github.com/Codey-LAB/Multi-LLM-API-Gateway) *(more stable builds land here first)*.
> This repo ([DEV](https://github.com/VolkanSah/Multi-LLM-API-Gateway)) is where the chaos happens. πŸ”¬ A ⭐ on the repos will be cool πŸ˜™

---

<details>
<summary><b>🧠 Usernote: how this was actually built (no vibecode - or am I lying? πŸ˜„)</b></summary>
     
I created this code on my own. And it took a toll on me - I mean really took a toll. We're not talking about my code not working, but more like I've been looking at my own design for so long that my brain is a mess. That's when AI came into the picture - not to do the coding for me, but to help me make sense of my thoughts and organize the ideas that were already floating around in my head.

So, is this something called vibecoding? **No**, it's not. Vibecoding is when you send off code without really understanding what it does, and just hope it works out. But I know exactly what's going on here - every single line, even the weird parts. I made some specific choices, like using the guardian pattern, setting up a sandbox, and creating a `.pyfun` file that's the single source of truth. I also followed the no-key-no-tool rule. These were all my decisions, made before any AI even got involved. My coding style is pretty unique, and you'll notice it as soon as you look at the source code. The AI was more like a partner that helped me out, typing fast and sometimes making mistakes that I had to fix.

...or am I just making it up? Don't just listen to me, go check the code for yourself.

</details>

---

<details>
<summary><b>πŸ†• What's new in v1.2.0 β€” memory that survives a reboot</b></summary>

> Full changelog (with proof) in [`REVIEW.md`](REVIEW.md). The short version, my words:

- **Memory orchestration.** `persist_result` without `DATABASE_URL` used to throw a `RuntimeError`. Now everything lands in a restart-safe `persist_queue` in SQLite β€” proven: 3 entries in, reboot, 3 entries out β€” and a background flusher pushes them into PostgreSQL whenever the bridge is back. `persist_status` (MCP + `/api`) shows queue depth, attempts and bridge state.
- **Auto-pricing, konsequent.** I asked whether the manual `cost_*` lines still make sense. OpenRouter FAQ, checked live: no markup, per-token = vendor list price (the ~5.5 % fee hits credit purchase, not tokens). So 34 cost lines are gone. What stays: my own models (`smollm2-360m` = 0.0 β€” no external source knows my own deployment). `.pyfun` values still win as override, always.
- **ShellMaster = SECURITY LEVEL ROT.** My CLI commander for the local Quart agent (`localhost:5004`) β€” commands run on YOUR machine, so: local only, never on a public Space. Token lives in `.env` via `SHELLMASTER_TOKEN` (same pattern as every provider); the `.pyfun` field is only a local test fallback. `active = "false"`. Stays off until someone consciously flips it.
- **Score slot for my filter.** `hub_results.score` exists β€” the hub passes it through completely uninterpreted. What's worth remembering long-term gets decided by my own filter, not by the hub. That part is my code, my rules.

*Tests: 26/26 orchestration + 4/4 smoke β€” green.*

<details>
<summary><b>v1.1.0 (the rebuild) β€” older news</b></summary>

- **Fixed:** `/mcp` 404 (mount middleware stripped the prefix FastMCP expects) and the missing session-manager lifespan β€” MCP is fully functional again.
- **New:** **Auto model pricing** β€” costs fetched from the public OpenRouter models API + the LiteLLM community price list, cached in `db_sync` (24h TTL). `.pyfun [MODELS]` values win as override.
- **New:** Brave + Tavily search providers with fallback chain β€” `web_search` registers as soon as `BRAVE_API_KEY` or `TAVILY_API_KEY` is set.
- **New:** `db_query` as MCP tool (SELECT-only, app/* tables).
- **Cleanup:** dead code removed, `requirements.txt` pins `mcp>=1.10,<2` (not `fastmcp`), LF line endings.

</details>
</details>

--- 

<details>
<summary><b>❓ Why this exists</b></summary>

The AI ecosystem is full of servers with hardcoded keys, `os.environ` scattered everywhere, zero sandboxing. One misconfigured fork and your API keys are gone.

This is exactly the kind of negligence (and worse β€” outright fraud) that [Wall of Shames](https://github.com/Wall-of-Shames) documents: fake "AI tools" exploiting non-technical users β€” API wrappers dressed up as custom models, Telegram payment funnels, bought stars. If you build on open source, you should know this exists.

This hub is the antidote:

- **Structural sandboxing** β€” `app/*` can never touch `fundaments/` or `.env`. Not by convention. By design.
- **Guardian pattern** β€” `main.py` is the only process that reads secrets. It injects validated services as a dict. `app/*` never sees the raw environment.
- **Graceful degradation** β€” No key? Tool doesn't register. Server still starts. No crash, no error, no empty `None` floating around.
- **Single source of truth** β€” All tool/provider/model config lives in `app/.pyfun`. Adding a provider = edit one file. No code changes.

</details>

--- 

<details>
<summary><b>πŸ”Œ Two interfaces β€” one server</b></summary>

Two completely independent interfaces on the same hypercorn instance:

```
POST /api          β†’ REST interface β€” for custom clients, desktop apps, CMS plugins
GET+POST /mcp      β†’ MCP interface β€” for Claude Desktop, Cursor, Windsurf, any MCP client
GET /              β†’ Health check β€” uptime, status
```

They share the same tool registry, provider config, and fallback chain. Adding a tool once makes it available on both interfaces automatically.

**REST (`/api`)** β€” simple JSON POST, no protocol overhead, works with any HTTP client:

```json
POST /api
{"tool": "llm_complete", "params": {"prompt": "Hello", "provider": "anthropic"}}
```

Used by: Desktop Client (`DESKTOP_CLIENT/hub.py`), WordPress plugin, any custom integration.

**MCP (`/mcp`)** β€” full MCP protocol: tool discovery, structured calls, streaming responses.

- Primary transport: **Streamable HTTP** (MCP spec 2025-11-25)
- Fallback transport: **SSE** (legacy, configurable via `.pyfun`)

```ini
[HUB]
HUB_TRANSPORT = "streamable-http"   # default β€” MCP spec 2025-11-25
# HUB_TRANSPORT = "sse"             # legacy fallback for older clients
[HUB_END]
```

Auth, rate limiting and logging can all hook into the `/mcp` route in `app/app.py` before a request ever reaches FastMCP.

</details>

---

<details>
<summary><b>πŸ— Architecture β€” the sandbox is structural</b></summary>

```
main.py (Guardian)
β”‚
β”‚  reads .env / HF Secrets
β”‚  initializes fundaments/* conditionally
β”‚  injects validated services as dict
β”‚
└──► app/app.py (Orchestrator, sandboxed)
     β”‚
     β”‚  unpacks fundaments ONCE, at startup, never stores globally
     β”‚  starts hypercorn (async ASGI)
     β”‚  routes: GET / | POST /api | /mcp (transport-dependent)
     β”‚
     β”œβ”€β”€ app/mcp.py         ← FastMCP + transport handler (Streamable HTTP / SSE)
     β”œβ”€β”€ app/tools.py       ← Tool registry (key-gated)
     β”œβ”€β”€ app/providers.py   ← LLM + Search execution + fallback chain
     β”œβ”€β”€ app/models.py      ← Model limits, costs, capabilities
     β”œβ”€β”€ app/shellmaster.py ← CLI commander (SECURITY LEVEL ROT β€” local only)
     β”œβ”€β”€ app/pricing.py     ← Auto model pricing (OpenRouter + LiteLLM)
     β”œβ”€β”€ app/config.py      ← .pyfun parser (single source of truth)
     └── app/db_sync.py     ← SQLite: short-term state + persist_queue (memory bridge)
                              β‰  fundaments/postgresql.py (Guardian-only, long-term)
```

```python
# app/app.py β€” fundaments unpacked ONCE, NEVER stored globally
async def start_application(fundaments: Dict[str, Any]) -> None:
    config_service         = fundaments["config"]
    db_service             = fundaments["db"]          # None if not configured
    encryption_service     = fundaments["encryption"]  # None if keys missing
    access_control_service = fundaments["access_control"]
    ...
    # From here: app/* reads its own config from app/.pyfun only.
    # fundaments are never passed into other app/* modules.
```

`app/app.py` never calls `os.environ`. Never imports from `fundaments/`. Never reads `.env`.
This isn't documentation. It's enforced by the import structure.

**Why Quart + hypercorn?**

**Quart** is async Flask β€” fully `async/await` native. FastMCP's handlers are async; mixing sync Flask would require thread hacks. With Quart, `/mcp` hands off directly to FastMCP β€” no bridging, no blocking.

**hypercorn** is an ASGI server (vs. waitress/gunicorn which are WSGI). WSGI servers handle one request per thread β€” wrong for long-lived MCP connections. hypercorn handles both Streamable HTTP and SSE natively, and runs without extra config on HuggingFace Spaces. HTTP/2 support (`config.h2 = True`) is built-in.

</details>


---

<details>
<summary><b>πŸ’Ύ Memory β€” short-term, long-term, and my filter (v1.2.0)</b></summary>

The design is deliberately simple:

```
SQLite  = short-term memory  β€” all AI tools read & write here, nobody waits for the cloud
SQLite persist_queue = the bridge β€” restart-safe, survives reboots (proven)
PostgreSQL = long-term memory β€” what survived MY filter goes here
```

```
persist_result (MCP + /api)
   ↓ enqueue_persist()        ← immediately, ALWAYS, no crash β€” even without DATABASE_URL
persist_queue (SQLite)        ← survives restarts; on HF Spaces /tmp, PG is the only durable memory
   ↓ flush_persist_queue()    ← background flusher, retry every 60 s (configurable)
PostgreSQL hub_results        ← (id, created_at, source, model, score, payload JSONB)
```

- **No `DATABASE_URL`?** `status: "queued"` β€” no RuntimeError, no 502, nothing lost.
- **PostgreSQL down?** Entry stays, `attempts` +1, sanitized `last_error`. Flusher catches up when the bridge returns.
- **`score REAL`** β€” a reserved slot for my own quality filter. The hub passes it through untouched; the filter writes it (or filters on read) later. No hub code interprets it. That's on purpose β€” my filter, my rules.
- **Limits:** queue max 500 (oldest evicted, like `tool_cache`) Β· at-least-once semantics (a duplicate beats a loss) Β· observability via `persist_status` (queue depth, oldest entry, attempts, bridge state).

**Guardian layer vs app layer β€” table ownership, hard rule:**

| Table | Owner | Access |
| :--- | :--- | :--- |
| `users` | `fundaments/user_handler.py` | Guardian only |
| `sessions` | `fundaments/user_handler.py` | Guardian only |
| `hub_state`, `tool_cache`, `persist_queue` | `app/db_sync.py` | app/* only |
| `hub_results` | PostgreSQL / Guardian | via `persist_result` β†’ queue β†’ flusher |

</details>

---

<details>
<summary><b>🧰 Tools β€” no key, no tool, server still starts</b></summary>

Tools register at startup β€” only if the required API key exists. No key, no tool. Server always starts.

| ENV Secret | Tool | Notes |
| :--- | :--- | :--- |
| `ANTHROPIC_API_KEY` | `llm_complete` | Claude Haiku / Sonnet / Opus |
| `GEMINI_API_KEY` | `llm_complete` | Gemini 2.0 / 2.5 / 3.x Flash & Pro |
| `OPENROUTER_API_KEY` | `llm_complete` | 100+ models via OpenRouter |
| `HF_TOKEN` | `llm_complete` | HuggingFace Inference API |
| `BRAVE_API_KEY` | `web_search` | Independent web index |
| `TAVILY_API_KEY` | `web_search` | AI-optimized search with synthesized answers |
| `DATABASE_URL` | `persist_result`, `persist_status` | Long-term memory bridge (queue without it) |
| `SHELLMASTER_TOKEN` | `shellmaster*` | β›” SECURITY LEVEL ROT β€” local only, `active="false"` |
| *(always)* | `list_active_tools` | Shows key names only β€” never values. Plus `pricing_stats` |
| *(always)* | `health_check` | Status + uptime + active transport |
| *(always)* | `get_model_info` | Limits, costs, capabilities per model (auto-merged) |
| *(always)* | `get_model_pricing` | Auto-fetched costs β€” `.pyfun` values win as override |
| *(always)* | `refresh_pricing` | Force refresh from OpenRouter + LiteLLM |
| *(always)* | `db_query` | Read-only SELECT on internal hub state |

For all key names see [`app/.pyfun`](app/.pyfun).

**Tools are configured in `.pyfun` β€” including system prompts:**

```ini
[TOOL.code_review]
active           = "true"
description      = "Review code for bugs, security issues and improvements"
provider_type    = "llm"
default_provider = "anthropic"
timeout_sec      = "60"
system_prompt    = "You are an expert code reviewer. Analyze the given code for bugs, security issues, and improvements. Be specific and concise."
[TOOL.code_review_END]
```

Current built-in tools: `llm_complete`, `code_review`, `summarize`, `translate`, `web_search`, `db_query`, `persist_result`, `persist_status`
Future hooks (commented, ready): `image_gen`, `code_exec`, ShellMaster 2.0 (ROT β€” local only), Discord, GitHub webhooks

</details>

---

<details>
<summary><b>πŸ” Fallback chain</b></summary>

All LLM providers share one `llm_complete` tool. If a provider fails, the hub walks the fallback chain from `.pyfun`:

```
e.g. anthropic β†’ gemini β†’ openrouter β†’ huggingface
```

```ini
[LLM_PROVIDER.anthropic]
fallback_to = "gemini"
[LLM_PROVIDER.anthropic_END]

[LLM_PROVIDER.gemini]
fallback_to = "openrouter"
[LLM_PROVIDER.gemini_END]
```

Same pattern applies to search providers (`brave β†’ tavily`).

</details>

--- 


<details open>
<summary><b>πŸš€ Quick start</b></summary>

### HuggingFace Spaces (recommended)

1. Fork / duplicate this Space
2. Go to **Settings β†’ Variables and secrets**
3. Add the API keys you have (any subset works)
4. Space starts automatically β€” only tools with valid keys register

[β†’ Live Demo Space](https://huggingface.co/spaces/codey-lab/Multi-LLM-API-Gateway) (no LLM keys set)

### Local / Docker

```bash
git clone https://github.com/VolkanSah/Multi-LLM-API-Gateway
cd Multi-LLM-API-Gateway
cp example-mcp___.env .env
# fill in your keys
pip install -r requirements.txt
python main.py
```

Minimum required ENV vars (everything else is optional):

```env
PYFUNDAMENTS_DEBUG=""
LOG_LEVEL="INFO"
LOG_TO_TMP=""
ENABLE_PUBLIC_LOGS="false"
HF_TOKEN=""
HUB_SPACE_URL=""
```

> Note: HF Spaces prints stdout to a **publicly visible log tab**. `ENABLE_PUBLIC_LOGS="false"` keeps your logs yours. Default in code is still `true` β€” my fundament, my call, documented everywhere; flip it consciously.

Transport is configured in `app/.pyfun [HUB]` β€” not via ENV.

</details>

---


<details>
<summary><b>πŸ”— Connect an MCP client</b></summary>

### Streamable HTTP (default β€” MCP spec 2025-11-25)

```json
{
  "mcpServers": {
    "universal-mcp-hub": {
      "url": "https://YOUR_USERNAME-universal-mcp-hub.hf.space/mcp"
    }
  }
}
```

### Streamable HTTP β€” Private Space (with HF token)

```json
{
  "mcpServers": {
    "universal-mcp-hub": {
      "url": "https://YOUR_USERNAME-universal-mcp-hub.hf.space/mcp",
      "headers": {
        "Authorization": "Bearer hf_..."
      }
    }
  }
}
```

### SSE legacy fallback (set `HUB_TRANSPORT = "sse"` in `.pyfun`)

```json
{
  "mcpServers": {
    "universal-mcp-hub": {
      "url": "https://YOUR_USERNAME-universal-mcp-hub.hf.space/mcp"
    }
  }
}
```

> Same URL (`/mcp`) for both transports β€” the protocol is negotiated automatically.
> SSE fallback is for older clients that don't support Streamable HTTP yet.
> (`HUB_STATELESS="true"` is intentional for HF Spaces β€” no `Mcp-Session-Id` header is expected, not a bug.)

</details>


---


<details>
<summary><b>πŸ–₯ Desktop client (experimental β€” ~80 % me, 20 % typing assistant)</b></summary>

A full PySide6 desktop client is included in `DESKTOP_CLIENT/hub.py`.
Communicates via the REST `/api` endpoint β€” no MCP protocol overhead.
Ideal for private or non-public Spaces.

```bash
pip install PySide6 httpx
# optional file handling:
pip install Pillow PyPDF2 pandas openpyxl
python DESKTOP_CLIENT/hub.py
```

**Features:**

- Multi-chat with persistent history
- Tool / Provider / Model selector loaded live from your Hub
- File attachments: images, PDF, CSV, Excel, ZIP, source code
- Connect tab with health check + auto-load
- Settings: HF Token + Hub URL saved locally, never sent anywhere except your own Hub
- Full request/response log with timestamps
- Runs on Windows, Linux, macOS

[β†’ Desktop Client docs](DESKTOP_CLIENT/README.md)

</details>

---

<details>
<summary><b>🧩 CMS & custom clients</b></summary>

| Client | Interface used | Notes |
| :--- | :--- | :--- |
| [Desktop Client](DESKTOP_CLIENT/hub.py) | REST `/api` | PySide6, local |
| [WP AI Hub](https://github.com/VolkanSah/WP-AI-HUB/) | REST `/api` | WordPress plugin |
| TYPO3 (soon) | REST `/api` | β€” |
| Claude Desktop | MCP `/mcp` | Streamable HTTP |
| Cursor / Windsurf | MCP `/mcp` | Streamable HTTP |

</details>


---


<details>
<summary><b>βš™οΈ Configuration (.pyfun) β€” one file to rule the app</b></summary>

`app/.pyfun` is the single source of truth for all app behavior. Three tiers:

```
LAZY:       [HUB] + one [LLM_PROVIDER.*]                    β†’ works
NORMAL:     + [SEARCH_PROVIDER.*] + [MODELS.*]              β†’ works better
PRODUCTIVE: + [TOOLS] + [HUB_LIMITS] + [DB_SYNC]           β†’ full power
```

Key settings in `[HUB]`:

```ini
[HUB]
HUB_TRANSPORT   = "streamable-http"   # streamable-http | sse
HUB_STATELESS   = "true"              # true = HF Spaces safe, no session state
HUB_PORT        = "7860"
[HUB_END]
```

**About `[MODELS]` costs (v1.2.0):** auto-pricing fills everything from OpenRouter + LiteLLM. Manual `cost_*` lines only remain for models no external source can know β€” my own deployments. If you ever get different conditions than the public lists (custom deals exist), just add `cost_*` lines for THAT model β€” `.pyfun` wins, always. The section also carries `requests_per_min/day`, `context_tokens`, `capabilities` and the provider mapping β€” none of that exists in any price API.

Adding a new LLM provider β€” two steps:

```ini
# 1. app/.pyfun
[LLM_PROVIDER.mistral]
active        = "true"
base_url      = "https://api.mistral.ai/v1"
env_key       = "MISTRAL_API_KEY"
default_model = "mistral-large-latest"
models        = "mistral-large-latest, mistral-small-latest"
fallback_to   = ""
[LLM_PROVIDER.mistral_END]
```

```python
# 2. app/providers.py β€” uncomment the dummy
_PROVIDER_CLASSES = {
    ...
    "mistral": MistralProvider,   # ← uncomment to activate
}
```

</details>


---


<details>
<summary><b>πŸ“¦ Dependencies</b></summary>

```
# PyFundaments Core (always required)
asyncpg          β€” async PostgreSQL pool (Guardian/cloud DB)
python-dotenv    β€” .env loading
passlib          β€” PBKDF2 password hashing in user_handler.py
cryptography     β€” encryption layer in fundaments/

# MCP Hub
mcp              β€” MCP protocol + FastMCP (Streamable HTTP + SSE)
httpx            β€” async HTTP for all provider API calls
quart            β€” async Flask (ASGI) β€” needed for MCP + hypercorn
hypercorn        β€” ASGI server β€” Streamable HTTP + SSE, HF Spaces native
requests         β€” sync HTTP for tool workers

# Optional (uncomment in requirements.txt as needed)
# aiofiles         β€” async file ops (ML pipelines, file uploads)
# discord.py       β€” Discord bot integration (planned)
# PyNaCl           β€” Discord signature verification
# psycopg2-binary  β€” alternative PostgreSQL driver
```

> **Note:** The package is `mcp` (not `fastmcp`) β€” `FastMCP` is imported from `mcp.server.fastmcp`.
> Streamable HTTP support requires `mcp >= 1.6.0`.

</details>


---


<details>
<summary><b>πŸ›‘ Security design</b></summary>

- API keys live in HF Secrets / `.env` β€” never in `.pyfun`, never in code
- `list_active_tools` returns key **names** only β€” never values
- `db_query` is SELECT-only, enforced at application level (not just docs)
- `app/*` has zero import access to `fundaments/` internals
- Direct execution of `app/app.py` blocked by design β€” warning + null-fundaments fallback
- `fundaments/` initialized conditionally β€” missing services degrade gracefully, never crash
- Streamable HTTP uses standard Bearer headers β€” no token-in-URL (unlike SSE)
- ShellMaster: **SECURITY LEVEL ROT** β€” hardblock list (rm -rf, mkfs, …), JSONL command registry, explicit confirmation before every execution, local-only (`localhost:5004`), token via `.env`

> PyFundaments is not perfect. But it's more secure than most of what runs in production today.

[β†’ Full Security Policy](SECURITY.md)

</details>


---

<details>
<summary><b>🧱 Foundation: PyFundaments</b></summary>

Built on [PyFundaments](PyFundaments.md) β€” a security-first Python boilerplate, crafted by hand over months (see the usernote at the top):

- `config_handler.py` β€” env loading with validation
- `postgresql.py` β€” async DB pool (Guardian-only)
- `encryption.py` β€” key-based encryption layer
- `access_control.py` β€” role/permission management
- `user_handler.py` β€” user lifecycle management
- `security.py` β€” unified security manager composing the above
- `debug.py` β€” conditional startup diagnostics

None accessible from `app/*`. Injected as a validated dict by `main.py`.

[β†’ PyFundaments Function Overview](PyFundaments%20–%20Function%20Overview.md)
[β†’ Module Docs](docs/app/)
[β†’ Source Repo](https://github.com/VolkanSah/Multi-LLM-API-Gateway)

</details>

---

<details><summary><b>πŸ›€οΈ Roadmap</b></summary>

## haha that's good!
- [x] 10 months before...
- [x] some blackouts
- [x] more blackouts
- [x] ... month 6 WTF... runs but only stupid secure LLM wrapper and tools...
- [x] ... pff brick again!
- [x] ... fuck!
- [x] ... rewrite
- [x] fuck Neon DB + MCP changes secure stuff! fuck
- [x] rewritten
- [x] GLM checked it, stupid guy! but finds 2 hidden design bugs, no execution but stupid fail!
- [x] Claude checks again and again and again, my 5 hours limit used in 1.23 min. A record of my self, normally need 2 minutes
- [x] wtf, fuck you Claude, fuck you Gemini, fuck you GLM, fuck you Kimi, fuck you DeepSeek, all others I do not use
- [x] fuck! but runs again! I see my first instinct was the best, AI made me crazy!
- [x] new rewrite with Claude Sonnet, first kick this asshole in his fucking balls 12 times! I get poor bitch!
- [x] it runs...
- [x] Fuck yeah, stable fast, secure and against scammers! only for privates!
- [x] fail architecture for vibecoders!
- [x] README AI slop from AI with a fucking touch of me!
- [x] conditional initialization of fundament modules...
- [x] Fundament modules are ready for the app logic.
- [x] PostgreSQL bridge activ
- [x] ShellMaster & Discord API not 100 % finished!
- [X] tools anΒ΄d stiff.. later to much yet!
- [ ] some futers.. still crafting
     
</details>




---


<details>
<summary><b>πŸ“œ History & related projects</b></summary>

[ShellMaster](https://github.com/VolkanSah/ChatGPT-ShellMaster) (2023, MIT) was the precursor β€” browser-accessible shell for ChatGPT with session memory, built before MCP was a concept. Universal AI Hub is its natural evolution: same idea, proper architecture, dual interface. And yes β€” the ShellMaster idea is back as a tool hook, now with a red security level and a conscience.

Related:

- [Customs LLMs for free β€” Build Your Own LLM Service](https://github.com/VolkanSah/SmolLM2-customs/)
- [WP AI Hub (WordPress Client)](https://github.com/VolkanSah/WP-AI-HUB/)
- [ShellMaster (2023 precursor)](https://github.com/VolkanSah/ChatGPT-ShellMaster)

</details>

---


<details>
<summary><b>βš–οΈ License β€” Multi-License & ESOL (mandatory)</b></summary>

- Projekt GNU Affero General Public License v3.0 [see License](https://www.gnu.org/licenses/agpl-3.0.html) + Ethical Security Operations License v2.1 [see License](ESOL) β€” mandatory, non-severable
- Some scripts i made Apache License 2.0 [see License](https://www.apache.org/licenses/LICENSE-2.0) + GNU General Public License v3.0 [see License](https://www.gnu.org/licenses/gpl-3.0.html) + MIT License [see License](https://opensource.org/licenses/MIT) (only for as for examples, some skills and agents public on MIT or other open source license i use here in this hub for showcases, see files for more infos)

##### By using this software you agree to all ethical constraints defined in ESOL v2.1.

</details>

---

*Architecture, security decisions and 100 % of brocken code ( ok 100 % Running with less than 1 % mistakes) and PyFundaments by me.*
*Built with Claude (Anthropic not claude coder or codex or wtf!) after 20 % own desaster 5 seps bevor relase, played with GLM to see an outher focus but at the end as a typing assistant for docs (and the occasional bug) after i brick my hole work after i made it to complex... so i mean its not ready!*

> crafted with passion - just wanted to understand how it works, don't actually need it, have a CLI πŸ˜„
> 
> README.md craftet (rewritten) by gemini 3 Pro , fixed by me, looks terrible i know! AI slop from claude, geminie and me! Soon better i sewar!