Skip to content

Commit 3dfe0f4

Browse files
committed
implementation of the mcp-auth endpoint
1 parent 9c8a7ff commit 3dfe0f4

16 files changed

Lines changed: 1268 additions & 7 deletions

File tree

README.md

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ The service includes comprehensive user data collection capabilities for various
3232
* [Llama Stack as separate server](#llama-stack-as-separate-server)
3333
* [MCP Server and Tool Configuration](#mcp-server-and-tool-configuration)
3434
* [Configuring MCP Servers](#configuring-mcp-servers)
35-
* [Configuring MCP Headers](#configuring-mcp-headers)
35+
* [Configuring MCP Server Authentication](#configuring-mcp-server-authentication)
3636
* [Llama Stack project and configuration](#llama-stack-project-and-configuration)
3737
* [Check connection to Llama Stack](#check-connection-to-llama-stack)
3838
* [Llama Stack as client library](#llama-stack-as-client-library)
@@ -363,7 +363,7 @@ mcp_servers:
363363
Authorization: "kubernetes" # Uses user's k8s token from request auth
364364
```
365365

366-
The user's Kubernetes token is extracted from the incoming request's `Authorization` header and forwarded to the MCP server.
366+
**Note:** Kubernetes token-based MCP authorization only works when Lightspeed Core Stack is configured with Kubernetes authentication (`authentication.k8s`). For any other authentication types, MCP servers configured with `Authorization: "kubernetes"` are removed from the available MCP servers list.
367367

368368
##### 3. Client-Provided Tokens (For Per-User Authentication)
369369

@@ -391,6 +391,34 @@ curl -X POST "http://localhost:8080/v1/query" \
391391

392392
**Structure**: `MCP-HEADERS: {"<server-name>": {"<header-name>": "<header-value>", ...}, ...}`
393393

394+
##### Client-Authenticated MCP Servers Discovery
395+
396+
To help clients determine which MCP servers require client-provided tokens, use the **MCP Client Auth Options** endpoint:
397+
398+
```bash
399+
GET /v1/mcp-auth/client-options
400+
```
401+
402+
**Response:**
403+
```json
404+
{
405+
"servers": [
406+
{
407+
"name": "user-specific-service",
408+
"client_auth_headers": ["Authorization", "X-User-Token"]
409+
},
410+
{
411+
"name": "github-integration",
412+
"client_auth_headers": ["Authorization"]
413+
}
414+
]
415+
}
416+
```
417+
418+
This endpoint returns only MCP servers configured with `authorization_headers: "client"`, along with the specific header names that need to be provided via `MCP-HEADERS`. Servers using file-based or Kubernetes authentication are not included in this response.
419+
420+
**Use case:** Clients can call this endpoint at startup or before making requests to discover which servers they can authenticate with using their own tokens.
421+
394422
##### Combining Authentication Methods
395423

396424
You can mix and match authentication methods across different MCP servers, and even combine multiple methods for a single server:
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
FROM python:3.12-slim
2+
3+
WORKDIR /app
4+
5+
# Copy the mock server script
6+
COPY dev-tools/mcp-mock-server/server.py .
7+
8+
# Expose HTTP port (we'll only use HTTP in Docker for simplicity)
9+
EXPOSE 3000
10+
11+
# Run the mock server (HTTP only on port 3000)
12+
CMD ["python", "server.py", "3000"]

docker-compose-library.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
services:
2+
# Mock MCP server for testing
3+
mcp-mock-server:
4+
build:
5+
context: .
6+
dockerfile: dev-tools/mcp-mock-server/Dockerfile
7+
container_name: mcp-mock-server
8+
ports:
9+
- "3000:3000"
10+
networks:
11+
- lightspeednet
12+
healthcheck:
13+
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
14+
interval: 5s
15+
timeout: 3s
16+
retries: 3
17+
start_period: 5s
18+
219
# Lightspeed Stack with embedded llama-stack (library mode)
320
lightspeed-stack:
421
build:
@@ -8,6 +25,11 @@ services:
825
container_name: lightspeed-stack
926
ports:
1027
- "8080:8080"
28+
depends_on:
29+
mcp-mock-server:
30+
condition: service_healthy
31+
networks:
32+
- lightspeednet
1133
volumes:
1234
# Mount both config files - lightspeed-stack.yaml should have library mode enabled
1335
- ./lightspeed-stack.yaml:/app-root/lightspeed-stack.yaml:Z
@@ -47,3 +69,6 @@ services:
4769
retries: 3 # how many times to retry before marking as unhealthy
4870
start_period: 15s # time to wait before starting checks (increased for library initialization)
4971

72+
networks:
73+
lightspeednet:
74+
driver: bridge

docker-compose.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,21 @@
11
services:
2+
# Mock MCP server for testing
3+
mcp-mock-server:
4+
build:
5+
context: .
6+
dockerfile: dev-tools/mcp-mock-server/Dockerfile
7+
container_name: mcp-mock-server
8+
ports:
9+
- "3000:3000"
10+
networks:
11+
- lightspeednet
12+
healthcheck:
13+
test: ["CMD", "curl", "-f", "http://localhost:3000/"]
14+
interval: 5s
15+
timeout: 3s
16+
retries: 3
17+
start_period: 5s
18+
219
# Red Hat llama-stack distribution with FAISS
320
llama-stack:
421
build:
@@ -62,6 +79,8 @@ services:
6279
depends_on:
6380
llama-stack:
6481
condition: service_healthy
82+
mcp-mock-server:
83+
condition: service_healthy
6584
networks:
6685
- lightspeednet
6786
healthcheck:

0 commit comments

Comments
 (0)