@hypequery/serve 0.25.0 → 0.26.1
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/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +3 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/semantic/datasets/utils/mcp-restrictions.d.ts +16 -0
- package/dist/semantic/datasets/utils/mcp-restrictions.d.ts.map +1 -0
- package/dist/semantic/datasets/utils/mcp-restrictions.js +33 -0
- package/dist/server/create-api.d.ts.map +1 -1
- package/dist/server/create-api.js +15 -0
- package/dist/server/mcp-source.d.ts +28 -0
- package/dist/server/mcp-source.d.ts.map +1 -1
- package/dist/server/mcp-source.js +5 -0
- package/dist/utils/jwt-audience.d.ts +9 -0
- package/dist/utils/jwt-audience.d.ts.map +1 -0
- package/dist/utils/jwt-audience.js +27 -0
- package/package.json +3 -3
package/dist/auth.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../src/auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,WAAW,EACX,oBAAoB,EACpB,qBAAqB,EACrB,YAAY,EACZ,mBAAmB,EACnB,aAAa,EACb,YAAY,EACb,MAAM,YAAY,CAAC;AACpB,OAAO,EAIL,KAAK,UAAU,EAChB,MAAM,MAAM,CAAC;AAWd;;;GAGG;AACH,eAAO,MAAM,SAAS,GAAI,SAAS,YAAY,EAAE,MAAM,MAAM,KAAG,MAAM,GAAG,SAexE,CAAC;AAEF,qBAAa,SAAU,SAAQ,KAAM,YAAW,aAAa;IAC3D,MAAM,EAAE,aAAa,CAAC,QAAQ,CAAC,CAAC;IAChC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;gBAEtB,MAAM,EA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
|
1
2
|
import { SignJWT, createRemoteJWKSet, jwtVerify, } from "jose";
|
|
2
3
|
const resolveHeaderValue = (value) => {
|
|
3
4
|
if (Array.isArray(value)) {
|
|
@@ -175,7 +176,7 @@ export function createJwtStrategy(options) {
|
|
|
175
176
|
algorithms: options.algorithms ?? ["RS256"],
|
|
176
177
|
});
|
|
177
178
|
}
|
|
178
|
-
|
|
179
|
+
const strategy = async ({ request }) => {
|
|
179
180
|
const raw = getHeader(request, headerName);
|
|
180
181
|
if (typeof raw !== "string" || !raw.startsWith(prefix)) {
|
|
181
182
|
if (options.optional)
|
|
@@ -200,6 +201,7 @@ export function createJwtStrategy(options) {
|
|
|
200
201
|
}
|
|
201
202
|
return mapClaims(payload, request);
|
|
202
203
|
};
|
|
204
|
+
return attachJwtAudience(strategy, options.audience);
|
|
203
205
|
}
|
|
204
206
|
export const createAnalyticsTokenIssuer = (options) => {
|
|
205
207
|
const key = resolveSecretKey(options.secret, "createAnalyticsTokenIssuer");
|
package/dist/index.d.ts
CHANGED
|
@@ -32,5 +32,6 @@ export { serveDev } from "./dev.js";
|
|
|
32
32
|
export * from "./serve.js";
|
|
33
33
|
export * from "./semantic/index.js";
|
|
34
34
|
export { readServeMcpSource } from './server/mcp-source.js';
|
|
35
|
-
export type { ServeMcpSource } from './server/mcp-source.js';
|
|
35
|
+
export type { ServeMcpAuth, ServeMcpSource } from './server/mcp-source.js';
|
|
36
|
+
export type { McpRestrictedEntry } from './semantic/datasets/utils/mcp-restrictions.js';
|
|
36
37
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,aAAa,CAAC;AAC5B,cAAc,eAAe,CAAC;AAC9B,cAAc,cAAc,CAA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';
|
|
2
|
+
/**
|
|
3
|
+
* A dataset or metric whose own entry options decide who may query it over REST.
|
|
4
|
+
* The MCP transport serves the registered definitions and applies only the
|
|
5
|
+
* application's global auth and tenant, so these options would be silently skipped.
|
|
6
|
+
*/
|
|
7
|
+
export interface McpRestrictedEntry {
|
|
8
|
+
readonly kind: 'dataset' | 'metric';
|
|
9
|
+
/** The registration name. */
|
|
10
|
+
readonly name: string;
|
|
11
|
+
/** The entry options that carry the rule, such as `requiredRoles`. */
|
|
12
|
+
readonly rules: readonly string[];
|
|
13
|
+
}
|
|
14
|
+
/** Every registered dataset and metric that carries endpoint-level access rules. */
|
|
15
|
+
export declare function collectMcpRestrictions(datasets: DatasetsConfig<any> | undefined, metrics: MetricsConfig<any> | undefined): McpRestrictedEntry[];
|
|
16
|
+
//# sourceMappingURL=mcp-restrictions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-restrictions.d.ts","sourceRoot":"","sources":["../../../../src/semantic/datasets/utils/mcp-restrictions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAIvE;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,EAAE,SAAS,GAAG,QAAQ,CAAC;IACpC,6BAA6B;IAC7B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,sEAAsE;IACtE,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAsBD,oFAAoF;AACpF,wBAAgB,sBAAsB,CACpC,QAAQ,EAAE,cAAc,CAAC,GAAG,CAAC,GAAG,SAAS,EACzC,OAAO,EAAE,aAAa,CAAC,GAAG,CAAC,GAAG,SAAS,GACtC,kBAAkB,EAAE,CAWtB"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { resolveMetricEntry } from '../metric-endpoint.js';
|
|
2
|
+
import { resolveDatasetEntry } from './dataset-entry.js';
|
|
3
|
+
function rulesOf(entry) {
|
|
4
|
+
const rules = [];
|
|
5
|
+
// `requiresAuth: false` is not listed: MCP over HTTP always authenticates, which is stricter.
|
|
6
|
+
if (entry.auth != null)
|
|
7
|
+
rules.push('auth');
|
|
8
|
+
if ((entry.requiredRoles?.length ?? 0) > 0)
|
|
9
|
+
rules.push('requiredRoles');
|
|
10
|
+
if ((entry.requiredScopes?.length ?? 0) > 0)
|
|
11
|
+
rules.push('requiredScopes');
|
|
12
|
+
if ((entry.middlewares?.length ?? 0) > 0)
|
|
13
|
+
rules.push('middlewares');
|
|
14
|
+
// A per-dataset tenant override can resolve a different tenant than the global one.
|
|
15
|
+
if (entry.tenant !== undefined)
|
|
16
|
+
rules.push('tenant');
|
|
17
|
+
return rules;
|
|
18
|
+
}
|
|
19
|
+
/** Every registered dataset and metric that carries endpoint-level access rules. */
|
|
20
|
+
export function collectMcpRestrictions(datasets, metrics) {
|
|
21
|
+
const restricted = [];
|
|
22
|
+
for (const [name, entry] of Object.entries(datasets ?? {})) {
|
|
23
|
+
const rules = rulesOf(resolveDatasetEntry(entry));
|
|
24
|
+
if (rules.length > 0)
|
|
25
|
+
restricted.push({ kind: 'dataset', name, rules });
|
|
26
|
+
}
|
|
27
|
+
for (const [name, entry] of Object.entries(metrics ?? {})) {
|
|
28
|
+
const rules = rulesOf(resolveMetricEntry(entry));
|
|
29
|
+
if (rules.length > 0)
|
|
30
|
+
restricted.push({ kind: 'metric', name, rules });
|
|
31
|
+
}
|
|
32
|
+
return restricted;
|
|
33
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-api.d.ts","sourceRoot":"","sources":["../../src/server/create-api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EAEX,YAAY,EAEZ,gBAAgB,EAIhB,eAAe,EACf,WAAW,EACX,aAAa,EACb,cAAc,EACd,wBAAwB,EACzB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"create-api.d.ts","sourceRoot":"","sources":["../../src/server/create-api.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,WAAW,EAEX,YAAY,EAEZ,gBAAgB,EAIhB,eAAe,EACf,WAAW,EACX,aAAa,EACb,cAAc,EACd,wBAAwB,EACzB,MAAM,aAAa,CAAC;AAyCrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,SAAS,GACpB,QAAQ,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClE,KAAK,SAAS,WAAW,GAAG,WAAW,EACvC,QAAQ,SAAS,eAAe,CAAC,QAAQ,EAAE,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EACxE,QAAQ,SAAS,aAAa,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAC5D,SAAS,SAAS,cAAc,CAAC,KAAK,CAAC,GAAG,MAAM,CAAC,KAAK,EAAE,KAAK,CAAC,EAE9D,QAAQ,WAAW,CAAC,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC,KAClE,YAAY,CACb,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,CAAC,GACvC,wBAAwB,CAAC,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,EAClE,QAAQ,EACR,KAAK,CA0YN,CAAC"}
|
|
@@ -14,6 +14,7 @@ import { createCacheObservability, detectBuilderCache } from "../cache-observabi
|
|
|
14
14
|
import { createDatasetClient, serializeSemanticContract, toQueryBuilderFactory } from "@hypequery/datasets";
|
|
15
15
|
import { createMetricEndpoint, createDatasetEndpoint, createSemanticContractEndpoint, buildSemanticContractSource, } from "../semantic/datasets/index.js";
|
|
16
16
|
import { attachServeMcpSource } from "./mcp-source.js";
|
|
17
|
+
import { collectMcpRestrictions } from "../semantic/datasets/utils/mcp-restrictions.js";
|
|
17
18
|
import { exportClientContract, resolveClientMountPath } from "./client-contract.js";
|
|
18
19
|
import { createClientEndpointBinding } from "../semantic/datasets/utils/client-endpoint-binding.js";
|
|
19
20
|
import { endpointClientProfile } from "../semantic/datasets/utils/client-endpoint-profile.js";
|
|
@@ -310,8 +311,22 @@ export const createAPI = (config) => {
|
|
|
310
311
|
// same semantic model as this entrypoint rather than a second MCP config.
|
|
311
312
|
if (config.datasets) {
|
|
312
313
|
const mcpDatasets = buildSemanticContractSource(config.datasets, config.metrics);
|
|
314
|
+
const restricted = collectMcpRestrictions(config.datasets, config.metrics);
|
|
313
315
|
attachServeMcpSource(api, {
|
|
314
316
|
datasets: mcpDatasets,
|
|
317
|
+
...(restricted.length > 0 ? { restricted } : {}),
|
|
318
|
+
// Read when MCP starts: `api.use()` may add global middlewares after defineServe.
|
|
319
|
+
globalMiddlewareCount: () => globalMiddlewares.length,
|
|
320
|
+
...(authStrategies.length > 0
|
|
321
|
+
? {
|
|
322
|
+
auth: {
|
|
323
|
+
strategies: authStrategies,
|
|
324
|
+
...(globalTenantConfig
|
|
325
|
+
? { tenant: { extract: globalTenantConfig.extract } }
|
|
326
|
+
: {}),
|
|
327
|
+
},
|
|
328
|
+
}
|
|
329
|
+
: {}),
|
|
315
330
|
resolveAnalytics: () => {
|
|
316
331
|
if (!resolvedQueryBuilder) {
|
|
317
332
|
throw new Error('A query builder is required to execute datasets over MCP. Pass `queryBuilder` '
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import type { DatasetCatalogSource, DatasetClient } from '@hypequery/datasets';
|
|
2
|
+
import type { AuthContext, AuthStrategy } from '../types.js';
|
|
3
|
+
import type { McpRestrictedEntry } from '../semantic/datasets/utils/mcp-restrictions.js';
|
|
2
4
|
export interface ServeMcpSource {
|
|
3
5
|
readonly version: 1;
|
|
4
6
|
/** Datasets keyed as registered, with named metrics grouped onto each. */
|
|
@@ -9,6 +11,32 @@ export interface ServeMcpSource {
|
|
|
9
11
|
* configured query builder should fail when MCP starts rather than at import.
|
|
10
12
|
*/
|
|
11
13
|
readonly resolveAnalytics: () => DatasetClient;
|
|
14
|
+
/**
|
|
15
|
+
* The application's own authentication, so `hypequery mcp --http` verifies
|
|
16
|
+
* callers and assigns tenants exactly as the REST API does. Absent when the
|
|
17
|
+
* application configures no auth.
|
|
18
|
+
*/
|
|
19
|
+
readonly auth?: ServeMcpAuth;
|
|
20
|
+
/**
|
|
21
|
+
* Datasets and metrics whose own entry options (auth, roles, scopes, middlewares,
|
|
22
|
+
* tenant override) decide who may query them over REST. The MCP transport does not
|
|
23
|
+
* apply those, so a server that verifies callers must refuse to serve them.
|
|
24
|
+
*/
|
|
25
|
+
readonly restricted?: readonly McpRestrictedEntry[];
|
|
26
|
+
/**
|
|
27
|
+
* How many global middlewares (`defineServe({ middlewares })` and `api.use()`) REST runs
|
|
28
|
+
* before every endpoint. The MCP transport does not run them, so a server that verifies
|
|
29
|
+
* callers must refuse to serve when any are configured. Read lazily: `api.use()` may run
|
|
30
|
+
* after `defineServe` returns.
|
|
31
|
+
*/
|
|
32
|
+
readonly globalMiddlewareCount?: () => number;
|
|
33
|
+
}
|
|
34
|
+
/** The application's auth strategies and tenant extraction, as configured on `defineServe`. */
|
|
35
|
+
export interface ServeMcpAuth {
|
|
36
|
+
readonly strategies: readonly AuthStrategy<AuthContext>[];
|
|
37
|
+
readonly tenant?: {
|
|
38
|
+
readonly extract: (auth: AuthContext) => string | null | undefined;
|
|
39
|
+
};
|
|
12
40
|
}
|
|
13
41
|
export declare function attachServeMcpSource(target: object, source: Omit<ServeMcpSource, 'version'>): void;
|
|
14
42
|
/** Read the MCP source off a loaded Serve entrypoint, if it registered datasets. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp-source.d.ts","sourceRoot":"","sources":["../../src/server/mcp-source.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,aAAa,EAAE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AAc,GAAG,SAAS,CAM7E"}
|
|
@@ -14,6 +14,11 @@ export function attachServeMcpSource(target, source) {
|
|
|
14
14
|
version: 1,
|
|
15
15
|
datasets: Object.freeze({ ...source.datasets }),
|
|
16
16
|
resolveAnalytics: source.resolveAnalytics,
|
|
17
|
+
...(source.globalMiddlewareCount ? { globalMiddlewareCount: source.globalMiddlewareCount } : {}),
|
|
18
|
+
...(source.auth ? { auth: Object.freeze({ ...source.auth, strategies: Object.freeze([...source.auth.strategies]) }) } : {}),
|
|
19
|
+
...(source.restricted?.length
|
|
20
|
+
? { restricted: Object.freeze(source.restricted.map(entry => Object.freeze({ ...entry, rules: Object.freeze([...entry.rules]) }))) }
|
|
21
|
+
: {}),
|
|
17
22
|
}),
|
|
18
23
|
enumerable: false,
|
|
19
24
|
configurable: false,
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface JwtStrategyAudience {
|
|
2
|
+
readonly version: 1;
|
|
3
|
+
/** The `aud` values a token may carry one of; empty when the audience is not checked. */
|
|
4
|
+
readonly audiences: readonly string[];
|
|
5
|
+
}
|
|
6
|
+
export declare function attachJwtAudience<T extends object>(strategy: T, audience: string | readonly string[] | undefined): T;
|
|
7
|
+
/** The audiences a `createJwtStrategy` strategy accepts, or undefined for any other strategy. */
|
|
8
|
+
export declare function readJwtAudience(strategy: unknown): readonly string[] | undefined;
|
|
9
|
+
//# sourceMappingURL=jwt-audience.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"jwt-audience.d.ts","sourceRoot":"","sources":["../../src/utils/jwt-audience.ts"],"names":[],"mappings":"AAWA,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,OAAO,EAAE,CAAC,CAAC;IACpB,yFAAyF;IACzF,QAAQ,CAAC,SAAS,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED,wBAAgB,iBAAiB,CAAC,CAAC,SAAS,MAAM,EAChD,QAAQ,EAAE,CAAC,EACX,QAAQ,EAAE,MAAM,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,GAC/C,CAAC,CASH;AAED,iGAAiG;AACjG,wBAAgB,eAAe,CAAC,QAAQ,EAAE,OAAO,GAAG,SAAS,MAAM,EAAE,GAAG,SAAS,CAIhF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lets a host learn which audiences a JWT strategy accepts without verifying a token.
|
|
3
|
+
*
|
|
4
|
+
* `createJwtStrategy` returns a closure, so its configuration is otherwise invisible.
|
|
5
|
+
* `hypequery mcp --http` needs it to refuse a strategy that would also accept tokens
|
|
6
|
+
* issued for another API. Attached under a registered symbol so a consumer that cannot
|
|
7
|
+
* import serve (it is an optional peer) reads the same key. Keep it in step with
|
|
8
|
+
* `@hypequery/mcp`'s `http-auth.ts`.
|
|
9
|
+
*/
|
|
10
|
+
const jwtAudienceSymbol = Symbol.for('hypequery.jwt-audience.v1');
|
|
11
|
+
export function attachJwtAudience(strategy, audience) {
|
|
12
|
+
const audiences = audience === undefined ? [] : typeof audience === 'string' ? [audience] : [...audience];
|
|
13
|
+
Object.defineProperty(strategy, jwtAudienceSymbol, {
|
|
14
|
+
value: Object.freeze({ version: 1, audiences: Object.freeze(audiences) }),
|
|
15
|
+
enumerable: false,
|
|
16
|
+
configurable: false,
|
|
17
|
+
writable: false,
|
|
18
|
+
});
|
|
19
|
+
return strategy;
|
|
20
|
+
}
|
|
21
|
+
/** The audiences a `createJwtStrategy` strategy accepts, or undefined for any other strategy. */
|
|
22
|
+
export function readJwtAudience(strategy) {
|
|
23
|
+
if (typeof strategy !== 'function')
|
|
24
|
+
return undefined;
|
|
25
|
+
const value = strategy[jwtAudienceSymbol];
|
|
26
|
+
return value?.version === 1 && Array.isArray(value.audiences) ? value.audiences : undefined;
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hypequery/serve",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"description": "Code-first TypeScript runtime for validated ClickHouse analytics APIs, OpenAPI, auth, and tenancy",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"clickhouse",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
"openapi-typescript": "^7.13.0",
|
|
39
39
|
"zod": "^4.6.6",
|
|
40
40
|
"zod-to-json-schema": "^3.25.2",
|
|
41
|
-
"@hypequery/datasets": "^0.
|
|
42
|
-
"@hypequery/protocol": "^0.
|
|
41
|
+
"@hypequery/datasets": "^0.32.0",
|
|
42
|
+
"@hypequery/protocol": "^0.27.0"
|
|
43
43
|
},
|
|
44
44
|
"peerDependencies": {
|
|
45
45
|
"tsx": "^4.0.0",
|