Skip to content

Commit 5d3c888

Browse files
committed
add docs
1 parent ffdc864 commit 5d3c888

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

CLAUDE.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,24 @@ From sessions:
130130
1. **StreamNative Cloud**: `--organization` + `--key-file`
131131
2. **External Kafka**: `--use-external-kafka` + Kafka params
132132
3. **External Pulsar**: `--use-external-pulsar` + Pulsar params
133+
4. **Multi-Session Pulsar** (SSE only): `--use-external-pulsar` + `--multi-session-pulsar`
133134

134135
Pre-configured context: `--pulsar-instance` + `--pulsar-cluster` disables context management tools.
135136

137+
### Multi-Session Pulsar Mode
138+
139+
When `--multi-session-pulsar` is enabled (SSE server with external Pulsar only):
140+
141+
- **No global PulsarSession**: Each request must provide its own token via `Authorization: Bearer <token>` header
142+
- **HTTP 401 on auth failure**: Requests without valid tokens are rejected with HTTP 401 Unauthorized
143+
- **Per-user session caching**: Sessions are cached using LRU with configurable size and TTL
144+
- **Session management**: See `pkg/mcp/session/pulsar_session_manager.go`
145+
146+
Key files:
147+
- `pkg/cmd/mcp/sse.go` - Auth middleware wraps SSEHandler()/MessageHandler()
148+
- `pkg/mcp/session/pulsar_session_manager.go` - LRU session cache with TTL cleanup
149+
- `pkg/cmd/mcp/server.go` - Skips global PulsarSession when multi-session enabled
150+
136151
## Error Handling
137152

138153
- Wrap errors: `fmt.Errorf("failed to X: %w", err)`

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,41 @@ snmcp sse --http-addr :9090 --http-path /mcp --use-external-pulsar --pulsar-web-
124124
docker run -i --rm -e SNMCP_ORGANIZATION=my-org -e SNMCP_KEY_FILE=/key.json -v /path/to/key-file.json:/key.json -p 9090:9090 streamnative/snmcp sse
125125
```
126126

127+
#### Multi-Session Pulsar Mode (SSE only)
128+
129+
When running the SSE server with external Pulsar, you can enable **multi-session mode** to support per-user authentication. In this mode, each HTTP request must include an `Authorization: Bearer <token>` header, and the server will create separate Pulsar sessions for each unique token.
130+
131+
```bash
132+
# Start SSE server with multi-session Pulsar mode
133+
snmcp sse --http-addr :9090 --http-path /mcp \
134+
--use-external-pulsar \
135+
--pulsar-web-service-url http://pulsar.example.com:8080 \
136+
--multi-session-pulsar \
137+
--session-cache-size 100 \
138+
--session-ttl-minutes 30
139+
```
140+
141+
**Key features:**
142+
- **Per-user sessions**: Each user's Pulsar token creates a separate session
143+
- **LRU caching**: Sessions are cached with LRU eviction when the cache is full
144+
- **TTL-based cleanup**: Idle sessions are automatically cleaned up after the configured TTL
145+
- **Strict authentication**: Requests without a valid `Authorization` header receive HTTP 401 Unauthorized
146+
147+
**Authentication flow:**
148+
1. Client connects to SSE endpoint with `Authorization: Bearer <pulsar-jwt-token>` header
149+
2. Server validates the token by attempting to create a Pulsar session
150+
3. If valid, the session is cached and reused for subsequent requests
151+
4. If invalid or missing, server returns HTTP 401 Unauthorized
152+
153+
**Configuration options:**
154+
| Flag | Default | Description |
155+
|------|---------|-------------|
156+
| `--multi-session-pulsar` | `false` | Enable per-user Pulsar sessions |
157+
| `--session-cache-size` | `100` | Maximum number of cached sessions |
158+
| `--session-ttl-minutes` | `30` | Session idle timeout before eviction |
159+
160+
> **Note:** Multi-session mode is only available for external Pulsar mode (`--use-external-pulsar`) and only works with the SSE server, not stdio.
161+
127162
### Command-line Options
128163

129164
```
@@ -175,6 +210,9 @@ Flags:
175210
--use-external-pulsar Use external Pulsar
176211
--http-addr string HTTP server address (default ":9090")
177212
--http-path string HTTP server path for SSE endpoint (default "/mcp")
213+
--multi-session-pulsar Enable per-user Pulsar sessions based on Authorization header tokens (only for external Pulsar mode)
214+
--session-cache-size int Maximum number of cached Pulsar sessions when multi-session is enabled (default 100)
215+
--session-ttl-minutes int Session TTL in minutes before eviction when multi-session is enabled (default 30)
178216
-v, --version version for snmcp
179217
```
180218

0 commit comments

Comments
 (0)