182 lines
5.4 KiB
Markdown
182 lines
5.4 KiB
Markdown
# Running MCP Gateway with Open-UI
|
|
|
|
You now have OpenAI-compatible endpoints for your MCP Gateway! This allows Open-UI to use all your MCP tools.
|
|
|
|
## ✅ What's Been Done
|
|
|
|
1. ✅ Created `openai_routes.py` - Handles OpenAI-compatible API requests
|
|
2. ✅ Updated `gateway_proxy.py` - Added `/v1/models` and `/v1/chat/completions` endpoints
|
|
3. ✅ Configuration ready - Just need to restart the gateway
|
|
|
|
## 🚀 Next Steps
|
|
|
|
### Step 1: Restart Your Gateway
|
|
|
|
```bash
|
|
cd /sessions/beautiful-serene-gauss/mnt/MCP\ Servers/mcp-gateway/
|
|
docker compose restart mcp-gateway
|
|
```
|
|
|
|
Check the logs to verify the endpoints are registered:
|
|
|
|
```bash
|
|
docker compose logs mcp-gateway | grep -i "openai\|v1"
|
|
```
|
|
|
|
You should see: `OpenAI-compatible endpoints registered at /v1/*`
|
|
|
|
### Step 2: Test the New Endpoints
|
|
|
|
**Test `/v1/models`:**
|
|
```bash
|
|
curl -H "Authorization: Bearer rIoRseJSR9rqwl5bp4CEOyOUKdymaoJnAsT-y752BDi2qD9jJYbgd8sWkiQIGMtz" \
|
|
https://mcp.wilddragon.net/v1/models
|
|
```
|
|
|
|
Expected response:
|
|
```json
|
|
{
|
|
"object": "list",
|
|
"data": [
|
|
{
|
|
"id": "mcp-gateway",
|
|
"object": "model",
|
|
"owned_by": "mcp-gateway"
|
|
}
|
|
]
|
|
}
|
|
```
|
|
|
|
### Step 3: Configure Open-UI
|
|
|
|
1. **Open Open-UI**: http://10.0.0.25:3009/
|
|
2. **Go to**: Admin → Settings → Connections
|
|
3. **Scroll to**: "Direct Connections"
|
|
4. **Enable**: Toggle "Direct Connections" ON
|
|
5. **Add Connection**:
|
|
- **API Base URL**: `https://mcp.wilddragon.net/v1`
|
|
- **API Key**: `rIoRseJSR9rqwl5bp4CEOyOUKdymaoJnAsT-y752BDi2qD9jJYbgd8sWkiQIGMtz`
|
|
6. **Click**: Save
|
|
|
|
### Step 4: Use in Open-UI
|
|
|
|
1. **Create a new chat**
|
|
2. **Model selection**: Choose `mcp-gateway`
|
|
3. **Start chatting** - The gateway will show available tools
|
|
|
|
## 🔑 Your Bearer Token
|
|
|
|
```
|
|
rIoRseJSR9rqwl5bp4CEOyOUKdymaoJnAsT-y752BDi2qD9jJYbgd8sWkiQIGMtz
|
|
```
|
|
|
|
Save this somewhere safe. It's what authenticates requests from Open-UI to your gateway.
|
|
|
|
## 🛠️ Running Both Systems
|
|
|
|
Your setup now runs:
|
|
|
|
```
|
|
┌─────────────────────────────────────────────┐
|
|
│ Your Workstation │
|
|
├─────────────────────────────────────────────┤
|
|
│ Claude.ai ──────────────┐ │
|
|
│ ▼ │
|
|
│ MCP Gateway │
|
|
│ (Port 4444) │
|
|
│ ▲ │
|
|
│ Open-UI ────────────────┘ │
|
|
│ (Port 3009) │
|
|
└─────────────────────────────────────────────┘
|
|
│
|
|
│ ERPNext, TrueNAS, Home Assistant, Wave
|
|
▼
|
|
(External services)
|
|
```
|
|
|
|
**Both Claude and Open-UI** can now:
|
|
- ✅ List all available MCP tools
|
|
- ✅ Call Wave Finance tools (invoices, customers, etc.)
|
|
- ✅ Execute TrueNAS commands (storage, snapshots, etc.)
|
|
- ✅ Control Home Assistant (lights, climate, etc.)
|
|
- ✅ Query ERPNext data
|
|
|
|
## 📝 API Endpoints Now Available
|
|
|
|
| Endpoint | Method | Purpose |
|
|
|----------|--------|---------|
|
|
| `/v1/models` | GET | List available models (returns `mcp-gateway`) |
|
|
| `/v1/chat/completions` | POST | OpenAI-compatible chat endpoint |
|
|
| `/mcp` | POST | Raw MCP protocol (for Claude) |
|
|
| `/health` | GET | Health check |
|
|
| `/status` | GET | Gateway status |
|
|
|
|
## 🔧 Advanced Configuration
|
|
|
|
### Using a Different Bearer Token
|
|
|
|
If you want to use a different token:
|
|
|
|
1. **Update `.env`** (if you want to persist it):
|
|
```bash
|
|
GATEWAY_API_TOKEN=your_new_token_here
|
|
```
|
|
|
|
2. **Restart gateway**:
|
|
```bash
|
|
docker compose restart mcp-gateway
|
|
```
|
|
|
|
### Enabling Tool Execution
|
|
|
|
Currently, the gateway shows available tools. To actually execute them:
|
|
|
|
1. Edit `gateway-proxy/openai_routes.py`
|
|
2. Uncomment the `_call_mcp_tool()` function calls
|
|
3. Add logic to process tool calls in the response
|
|
|
|
### Custom System Prompt
|
|
|
|
Edit `openai_routes.py` function `_get_mcp_tools()` to add a custom system prompt that guides the LLM on how to use tools.
|
|
|
|
## ⚠️ Troubleshooting
|
|
|
|
### "Connection refused" error
|
|
- **Check**: Is the gateway running? `docker compose ps`
|
|
- **Restart**: `docker compose restart mcp-gateway`
|
|
- **Check logs**: `docker compose logs mcp-gateway`
|
|
|
|
### "Unauthorized" error
|
|
- **Check**: Bearer token is correct
|
|
- **Check**: Header format: `Authorization: Bearer YOUR_TOKEN`
|
|
|
|
### No tools showing
|
|
- **Check**: Are MCP backends initialized? `docker compose logs mcp-erpnext`
|
|
- **Check**: Is `/mcp` endpoint working? Test with Claude.ai first
|
|
|
|
## ✨ Next: Production Hardening
|
|
|
|
When ready, consider:
|
|
|
|
1. **HTTPS certificates** - Use proper SSL/TLS
|
|
2. **Rate limiting** - Prevent API abuse
|
|
3. **Logging** - Monitor all requests
|
|
4. **Metrics** - Track usage patterns
|
|
5. **Tool execution** - Actually execute MCP tools, not just list them
|
|
|
|
## 📚 Files Modified
|
|
|
|
- `gateway-proxy/gateway_proxy.py` - Added OpenAI route imports and endpoints
|
|
- `gateway-proxy/openai_routes.py` - New file with OpenAI handlers
|
|
- `openai_adapter.py` - Optional adapter class
|
|
- `.` - This setup guide
|
|
|
|
## 🎯 You Now Have
|
|
|
|
✅ MCP Gateway with OAuth 2.1 (for Claude)
|
|
✅ OpenAI-compatible API (for Open-UI)
|
|
✅ All your tools accessible from both clients
|
|
✅ Bearer token authentication
|
|
✅ Production-ready architecture
|
|
|
|
Enjoy! 🚀
|