@casys/mcp-server 0.17.4 → 0.17.6
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/casys-mcp-server-0.17.6.tgz +0 -0
- package/mod.ts +1 -0
- package/package.json +2 -1
- package/src/auth/jwt-provider.ts +5 -1
- package/src/auth/middleware.ts +28 -3
- package/src/mcp-app.ts +13 -4
- package/src/types.ts +8 -0
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:
|
|
Binary file
|
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.6",
|
|
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,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
13
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
14
|
+
"@casys/mcp-compose": "^0.5.2",
|
|
14
15
|
"hono": "^4.0.0",
|
|
15
16
|
"ajv": "^8.17.1",
|
|
16
17
|
"jose": "^6.0.0",
|
package/src/auth/jwt-provider.ts
CHANGED
|
@@ -281,7 +281,11 @@ export class JwtAuthProvider extends AuthProvider {
|
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
return authInfo;
|
|
284
|
-
} catch {
|
|
284
|
+
} catch (err) {
|
|
285
|
+
// Log the actual rejection reason so JWKS fetch failures, audience
|
|
286
|
+
// mismatches, and expiration errors are distinguishable in logs.
|
|
287
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
288
|
+
console.error(`[JwtAuthProvider] Token rejected: ${msg}`);
|
|
285
289
|
return null;
|
|
286
290
|
}
|
|
287
291
|
}
|
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
|
@@ -439,8 +439,16 @@ export interface MCPTool {
|
|
|
439
439
|
* };
|
|
440
440
|
* ```
|
|
441
441
|
*/
|
|
442
|
+
export interface ToolHandlerContext {
|
|
443
|
+
readonly toolName: string;
|
|
444
|
+
readonly request?: Request;
|
|
445
|
+
readonly sessionId?: string;
|
|
446
|
+
readonly authInfo?: import("./auth/types.js").AuthInfo;
|
|
447
|
+
}
|
|
448
|
+
|
|
442
449
|
export type ToolHandler = (
|
|
443
450
|
args: Record<string, unknown>,
|
|
451
|
+
ctx?: ToolHandlerContext,
|
|
444
452
|
) => Promise<unknown> | unknown;
|
|
445
453
|
|
|
446
454
|
/**
|