@casys/mcp-server 0.17.5 → 0.17.7
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 +38 -0
- package/mod.ts +1 -0
- package/package.json +3 -1
- package/src/auth/middleware.ts +28 -3
- package/src/mcp-app.ts +13 -4
- package/src/types.ts +13 -4
package/README.md
CHANGED
|
@@ -246,6 +246,44 @@ When auth is configured, the framework automatically exposes
|
|
|
246
246
|
`GET /.well-known/oauth-protected-resource` per
|
|
247
247
|
[RFC 9728](https://www.rfc-editor.org/rfc/rfc9728).
|
|
248
248
|
|
|
249
|
+
### DCR Discovery Proxy (RFC 8414 + RFC 7591)
|
|
250
|
+
|
|
251
|
+
IdPs without native Dynamic Client Registration (Zitadel, unconfigured
|
|
252
|
+
Keycloak, Okta free tier) don't publish `registration_endpoint` in their
|
|
253
|
+
AS metadata, so MCP clients like Claude.ai or Cursor can't auto-register.
|
|
254
|
+
|
|
255
|
+
`createAsMetadataHandler` is a framework-agnostic Web Standard handler
|
|
256
|
+
that proxies the upstream RFC 8414 metadata and injects a
|
|
257
|
+
`registration_endpoint` pointing to your own DCR proxy:
|
|
258
|
+
|
|
259
|
+
```typescript
|
|
260
|
+
// routes/.well-known/oauth-authorization-server.ts (Fresh example)
|
|
261
|
+
import { createAsMetadataHandler } from "@casys/mcp-server";
|
|
262
|
+
|
|
263
|
+
const handle = createAsMetadataHandler({
|
|
264
|
+
upstreamIssuer: "https://my-tenant.zitadel.cloud",
|
|
265
|
+
registrationEndpoint: "https://my-app.example.com/oauth/register",
|
|
266
|
+
// cacheTtlMs?: 24h default, stale-while-revalidate
|
|
267
|
+
// extraFields?: override scopes_supported, etc.
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
export const handler = { GET: (ctx) => handle(ctx.req) };
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
Then point the PRM at your own host so clients hit the enriched metadata:
|
|
274
|
+
|
|
275
|
+
```typescript
|
|
276
|
+
authorizationServers: ["https://my-app.example.com"],
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
The DCR endpoint itself (RFC 7591 `/oauth/register`) is out of scope —
|
|
280
|
+
mount it in your framework and forward to the IdP's admin API.
|
|
281
|
+
|
|
282
|
+
**Path caveat**: if the MCP server lives at `/mcp`, clients may build
|
|
283
|
+
the discovery URL as
|
|
284
|
+
`<host>/.well-known/oauth-authorization-server/mcp`. Mount the handler
|
|
285
|
+
at the exact path your PRM advertises.
|
|
286
|
+
|
|
249
287
|
### Observability
|
|
250
288
|
|
|
251
289
|
Every tool call emits an **OpenTelemetry span** with rich attributes:
|
package/mod.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@casys/mcp-server",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.7",
|
|
4
4
|
"description": "Production-ready MCP server framework with concurrency control, auth, and observability",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "mod.ts",
|
|
@@ -11,6 +11,8 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
14
|
+
"@modelcontextprotocol/ext-apps": "^1.7.1",
|
|
15
|
+
"@casys/mcp-compose": "^0.5.2",
|
|
14
16
|
"hono": "^4.0.0",
|
|
15
17
|
"ajv": "^8.17.1",
|
|
16
18
|
"jose": "^6.0.0",
|
package/src/auth/middleware.ts
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { AuthProvider } from "./provider.js";
|
|
11
|
+
import type { AuthInfo } from "./types.js";
|
|
11
12
|
import type { Middleware } from "../middleware/types.js";
|
|
12
13
|
import { isOtelEnabled, recordAuthEvent } from "../observability/otel.js";
|
|
13
14
|
|
|
@@ -105,6 +106,32 @@ export function createForbiddenResponse(requiredScopes: string[]): Response {
|
|
|
105
106
|
);
|
|
106
107
|
}
|
|
107
108
|
|
|
109
|
+
export function freezeAuthInfo(authInfo: AuthInfo): AuthInfo {
|
|
110
|
+
const scopes = Object.freeze([...authInfo.scopes]) as unknown as string[];
|
|
111
|
+
const frozen: AuthInfo = {
|
|
112
|
+
...authInfo,
|
|
113
|
+
scopes,
|
|
114
|
+
...(authInfo.claims
|
|
115
|
+
? {
|
|
116
|
+
claims: deepFreezeJson(structuredClone(authInfo.claims)) as Record<
|
|
117
|
+
string,
|
|
118
|
+
unknown
|
|
119
|
+
>,
|
|
120
|
+
}
|
|
121
|
+
: {}),
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
return Object.freeze(frozen);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function deepFreezeJson<T>(value: T): T {
|
|
128
|
+
if (typeof value !== "object" || value === null) return value;
|
|
129
|
+
for (const nested of Object.values(value)) {
|
|
130
|
+
deepFreezeJson(nested);
|
|
131
|
+
}
|
|
132
|
+
return Object.freeze(value);
|
|
133
|
+
}
|
|
134
|
+
|
|
108
135
|
/**
|
|
109
136
|
* Create an authentication middleware for the MCP pipeline.
|
|
110
137
|
*
|
|
@@ -165,9 +192,7 @@ export function createAuthMiddleware(provider: AuthProvider): Middleware {
|
|
|
165
192
|
}
|
|
166
193
|
|
|
167
194
|
// Deep-freeze authInfo to prevent mutation by downstream middlewares
|
|
168
|
-
|
|
169
|
-
if (authInfo.scopes) Object.freeze(authInfo.scopes);
|
|
170
|
-
ctx.authInfo = Object.freeze(authInfo);
|
|
195
|
+
ctx.authInfo = freezeAuthInfo(authInfo);
|
|
171
196
|
|
|
172
197
|
// Propagate resourceMetadataUrl for downstream middlewares (scope-middleware)
|
|
173
198
|
ctx.resourceMetadataUrl = metadataUrl;
|
package/src/mcp-app.ts
CHANGED
|
@@ -42,6 +42,7 @@ import {
|
|
|
42
42
|
createForbiddenResponse,
|
|
43
43
|
createUnauthorizedResponse,
|
|
44
44
|
extractBearerToken,
|
|
45
|
+
freezeAuthInfo,
|
|
45
46
|
} from "./auth/middleware.js";
|
|
46
47
|
import { createScopeMiddleware } from "./auth/scope-middleware.js";
|
|
47
48
|
import { createAuthProviderFromConfig, loadAuthConfig } from "./auth/config.js";
|
|
@@ -600,7 +601,14 @@ export class McpApp {
|
|
|
600
601
|
if (!tool) {
|
|
601
602
|
throw new Error(`Unknown tool: ${ctx.toolName}`);
|
|
602
603
|
}
|
|
603
|
-
return Promise.resolve(tool.handler(ctx.args
|
|
604
|
+
return Promise.resolve(tool.handler(ctx.args, {
|
|
605
|
+
toolName: ctx.toolName,
|
|
606
|
+
...(ctx.request ? { request: ctx.request } : {}),
|
|
607
|
+
...(typeof ctx.sessionId === "string"
|
|
608
|
+
? { sessionId: ctx.sessionId }
|
|
609
|
+
: {}),
|
|
610
|
+
...(ctx.authInfo ? { authInfo: ctx.authInfo as AuthInfo } : {}),
|
|
611
|
+
}));
|
|
604
612
|
});
|
|
605
613
|
}
|
|
606
614
|
|
|
@@ -1218,7 +1226,7 @@ export class McpApp {
|
|
|
1218
1226
|
};
|
|
1219
1227
|
}
|
|
1220
1228
|
|
|
1221
|
-
return { authInfo };
|
|
1229
|
+
return { authInfo: freezeAuthInfo(authInfo) };
|
|
1222
1230
|
};
|
|
1223
1231
|
|
|
1224
1232
|
const checkHttpRateLimit = async (
|
|
@@ -2177,8 +2185,9 @@ export class McpApp {
|
|
|
2177
2185
|
private buildToolListing(): Array<Record<string, unknown>> {
|
|
2178
2186
|
return Array.from(this.tools.values())
|
|
2179
2187
|
.filter((t) => {
|
|
2180
|
-
const vis = t._meta?.ui
|
|
2181
|
-
|
|
2188
|
+
const vis = (t._meta?.ui as { visibility?: unknown } | undefined)
|
|
2189
|
+
?.visibility;
|
|
2190
|
+
if (Array.isArray(vis) && !vis.includes("model")) return false;
|
|
2182
2191
|
return true;
|
|
2183
2192
|
})
|
|
2184
2193
|
.map((t) => {
|
package/src/types.ts
CHANGED
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* @module lib/server/types
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import type { McpUiToolMeta as McpUiToolMetaBase } from "@
|
|
10
|
+
import type { McpUiToolMeta as McpUiToolMetaBase } from "@modelcontextprotocol/ext-apps";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Rate limit configuration
|
|
@@ -141,9 +141,10 @@ export interface McpAppOptions {
|
|
|
141
141
|
/**
|
|
142
142
|
* MCP Apps UI metadata for tools (SEP-1865 + PML extensions)
|
|
143
143
|
*
|
|
144
|
-
* Extends the base `McpUiToolMeta` from
|
|
145
|
-
* PML-specific `emits`/`accepts`
|
|
146
|
-
*
|
|
144
|
+
* Extends the base `McpUiToolMeta` from `@modelcontextprotocol/ext-apps`
|
|
145
|
+
* (the official MCP Apps contract) with PML-specific `emits`/`accepts`
|
|
146
|
+
* fields for cross-UI sync rules. The server narrows/extends the spec type;
|
|
147
|
+
* the contract itself is owned upstream by the protocol, not by this repo.
|
|
147
148
|
*
|
|
148
149
|
* @example
|
|
149
150
|
* ```typescript
|
|
@@ -439,8 +440,16 @@ export interface MCPTool {
|
|
|
439
440
|
* };
|
|
440
441
|
* ```
|
|
441
442
|
*/
|
|
443
|
+
export interface ToolHandlerContext {
|
|
444
|
+
readonly toolName: string;
|
|
445
|
+
readonly request?: Request;
|
|
446
|
+
readonly sessionId?: string;
|
|
447
|
+
readonly authInfo?: import("./auth/types.js").AuthInfo;
|
|
448
|
+
}
|
|
449
|
+
|
|
442
450
|
export type ToolHandler = (
|
|
443
451
|
args: Record<string, unknown>,
|
|
452
|
+
ctx?: ToolHandlerContext,
|
|
444
453
|
) => Promise<unknown> | unknown;
|
|
445
454
|
|
|
446
455
|
/**
|