@casys/mcp-server 0.22.0 → 0.23.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 +11 -12
- package/mod.ts +46 -0
- package/package.json +1 -1
- package/src/auth/middleware.ts +36 -7
- package/src/client-auth/token-store/memory-store.ts +11 -6
- package/src/mcp-app.ts +2137 -98
- package/src/middleware/types.ts +33 -0
- package/src/mrtr/capability-check.ts +303 -0
- package/src/mrtr/mod.ts +39 -0
- package/src/mrtr/request-state.ts +435 -0
- package/src/mrtr/types.ts +93 -0
- package/src/subscriptions/subscription-registry.ts +558 -0
- package/src/tasks/mod.ts +33 -0
- package/src/tasks/task-store.ts +1014 -0
- package/src/transport/request-headers.ts +661 -0
- package/src/types.ts +132 -1
package/README.md
CHANGED
|
@@ -248,13 +248,13 @@ When auth is configured, the framework automatically exposes
|
|
|
248
248
|
|
|
249
249
|
### DCR Discovery Proxy (RFC 8414 + RFC 7591)
|
|
250
250
|
|
|
251
|
-
IdPs without native Dynamic Client Registration (Zitadel, unconfigured
|
|
252
|
-
|
|
253
|
-
|
|
251
|
+
IdPs without native Dynamic Client Registration (Zitadel, unconfigured Keycloak,
|
|
252
|
+
Okta free tier) don't publish `registration_endpoint` in their AS metadata, so
|
|
253
|
+
MCP clients like Claude.ai or Cursor can't auto-register.
|
|
254
254
|
|
|
255
|
-
`createAsMetadataHandler` is a framework-agnostic Web Standard handler
|
|
256
|
-
|
|
257
|
-
|
|
255
|
+
`createAsMetadataHandler` is a framework-agnostic Web Standard handler that
|
|
256
|
+
proxies the upstream RFC 8414 metadata and injects a `registration_endpoint`
|
|
257
|
+
pointing to your own DCR proxy:
|
|
258
258
|
|
|
259
259
|
```typescript
|
|
260
260
|
// routes/.well-known/oauth-authorization-server.ts (Fresh example)
|
|
@@ -276,13 +276,12 @@ Then point the PRM at your own host so clients hit the enriched metadata:
|
|
|
276
276
|
authorizationServers: ["https://my-app.example.com"],
|
|
277
277
|
```
|
|
278
278
|
|
|
279
|
-
The DCR endpoint itself (RFC 7591 `/oauth/register`) is out of scope —
|
|
280
|
-
|
|
279
|
+
The DCR endpoint itself (RFC 7591 `/oauth/register`) is out of scope — mount it
|
|
280
|
+
in your framework and forward to the IdP's admin API.
|
|
281
281
|
|
|
282
|
-
**Path caveat**: if the MCP server lives at `/mcp`, clients may build
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
at the exact path your PRM advertises.
|
|
282
|
+
**Path caveat**: if the MCP server lives at `/mcp`, clients may build the
|
|
283
|
+
discovery URL as `<host>/.well-known/oauth-authorization-server/mcp`. Mount the
|
|
284
|
+
handler at the exact path your PRM advertises.
|
|
286
285
|
|
|
287
286
|
### Observability
|
|
288
287
|
|
package/mod.ts
CHANGED
|
@@ -252,3 +252,49 @@ export type {
|
|
|
252
252
|
// Inspector — launch the MCP Inspector for interactive debugging
|
|
253
253
|
export { launchInspector } from "./src/inspector/launcher.js";
|
|
254
254
|
export type { InspectorOptions } from "./src/inspector/launcher.js";
|
|
255
|
+
|
|
256
|
+
// ── Spec 2026-07-28 features ─────────────────────────────────────────────────
|
|
257
|
+
|
|
258
|
+
// Tasks extension (io.modelcontextprotocol/tasks, SEP-2663).
|
|
259
|
+
//
|
|
260
|
+
// `createTask` is what a tool handler returns to opt into async-task mode, so it
|
|
261
|
+
// has to be reachable from the package root — without it the extension is wired
|
|
262
|
+
// but unusable by any consumer.
|
|
263
|
+
export { createTask } from "./src/tasks/mod.js";
|
|
264
|
+
export type {
|
|
265
|
+
AsyncTaskDescriptor,
|
|
266
|
+
DetailedTask,
|
|
267
|
+
Task,
|
|
268
|
+
TaskController,
|
|
269
|
+
TaskStoreOptions,
|
|
270
|
+
} from "./src/tasks/mod.js";
|
|
271
|
+
|
|
272
|
+
// MRTR — Multi Round-Trip Requests (SEP-2322).
|
|
273
|
+
//
|
|
274
|
+
// `InputRequiredSignal` is the shape a handler returns to ask the client for
|
|
275
|
+
// input. The seal/verify primitives are exported for consumers implementing their
|
|
276
|
+
// own transport; the framework seals automatically on `tools/call`.
|
|
277
|
+
export type {
|
|
278
|
+
InputRequestEntry,
|
|
279
|
+
InputRequestMethod,
|
|
280
|
+
InputRequiredSignal,
|
|
281
|
+
MrtrOptions,
|
|
282
|
+
} from "./src/mrtr/mod.js";
|
|
283
|
+
export {
|
|
284
|
+
exportStateKey,
|
|
285
|
+
generateStateKey,
|
|
286
|
+
sealRequestState,
|
|
287
|
+
verifyRequestState,
|
|
288
|
+
} from "./src/mrtr/mod.js";
|
|
289
|
+
|
|
290
|
+
// subscriptions/listen (SEP-2575).
|
|
291
|
+
//
|
|
292
|
+
// The registry is owned by McpApp; these are exported for consumers driving their
|
|
293
|
+
// own streams, and for the filter type used when narrowing what a deployment
|
|
294
|
+
// delivers.
|
|
295
|
+
export { SubscriptionRegistry } from "./src/subscriptions/subscription-registry.js";
|
|
296
|
+
export type {
|
|
297
|
+
SubscriptionFilter,
|
|
298
|
+
SubscriptionRegistryOptions,
|
|
299
|
+
SubscriptionSink,
|
|
300
|
+
} from "./src/subscriptions/subscription-registry.js";
|
package/package.json
CHANGED
package/src/auth/middleware.ts
CHANGED
|
@@ -12,7 +12,31 @@ import type { AuthInfo } from "./types.js";
|
|
|
12
12
|
import type { Middleware } from "../middleware/types.js";
|
|
13
13
|
import { isOtelEnabled, recordAuthEvent } from "../observability/otel.js";
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
// ── Auth error codes ────────────────────────────────────────────────────────
|
|
16
|
+
//
|
|
17
|
+
// Both codes moved OUT of the JSON-RPC reserved range (`-32768`..`-32000`) for
|
|
18
|
+
// spec 2026-07-28, which is stricter than earlier readings of it suggested:
|
|
19
|
+
//
|
|
20
|
+
// * `-32002` — "Implementations of this protocol version **MUST NOT** emit
|
|
21
|
+
// these codes", because 2025-11-25 and earlier used it for resource-not-found
|
|
22
|
+
// (now `-32602`). Keeping it for 403 was a conformance violation, not a
|
|
23
|
+
// grandfathered liberty. Two prior reviews, including one of this file, read
|
|
24
|
+
// the allocation policy as permitting it. It does not.
|
|
25
|
+
// * `-32001` — inside `-32000`..`-32019`, where "new implementations
|
|
26
|
+
// **SHOULD NOT** use codes from this sub-range at all" and receivers "**MUST
|
|
27
|
+
// NOT** assume any specific meaning".
|
|
28
|
+
//
|
|
29
|
+
// The spec's own guidance for codes it does not define: "**SHOULD** be allocated
|
|
30
|
+
// outside the JSON-RPC reserved range". Hence `-31401` / `-31403`, mnemonic for
|
|
31
|
+
// the HTTP statuses they accompany.
|
|
32
|
+
//
|
|
33
|
+
// BREAKING for anything matching on the old numbers — see the changelog.
|
|
34
|
+
|
|
35
|
+
/** 401 Unauthorized: no token, or an invalid one. */
|
|
36
|
+
export const JSONRPC_UNAUTHORIZED = -31401;
|
|
37
|
+
|
|
38
|
+
/** 403 Forbidden: authenticated, but missing a required scope. */
|
|
39
|
+
export const JSONRPC_FORBIDDEN = -31403;
|
|
16
40
|
|
|
17
41
|
function escapeAuthenticateParam(s: string): string {
|
|
18
42
|
return s.replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
@@ -68,7 +92,9 @@ export function createUnauthorizedResponse(
|
|
|
68
92
|
errorDescription?: string,
|
|
69
93
|
): Response {
|
|
70
94
|
const parts = [
|
|
71
|
-
`Bearer resource_metadata="${
|
|
95
|
+
`Bearer resource_metadata="${
|
|
96
|
+
escapeAuthenticateParam(resourceMetadataUrl)
|
|
97
|
+
}"`,
|
|
72
98
|
];
|
|
73
99
|
if (error) parts.push(`error="${escapeAuthenticateParam(error)}"`);
|
|
74
100
|
if (errorDescription) {
|
|
@@ -81,7 +107,10 @@ export function createUnauthorizedResponse(
|
|
|
81
107
|
JSON.stringify({
|
|
82
108
|
jsonrpc: "2.0",
|
|
83
109
|
id: null,
|
|
84
|
-
error: {
|
|
110
|
+
error: {
|
|
111
|
+
code: JSONRPC_UNAUTHORIZED,
|
|
112
|
+
message: errorDescription ?? "Unauthorized",
|
|
113
|
+
},
|
|
85
114
|
}),
|
|
86
115
|
{
|
|
87
116
|
status: 401,
|
|
@@ -105,11 +134,11 @@ export function createForbiddenResponse(
|
|
|
105
134
|
): Response {
|
|
106
135
|
const requiredScopesDescription = requiredScopes.join(", ");
|
|
107
136
|
const parts = [
|
|
108
|
-
`Bearer resource_metadata="${
|
|
109
|
-
|
|
110
|
-
`error_description="${
|
|
111
|
-
escapeAuthenticateParam(requiredScopesDescription)
|
|
137
|
+
`Bearer resource_metadata="${
|
|
138
|
+
escapeAuthenticateParam(resourceMetadataUrl)
|
|
112
139
|
}"`,
|
|
140
|
+
`error="insufficient_scope"`,
|
|
141
|
+
`error_description="${escapeAuthenticateParam(requiredScopesDescription)}"`,
|
|
113
142
|
];
|
|
114
143
|
|
|
115
144
|
return new Response(
|
|
@@ -9,19 +9,24 @@ import type { StoredCredentials, TokenStore } from "../types.js";
|
|
|
9
9
|
export class MemoryTokenStore implements TokenStore {
|
|
10
10
|
private store = new Map<string, StoredCredentials>();
|
|
11
11
|
|
|
12
|
-
async
|
|
13
|
-
|
|
12
|
+
// Not `async`: the Map operations are synchronous. The interface returns
|
|
13
|
+
// Promises so a real store can be I/O-backed; `Promise.resolve` satisfies it
|
|
14
|
+
// without claiming an await point that does not exist.
|
|
15
|
+
get(serverUrl: string): Promise<StoredCredentials | null> {
|
|
16
|
+
return Promise.resolve(this.store.get(serverUrl) ?? null);
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
set(serverUrl: string, credentials: StoredCredentials): Promise<void> {
|
|
17
20
|
this.store.set(serverUrl, credentials);
|
|
21
|
+
return Promise.resolve();
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
|
|
24
|
+
delete(serverUrl: string): Promise<void> {
|
|
21
25
|
this.store.delete(serverUrl);
|
|
26
|
+
return Promise.resolve();
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
return [...this.store.keys()];
|
|
29
|
+
list(): Promise<string[]> {
|
|
30
|
+
return Promise.resolve([...this.store.keys()]);
|
|
26
31
|
}
|
|
27
32
|
}
|