@abgov/adsp-sdk-mcp-server 1.36.0 → 1.38.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -114,16 +114,28 @@ Add it to your MCP client's server config, run via `npx`:
114
114
  ### HTTP transport
115
115
 
116
116
  To host the server instead of running it per user, start it with `MCP_TRANSPORT=http`. It serves Streamable HTTP
117
- at `POST /mcp`, with a liveness check at `GET /health` and a readiness check at `GET /ready`.
117
+ on two endpoints, with a liveness check at `GET /health` and a readiness check at `GET /ready`:
118
+
119
+ | Endpoint | Sign-in | Tools |
120
+ |---|---|---|
121
+ | `POST /mcp` | Never asked for; a token sent here is ignored | The 10 tools that answer from bundled content. `list_service_roles` and `get_service_configuration_schema` aren't listed, and calling them answers with an error saying to sign in at `/mcp/<tenant realm>` |
122
+ | `POST /mcp/<tenant realm>` | Required for that tenant realm (see [Signing in](#signing-in)) | All 12 |
123
+
124
+ Without the three sign-in settings below, the server serves only `/mcp`. There is no way to call the live tools
125
+ without signing in: anyone who can't sign in, and needs them, runs the server locally over stdio, as in
126
+ [Usage](#usage).
118
127
 
119
128
  | Variable | Default | Purpose |
120
129
  |---|---|---|
121
130
  | `MCP_TRANSPORT` | `stdio` | `http` to serve HTTP |
122
131
  | `PORT` | `3000` | Port to listen on |
123
- | `CORS_ORIGIN` | unset | Comma-separated browser origins allowed to call `/mcp`, for example `https://a.example,https://b.example`. Unset allows none; `*` allows any (not for hosted use) |
124
- | `MCP_MAX_IN_FLIGHT` | `64` | `POST /mcp` requests handled at once per process |
132
+ | `MCP_PUBLIC_URL` | unset | The server's external base URL, for example `https://adsp-sdk-mcp.example`. Used in the sign-in metadata and the `WWW-Authenticate` header, never taken from request headers |
133
+ | `ADSP_ACCESS_SERVICE_URL` | unset | Keycloak base URL. A realm's issuer is `<url>/auth/realms/<realm>` and its signing keys are read from there |
134
+ | `ADSP_DIRECTORY_SERVICE_URL` | unset | Directory service the live tools use to find ADSP services. Set all three sign-in settings to serve `/mcp/<tenant realm>` |
135
+ | `CORS_ORIGIN` | unset | Comma-separated browser origins allowed to call `/mcp` and `/mcp/<tenant realm>`, for example `https://a.example,https://b.example`. Unset allows none; `*` allows any (not for hosted use) |
136
+ | `MCP_MAX_IN_FLIGHT` | `64` | Requests handled at once per process, on each endpoint: `POST /mcp`, and signed-in `POST /mcp/<tenant realm>`. Each endpoint has its own slots, so requests without a token can't take the ones signed-in callers need |
125
137
  | `MCP_IN_FLIGHT_WAIT_MS` | `1000` | How long a request waits for a free slot before getting `503`. Also how long a live tool waits for a free upstream slot |
126
- | `MCP_RATE_LIMIT_PER_MINUTE` | `1200` | `POST /mcp` requests allowed per client IP per minute, per process. `0` turns the limit off |
138
+ | `MCP_RATE_LIMIT_PER_MINUTE` | `1200` | `POST /mcp` and `POST /mcp/<tenant realm>` requests allowed per client IP per minute, per process, counted together. `0` turns the limit off |
127
139
  | `MCP_LIVE_TOOL_MAX_CONCURRENT` | `8` | Live-tool calls to ADSP running at once per process, across both live tools |
128
140
  | `MCP_SHUTDOWN_DELAY_MS` | `5000` | After a shutdown signal, how long to keep serving with `/ready` failing, so the router stops sending traffic first |
129
141
  | `MCP_SHUTDOWN_TIMEOUT_MS` | `30000` | Hard deadline from the signal to exit, even if a request is still running. Must be longer than the delay |
@@ -131,16 +143,64 @@ at `POST /mcp`, with a liveness check at `GET /health` and a readiness check at
131
143
  | `OTEL_EXPORTER_OTLP_ENDPOINT` | unset | OTLP/HTTP collector base URL. When set, metrics are exported to `<endpoint>/v1/metrics` |
132
144
  | `OTEL_METRIC_EXPORT_INTERVAL` | `60000` | Metric export interval, in milliseconds |
133
145
 
134
- An invalid value for one of the `MCP_*` numbers, or `*` mixed with origins in `CORS_ORIGIN`, stops the server at
146
+ An invalid value for one of the `MCP_*` numbers, `*` mixed with origins in `CORS_ORIGIN`, some but not all of the
147
+ three sign-in settings, or a sign-in URL that isn't `https` (plain `http` is allowed only for `localhost` and `127.0.0.1`) stops the server at
135
148
  startup with an error naming the variable.
136
149
 
137
- HTTP mode is stateless: each `POST /mcp` gets its own MCP server, the response is JSON (the server never streams),
138
- and nothing is kept between requests. The response carries no `Mcp-Session-Id`, so any replica can serve any request
139
- and an idle client never loses its session. `GET /mcp` and `DELETE /mcp` return `405` with `Allow: POST`, because
140
- there is no stream to open and no session to delete.
150
+ HTTP mode is stateless: each `POST` to either endpoint gets its own MCP server, the response is JSON (the server
151
+ never streams), and nothing is kept between requests. The response carries no `Mcp-Session-Id`, so any replica can
152
+ serve any request and an idle client never loses its session. `GET` and `DELETE` on both endpoints return
153
+ `405` with `Allow: POST`, because there is no stream to open and no session to delete.
141
154
 
142
155
  `SESSION_TTL_MINUTES` has been removed and is ignored: there are no sessions to expire.
143
156
 
157
+ #### Signing in
158
+
159
+ `/mcp/<tenant realm>` is an OAuth protected resource; plain `/mcp` never asks for a sign-in.
160
+ Each tenant realm is its own authorization server, so the realm is part of the URL: a client connects to
161
+ `<MCP_PUBLIC_URL>/mcp/<tenant realm>` and signs in to that realm with the public client `adsp-mcp` (PKCE, no secret).
162
+
163
+ - A request without a token gets `401` with
164
+ `WWW-Authenticate: Bearer resource_metadata="<MCP_PUBLIC_URL>/.well-known/oauth-protected-resource/mcp/<realm>"`.
165
+ That document ([RFC 9728](https://www.rfc-editor.org/rfc/rfc9728)) names the realm as the only authorization
166
+ server, and the client finds Keycloak through `<issuer>/.well-known/openid-configuration`.
167
+ - A token is accepted only if it is signed by that realm (RS256), its issuer is exactly
168
+ `<ADSP_ACCESS_SERVICE_URL>/auth/realms/<realm>`, its audience includes `urn:ads:platform:adsp-sdk-mcp-server`, and
169
+ it hasn't expired (30 s clock tolerance). Anything else gets `401` with `error="invalid_token"`. A realm's token is
170
+ never accepted on another realm's URL.
171
+ - The server keeps no secret. It verifies tokens with each realm's public signing keys, refreshed after 10 minutes.
172
+ A token with a key id the server hasn't seen triggers a refresh at most once every 30 s, so rotated keys are
173
+ picked up and junk key ids can't drive traffic. If a refresh fails, the realm keeps working with its last keys.
174
+ - If a realm's keys have never been fetched and can't be within 5 s, requests for that realm get `503` with
175
+ `Retry-After` for the next 60 s. A realm that doesn't exist looks the same to the server, so a mistyped realm in the
176
+ URL also gets `503`. Key fetches are capped at 20 a minute across all realms per process, so made-up realm names
177
+ can't make the server send unbounded traffic to Keycloak, and they never push out a realm whose keys are known.
178
+ After a restart, each replica can therefore start verifying at most 20 new realms a minute.
179
+ - Every request is checked on its own token, and nothing from one request is kept for the next. Tokens are never
180
+ logged or written to disk.
181
+
182
+ The live tools (`list_service_roles` and `get_service_configuration_schema`) call ADSP **as the signed-in caller**,
183
+ with the caller's token and `ADSP_DIRECTORY_SERVICE_URL`. The host needs no `adsp-cli` login, `ADSP_CLIENT_ID` or
184
+ `ADSP_CLIENT_SECRET`. If ADSP rejects the token, the tool answers "Your sign-in was rejected or has expired. Sign in
185
+ again from your MCP client." The tool descriptions still mention `adsp-cli login`, which applies only to stdio.
186
+
187
+ A realm can sign in only if it has the `adsp-mcp` client. New tenant realms get it when they're created; existing
188
+ realms need it added.
189
+
190
+ Connecting each supported client, with `<url>` standing for `<MCP_PUBLIC_URL>/mcp/<tenant realm>`:
191
+
192
+ - **Claude Code:** `claude mcp add --transport http --client-id adsp-mcp --callback-port 33419 adsp-sdk <url>`, then
193
+ `/mcp` in Claude Code to sign in. Without `--callback-port` it picks a random port that isn't registered.
194
+ - **VS Code (GitHub Copilot):** add the server as type `http` with `<url>`. When VS Code says the server doesn't
195
+ support dynamic client registration, enter `adsp-mcp` as the client id and leave the secret empty. VS Code
196
+ receives the sign-in on port 33418, which must be free.
197
+ - **Cursor:** in `mcp.json`, `"adsp-sdk": { "url": "<url>", "auth": { "CLIENT_ID": "adsp-mcp" } }`.
198
+ - **MCP Inspector:** transport Streamable HTTP, URL `<url>`, and client id `adsp-mcp` in the authentication settings.
199
+
200
+ Known client issues reported upstream: some Claude Code versions store `--client-id` under the wrong key, VS Code
201
+ fails to sign in when port 33418 is busy, and Cursor's redirect has changed between versions. If sign-in fails with
202
+ a redirect error, the client's redirect is probably not one the `adsp-mcp` client allows.
203
+
144
204
  #### Health and shutdown
145
205
 
146
206
  - `GET /health` is liveness: it answers `200` while the process is up, including during the shutdown delay, so a pod
@@ -161,16 +221,20 @@ than it takes the router to stop sending traffic to a pod that fails readiness.
161
221
 
162
222
  #### Overload guards
163
223
 
164
- `POST /mcp` passes these checks in order. `GET /health` skips all of them. Every rejection is a JSON-RPC error body
165
- (`code: -32000`) and is counted in `mcp.requests.rejected`.
224
+ `POST /mcp` and `POST /mcp/<tenant realm>` pass these checks in order, and `POST /mcp` skips the sign-in step.
225
+ `GET /health` skips all of them. Every rejection is a
226
+ JSON-RPC error body (`code: -32000`) and is counted in `mcp.requests.rejected`.
166
227
 
167
228
  1. **Origin.** A request with an `Origin` header not in `CORS_ORIGIN` gets `403` (`Origin not allowed`), as the MCP
168
229
  specification requires. `Origin: null` is never allowed. A request without an `Origin` header, which is what
169
230
  non-browser clients such as agent-service and the MCP SDK send, passes. `Access-Control-Allow-Origin` is sent only
170
231
  for an allowed origin.
171
232
  2. **Rate limit.** Over `MCP_RATE_LIMIT_PER_MINUTE` from one client IP, a request gets `429` with `Retry-After`
172
- (`Rate limit exceeded`).
173
- 3. **In-flight cap.** With `MCP_MAX_IN_FLIGHT` requests already running, a request waits up to
233
+ (`Rate limit exceeded`). This runs before sign-in, so requests with bad tokens count too.
234
+ 3. **Sign-in.** A realm name that isn't letters, digits, `-` and `_` (up to 64) gets `404`, a missing or invalid
235
+ token `401`, and unavailable signing keys `503` (see [Signing in](#signing-in)). Requests that fail here never take
236
+ an in-flight slot.
237
+ 4. **In-flight cap.** With `MCP_MAX_IN_FLIGHT` requests already running on the same endpoint, a request waits up to
174
238
  `MCP_IN_FLIGHT_WAIT_MS` for a slot, so a short burst completes. A request still waiting after that, or arriving
175
239
  when as many requests are already waiting as `MCP_MAX_IN_FLIGHT`, gets `503` with `Retry-After: 1`
176
240
  (`Server busy`). Requests already running are never affected. A request is admitted before its body arrives, so
@@ -185,10 +249,10 @@ place and never calls ADSP. This applies in stdio mode too.
185
249
  Things to know when sizing and tuning these:
186
250
 
187
251
  - **The limits are per process.** With N replicas, the cluster takes about N times each limit.
188
- - **The rate limit is per client IP until authentication is added.** Every agent-service pod is then one client, and
189
- so is any group of users behind one NAT or proxy. Connecting and calling one tool is 3 `POST`s, so the default
190
- allows about 400 such client sessions a minute from one IP. Retune it once the deployment shows which client IPs
191
- reach the pod.
252
+ - **The rate limit is per client IP, not per signed-in user,** because it runs before the token is checked. Every
253
+ agent-service pod is one client, and so is any group of users behind one NAT or proxy. Connecting and calling one
254
+ tool is 3 `POST`s, so the default allows about 400 such client sessions a minute from one IP. Retune it once the
255
+ deployment shows which client IPs reach the pod.
192
256
  - **Clients don't retry.** Measured locally with `MCP_MAX_IN_FLIGHT=2` and both slots held:
193
257
 
194
258
  | Client | Over the cap for longer than `MCP_IN_FLIGHT_WAIT_MS` | Over the cap briefly (`MCP_IN_FLIGHT_WAIT_MS=3000`, slots freed after 0.5 s) |
@@ -207,9 +271,9 @@ OpenTelemetry SDK isn't loaded. Stdio mode never exports metrics.
207
271
 
208
272
  | Name | Kind | Unit | Labels | Meaning |
209
273
  |---|---|---|---|---|
210
- | `mcp.requests.in_flight` | UpDownCounter | `{request}` | none | `POST /mcp` requests admitted by the in-flight cap and not yet answered (waiting requests aren't counted) |
211
- | `mcp.requests.rejected` | Counter | `{request}` | `reason` | Requests or tool calls refused by an overload guard |
212
- | `mcp.request.duration` | Histogram | `s` | `mcp.method.name`, and `http.response.status_code` or `error.type=aborted` | Time to answer a `POST /mcp` request, or until the client disconnected |
274
+ | `mcp.requests.in_flight` | UpDownCounter | `{request}` | none | `POST /mcp` and `POST /mcp/<tenant realm>` requests admitted by the in-flight cap and not yet answered (waiting requests aren't counted) |
275
+ | `mcp.requests.rejected` | Counter | `{request}` | `reason` | Requests or tool calls refused by an overload guard or by sign-in |
276
+ | `mcp.request.duration` | Histogram | `s` | `mcp.method.name`, and `http.response.status_code` or `error.type=aborted` | Time to answer a `POST /mcp` request, or a `POST /mcp/<tenant realm>` request that passed sign-in, or until the client disconnected |
213
277
  | `mcp.tool.duration` | Histogram | `s` | `mcp.tool.name`, `error.type` (absent on success) | Time to run a tool call |
214
278
  | `mcp.live_tool.upstream.errors` | Counter | `{error}` | `mcp.tool.name`, `error.type` | Failed ADSP calls from `list_service_roles` and `get_service_configuration_schema` |
215
279
  | `nodejs.eventloop.delay.p50`, `.p99`, `.max` | Gauge | `s` | none | Event-loop delay since the previous export |
@@ -219,7 +283,7 @@ OpenTelemetry SDK isn't loaded. Stdio mode never exports metrics.
219
283
 
220
284
  Every label takes a value from a fixed set:
221
285
 
222
- - `mcp.tool.name`: one of the eleven tool names, or `unknown` for any name the server doesn't have.
286
+ - `mcp.tool.name`: one of the twelve tool names, or `unknown` for any name the server doesn't have.
223
287
  - `mcp.method.name`: an MCP method such as `initialize`, `tools/list` or `tools/call`; `other` for any other method;
224
288
  `batch` for a JSON-RPC batch; `unparsed` when the body wasn't valid JSON-RPC or was too large.
225
289
  - `error.type` on `mcp.request.duration`: `aborted` when the client disconnected before the response was written; the
@@ -229,7 +293,9 @@ Every label takes a value from a fixed set:
229
293
  - `error.type` on `mcp.live_tool.upstream.errors`: `http_4xx`, `http_5xx`, `network`, `not_in_directory`,
230
294
  `not_authenticated` or `other`. `not_authenticated` covers both a missing `adsp-cli` login and a failed token
231
295
  request, which `adsp-cli` reports the same way.
232
- - `reason` on `mcp.requests.rejected`: `in_flight_cap`, `rate_limit`, `origin` or `live_tool_cap`.
296
+ - `reason` on `mcp.requests.rejected`: `in_flight_cap`, `rate_limit`, `origin`, `live_tool_cap`, `auth` (a `401`
297
+ for an invalid token; a request with no token isn't counted, because every client's first request has none) or
298
+ `auth_unavailable` (a `503` because a realm's signing keys couldn't be fetched).
233
299
 
234
300
  ### Using the live tools
235
301