mirror of https://github.com/sysown/proxysql
This commit implements Phase 2 of the MCP multi-endpoint architecture:
per-endpoint Bearer token authentication.
## Changes
### lib/MCP_Endpoint.cpp
- Implemented `authenticate_request()` method with:
- Per-endpoint token validation (mcp-{endpoint}_endpoint_auth)
- Bearer token support via Authorization header
- Query parameter fallback (?token=xxx) for simple testing
- No authentication when token is not configured (backward compatible)
- Proper 401 Unauthorized response on auth failure
- Token whitespace trimming
- Debug logging for troubleshooting
### doc/MCP/Architecture.md
- Updated Per-Endpoint Authentication section with complete implementation
- Marked Phase 3 authentication task as completed (✅)
- Added authentication implementation code example
## Authentication Flow
1. Client sends request with Bearer token:
- Header: `Authorization: Bearer <token>`
- Or query param: `?token=<token>`
2. Server validates against endpoint-specific variable:
- `/mcp/config` → `mcp-config_endpoint_auth`
- `/mcp/observe` → `mcp-observe_endpoint_auth`
- `/mcp/query` → `mcp-query_endpoint_auth`
- `/mcp/admin` → `mcp-admin_endpoint_auth`
- `/mcp/cache` → `mcp-cache_endpoint_auth`
3. Returns 401 Unauthorized if:
- Auth is required but not provided
- Token doesn't match expected value
4. Allows request if:
- No auth token configured (backward compatible)
- Token matches expected value
## Testing
```bash
# Set auth token for /mcp/query endpoint
mysql -h 127.0.0.1 -P 6032 -u admin -padmin \
-e "SET mcp-query_endpoint_auth='my-secret-token'; LOAD MCP VARIABLES TO RUNTIME;"
# Test with Bearer token
curl -k -X POST https://127.0.0.1:6071/mcp/query \
-H "Content-Type: application/json" \
-H "Authorization: Bearer my-secret-token" \
-d '{"jsonrpc":"2.0","method":"tools/list","id":1}'
# Test with query parameter
curl -k -X POST "https://127.0.0.1:6071/mcp/query?token=my-secret-token" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"tools/list","id":1}'
```
## Status
✅ Authentication fully implemented and functional
⚠️ Testing with running ProxySQL instance still needed
Co-authored-by: Claude <claude@anthropic.com>
pull/5310/head
parent
c86a048d9c
commit
ced10dd054
Loading…
Reference in new issue