@raytio/mcp-server 2.0.0 → 2.2.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.
@@ -0,0 +1,29 @@
1
+ import { RaytioApiClient } from './raytio/api-client.js';
2
+ /**
3
+ * Result of resolving the effective tool domain set for the authenticated
4
+ * user. When `authorized` is `false`, the caller MUST expose no tools.
5
+ */
6
+ export interface AuthorizationResult {
7
+ /** Comma-separated domain spec suitable for `resolveDomains()`, or `undefined` when no tools should be exposed. */
8
+ domainSpec: string | undefined;
9
+ /** Human-readable reason for the decision. Emitted to stderr for operator visibility. */
10
+ reason: string;
11
+ /** `true` when the caller should expose tools. `false` means fail closed — expose nothing. */
12
+ authorized: boolean;
13
+ }
14
+ type StderrLogger = Pick<Console, 'error'>;
15
+ /**
16
+ * Resolve the tool domain surface for the authenticated user.
17
+ *
18
+ * Behaviour:
19
+ * - Always queries the backend for the user's resolved roles. On any
20
+ * failure, fails closed and exposes no tools.
21
+ * - The static `RAYTIO_TOOL_DOMAINS` override may only *restrict* the
22
+ * user's resolved domain set. It never grants access to domains the
23
+ * user does not have.
24
+ * - If the intersection is empty (or the user has no recognised roles),
25
+ * fails closed.
26
+ */
27
+ export declare function resolveToolDomains(apiClient: RaytioApiClient, envSpec: string | undefined, logger?: StderrLogger): Promise<AuthorizationResult>;
28
+ export {};
29
+ //# sourceMappingURL=authorization.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.d.ts","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAGzD;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,mHAAmH;IACnH,UAAU,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,yFAAyF;IACzF,MAAM,EAAE,MAAM,CAAC;IACf,8FAA8F;IAC9F,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,KAAK,YAAY,GAAG,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;AAgD3C;;;;;;;;;;;GAWG;AACH,wBAAsB,kBAAkB,CACtC,SAAS,EAAE,eAAe,EAC1B,OAAO,EAAE,MAAM,GAAG,SAAS,EAC3B,MAAM,GAAE,YAAsB,GAC7B,OAAO,CAAC,mBAAmB,CAAC,CAyC9B"}
@@ -0,0 +1,87 @@
1
+ import { resolveUserDomains } from './tools/role-mapping.js';
2
+ /**
3
+ * Domains that a static override may resolve to when the user only holds
4
+ * the full-access parent. This preserves the useful "further restrict a
5
+ * privileged user to read-only tools" case without ever letting a static
6
+ * override grant access the user does not already have.
7
+ */
8
+ const READONLY_PARENTS = {
9
+ 'ppm-readonly': 'ppm',
10
+ 'wrm-readonly': 'wrm',
11
+ 'sfa-readonly': 'sfa',
12
+ };
13
+ function parseSpec(spec) {
14
+ if (!spec)
15
+ return [];
16
+ return spec
17
+ .split(',')
18
+ .map((s) => s.trim())
19
+ .filter(Boolean);
20
+ }
21
+ /**
22
+ * Intersect a static domain list with the user's resolved domain list.
23
+ * Static entries that ask for a read-only sub-domain of a full-access
24
+ * domain the user already holds are permitted (a further restriction).
25
+ * Anything else the user does not have is silently dropped — a static
26
+ * override is a restriction, never a grant.
27
+ */
28
+ function restrictToUserDomains(staticDomains, userDomains) {
29
+ const userSet = new Set(userDomains);
30
+ const allowed = [];
31
+ for (const d of staticDomains) {
32
+ if (userSet.has(d)) {
33
+ allowed.push(d);
34
+ continue;
35
+ }
36
+ const parent = READONLY_PARENTS[d];
37
+ if (parent && userSet.has(parent)) {
38
+ allowed.push(d);
39
+ }
40
+ }
41
+ return allowed;
42
+ }
43
+ /**
44
+ * Resolve the tool domain surface for the authenticated user.
45
+ *
46
+ * Behaviour:
47
+ * - Always queries the backend for the user's resolved roles. On any
48
+ * failure, fails closed and exposes no tools.
49
+ * - The static `RAYTIO_TOOL_DOMAINS` override may only *restrict* the
50
+ * user's resolved domain set. It never grants access to domains the
51
+ * user does not have.
52
+ * - If the intersection is empty (or the user has no recognised roles),
53
+ * fails closed.
54
+ */
55
+ export async function resolveToolDomains(apiClient, envSpec, logger = console) {
56
+ const staticDomains = parseSpec(envSpec);
57
+ let dynamicSpec;
58
+ try {
59
+ dynamicSpec = await resolveUserDomains(apiClient);
60
+ }
61
+ catch (err) {
62
+ const reason = `role query failed: ${err?.message ?? err}`;
63
+ logger.error(`Raytio MCP: authorization resolution failed (${reason}) — exposing no tools (fail closed)`);
64
+ return { domainSpec: undefined, reason, authorized: false };
65
+ }
66
+ const userDomains = parseSpec(dynamicSpec);
67
+ if (userDomains.length === 0) {
68
+ const reason = 'user has no recognised roles';
69
+ logger.error(`Raytio MCP: ${reason} — exposing no tools (fail closed)`);
70
+ return { domainSpec: undefined, reason, authorized: false };
71
+ }
72
+ if (staticDomains.length === 0) {
73
+ const spec = userDomains.join(',');
74
+ logger.error(`Raytio MCP: resolved domains from user roles: ${spec}`);
75
+ return { domainSpec: spec, reason: 'resolved from user roles', authorized: true };
76
+ }
77
+ const allowed = restrictToUserDomains(staticDomains, userDomains);
78
+ if (allowed.length === 0) {
79
+ const reason = `static RAYTIO_TOOL_DOMAINS "${staticDomains.join(',')}" does not intersect user roles "${userDomains.join(',')}"`;
80
+ logger.error(`Raytio MCP: ${reason} — exposing no tools (fail closed)`);
81
+ return { domainSpec: undefined, reason, authorized: false };
82
+ }
83
+ const spec = allowed.join(',');
84
+ logger.error(`Raytio MCP: static RAYTIO_TOOL_DOMAINS restricted user roles (${userDomains.join(',')}) to ${spec}`);
85
+ return { domainSpec: spec, reason: 'restricted by static override', authorized: true };
86
+ }
87
+ //# sourceMappingURL=authorization.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authorization.js","sourceRoot":"","sources":["../src/authorization.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAiB7D;;;;;GAKG;AACH,MAAM,gBAAgB,GAA2B;IAC/C,cAAc,EAAE,KAAK;IACrB,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