@sota-io/mcp 1.5.0 → 1.6.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.
Files changed (51) hide show
  1. package/README.md +8 -2
  2. package/dist/auth/token-bridge.d.ts +16 -0
  3. package/dist/auth/token-bridge.d.ts.map +1 -1
  4. package/dist/auth/token-bridge.js +49 -9
  5. package/dist/auth/token-bridge.js.map +1 -1
  6. package/dist/auth/verify-jwt.js +6 -6
  7. package/dist/auth/verify-jwt.js.map +1 -1
  8. package/dist/http-app.d.ts +27 -0
  9. package/dist/http-app.d.ts.map +1 -0
  10. package/dist/http-app.js +310 -0
  11. package/dist/http-app.js.map +1 -0
  12. package/dist/http.d.ts +3 -15
  13. package/dist/http.d.ts.map +1 -1
  14. package/dist/http.js +13 -251
  15. package/dist/http.js.map +1 -1
  16. package/dist/index.js +2 -1
  17. package/dist/index.js.map +1 -1
  18. package/dist/lib/archive-builder.d.ts +25 -5
  19. package/dist/lib/archive-builder.d.ts.map +1 -1
  20. package/dist/lib/archive-builder.js +105 -34
  21. package/dist/lib/archive-builder.js.map +1 -1
  22. package/dist/lib/auth-config.d.ts +37 -0
  23. package/dist/lib/auth-config.d.ts.map +1 -0
  24. package/dist/lib/auth-config.js +95 -0
  25. package/dist/lib/auth-config.js.map +1 -0
  26. package/dist/lib/hosted-guard.d.ts +26 -0
  27. package/dist/lib/hosted-guard.d.ts.map +1 -0
  28. package/dist/lib/hosted-guard.js +48 -0
  29. package/dist/lib/hosted-guard.js.map +1 -0
  30. package/dist/lib/log.d.ts +17 -0
  31. package/dist/lib/log.d.ts.map +1 -0
  32. package/dist/lib/log.js +41 -0
  33. package/dist/lib/log.js.map +1 -0
  34. package/dist/lib/version.d.ts +22 -0
  35. package/dist/lib/version.d.ts.map +1 -0
  36. package/dist/lib/version.js +36 -0
  37. package/dist/lib/version.js.map +1 -0
  38. package/dist/oauth-proxy.d.ts +31 -0
  39. package/dist/oauth-proxy.d.ts.map +1 -0
  40. package/dist/oauth-proxy.js +212 -0
  41. package/dist/oauth-proxy.js.map +1 -0
  42. package/dist/tools/create-account.d.ts.map +1 -1
  43. package/dist/tools/create-account.js +23 -1
  44. package/dist/tools/create-account.js.map +1 -1
  45. package/dist/tools/deploy.d.ts +11 -1
  46. package/dist/tools/deploy.d.ts.map +1 -1
  47. package/dist/tools/deploy.js +92 -74
  48. package/dist/tools/deploy.js.map +1 -1
  49. package/dist/tools/env.js +1 -1
  50. package/dist/tools/env.js.map +1 -1
  51. package/package.json +1 -1
@@ -0,0 +1,37 @@
1
+ /**
2
+ * auth-config.ts — env-driven auth settings of the hosted MCP server (GDPR-3).
3
+ *
4
+ * Two values used to be hard-coded for prod (GDPR-3 ADR §11):
5
+ * - the OAuth proxy upstream (oauth-proxy.ts)
6
+ * - the accepted JWT issuers (auth/verify-jwt.ts)
7
+ *
8
+ * Env:
9
+ * AUTH_SERVER upstream GoTrue base incl. /auth/v1. Already set by
10
+ * compose (platform.yml: ${SUPABASE_URL}/auth/v1).
11
+ * Unset/blank → https://auth.sota.io/auth/v1 (prod).
12
+ * SUPABASE_JWT_ISSUERS comma-separated accepted iss values, exact match.
13
+ * Same name and rules as the Go API (config.go
14
+ * JWTIssuers). Unset/blank → today's two prod issuers.
15
+ *
16
+ * The upstream is always accepted as an issuer as well: GoTrue writes its own
17
+ * public URL into iss, so a dev or self-hosted setup only has to set
18
+ * AUTH_SERVER. Signature checking (SUPABASE_JWT_SECRET) stays the real gate.
19
+ *
20
+ * Invalid values throw, so the server fails at startup instead of answering
21
+ * 401 to every request later.
22
+ */
23
+ export declare const DEFAULT_AUTH_UPSTREAM = "https://auth.sota.io/auth/v1";
24
+ export declare const DEFAULT_ACCEPTED_ISSUERS: readonly string[];
25
+ /**
26
+ * Resolve the OAuth proxy upstream from AUTH_SERVER. Trailing slashes are
27
+ * trimmed; https is required (http only for localhost / 127.0.0.1).
28
+ */
29
+ export declare function resolveAuthUpstream(env?: NodeJS.ProcessEnv): string;
30
+ /**
31
+ * Parse SUPABASE_JWT_ISSUERS with the same rules as the Go API: absolute URL,
32
+ * no query/fragment/credentials, lower-case host, no trailing slash, https
33
+ * (http only for localhost). Blank → DEFAULT_ACCEPTED_ISSUERS. The upstream
34
+ * is appended when it is not in the list yet.
35
+ */
36
+ export declare function resolveAcceptedIssuers(env?: NodeJS.ProcessEnv, upstream?: string): string[];
37
+ //# sourceMappingURL=auth-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-config.d.ts","sourceRoot":"","sources":["../../src/lib/auth-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,eAAO,MAAM,qBAAqB,iCAAiC,CAAC;AAEpE,eAAO,MAAM,wBAAwB,EAAE,SAAS,MAAM,EAGrD,CAAC;AAMF;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAsBhF;AAED;;;;;GAKG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,GAAE,MAAM,CAAC,UAAwB,EACpC,QAAQ,GAAE,MAAiC,GAC1C,MAAM,EAAE,CA+BV"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * auth-config.ts — env-driven auth settings of the hosted MCP server (GDPR-3).
3
+ *
4
+ * Two values used to be hard-coded for prod (GDPR-3 ADR §11):
5
+ * - the OAuth proxy upstream (oauth-proxy.ts)
6
+ * - the accepted JWT issuers (auth/verify-jwt.ts)
7
+ *
8
+ * Env:
9
+ * AUTH_SERVER upstream GoTrue base incl. /auth/v1. Already set by
10
+ * compose (platform.yml: ${SUPABASE_URL}/auth/v1).
11
+ * Unset/blank → https://auth.sota.io/auth/v1 (prod).
12
+ * SUPABASE_JWT_ISSUERS comma-separated accepted iss values, exact match.
13
+ * Same name and rules as the Go API (config.go
14
+ * JWTIssuers). Unset/blank → today's two prod issuers.
15
+ *
16
+ * The upstream is always accepted as an issuer as well: GoTrue writes its own
17
+ * public URL into iss, so a dev or self-hosted setup only has to set
18
+ * AUTH_SERVER. Signature checking (SUPABASE_JWT_SECRET) stays the real gate.
19
+ *
20
+ * Invalid values throw, so the server fails at startup instead of answering
21
+ * 401 to every request later.
22
+ */
23
+ export const DEFAULT_AUTH_UPSTREAM = 'https://auth.sota.io/auth/v1';
24
+ export const DEFAULT_ACCEPTED_ISSUERS = [
25
+ 'https://wnwsdtqhywfxxlnyqafk.supabase.co/auth/v1',
26
+ 'https://auth.sota.io/auth/v1',
27
+ ];
28
+ function isLocalHost(hostname) {
29
+ return hostname === 'localhost' || hostname === '127.0.0.1' || hostname === '[::1]';
30
+ }
31
+ /**
32
+ * Resolve the OAuth proxy upstream from AUTH_SERVER. Trailing slashes are
33
+ * trimmed; https is required (http only for localhost / 127.0.0.1).
34
+ */
35
+ export function resolveAuthUpstream(env = process.env) {
36
+ const raw = (env.AUTH_SERVER ?? '').trim();
37
+ if (raw === '')
38
+ return DEFAULT_AUTH_UPSTREAM;
39
+ let u;
40
+ try {
41
+ u = new URL(raw);
42
+ }
43
+ catch {
44
+ throw new Error(`AUTH_SERVER: ${JSON.stringify(raw)} is not an absolute URL`);
45
+ }
46
+ if (u.username || u.password || u.search || u.hash) {
47
+ throw new Error(`AUTH_SERVER: ${JSON.stringify(raw)} must not carry credentials, a query or a fragment`);
48
+ }
49
+ if (u.protocol !== 'https:' && !(u.protocol === 'http:' && isLocalHost(u.hostname))) {
50
+ throw new Error(`AUTH_SERVER: ${JSON.stringify(raw)} must use https (http only for localhost/127.0.0.1)`);
51
+ }
52
+ // origin lower-cases the host; pathname keeps /auth/v1.
53
+ return `${u.origin}${u.pathname}`.replace(/\/+$/, '');
54
+ }
55
+ /**
56
+ * Parse SUPABASE_JWT_ISSUERS with the same rules as the Go API: absolute URL,
57
+ * no query/fragment/credentials, lower-case host, no trailing slash, https
58
+ * (http only for localhost). Blank → DEFAULT_ACCEPTED_ISSUERS. The upstream
59
+ * is appended when it is not in the list yet.
60
+ */
61
+ export function resolveAcceptedIssuers(env = process.env, upstream = resolveAuthUpstream(env)) {
62
+ const parsed = [];
63
+ for (const part of (env.SUPABASE_JWT_ISSUERS ?? '').split(',')) {
64
+ const iss = part.trim();
65
+ if (iss === '')
66
+ continue;
67
+ let u;
68
+ try {
69
+ u = new URL(iss);
70
+ }
71
+ catch {
72
+ throw new Error(`SUPABASE_JWT_ISSUERS: ${JSON.stringify(iss)} is not an absolute URL`);
73
+ }
74
+ if (u.username || u.password || u.search || u.hash || iss.includes('?') || iss.includes('#')) {
75
+ throw new Error(`SUPABASE_JWT_ISSUERS: ${JSON.stringify(iss)} is not an absolute URL`);
76
+ }
77
+ // URL lower-cases the host itself, so compare against the raw authority.
78
+ const rawAuthority = iss.slice(iss.indexOf('//') + 2).split('/')[0];
79
+ if (rawAuthority !== rawAuthority.toLowerCase()) {
80
+ throw new Error(`SUPABASE_JWT_ISSUERS: ${JSON.stringify(iss)} must have a lower-case host`);
81
+ }
82
+ if (iss.endsWith('/')) {
83
+ throw new Error(`SUPABASE_JWT_ISSUERS: ${JSON.stringify(iss)} must not end with a slash`);
84
+ }
85
+ if (u.protocol !== 'https:' && !(u.protocol === 'http:' && isLocalHost(u.hostname))) {
86
+ throw new Error(`SUPABASE_JWT_ISSUERS: ${JSON.stringify(iss)} must use https`);
87
+ }
88
+ parsed.push(iss);
89
+ }
90
+ const list = parsed.length > 0 ? parsed : [...DEFAULT_ACCEPTED_ISSUERS];
91
+ if (!list.includes(upstream))
92
+ list.push(upstream);
93
+ return list;
94
+ }
95
+ //# sourceMappingURL=auth-config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth-config.js","sourceRoot":"","sources":["../../src/lib/auth-config.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,MAAM,CAAC,MAAM,qBAAqB,GAAG,8BAA8B,CAAC;AAEpE,MAAM,CAAC,MAAM,wBAAwB,GAAsB;IACzD,kDAAkD;IAClD,8BAA8B;CAC/B,CAAC;AA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,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACtB,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,4BAA4B,CAAC,CAAC;QAC5F,CAAC;QACD,IAAI,CAAC,CAAC,QAAQ,KAAK,QAAQ,IAAI,CAAC,CAAC,CAAC,CAAC,QAAQ,KAAK,OAAO,IAAI,WAAW,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC;YACpF,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC;QACjF,CAAC;QACD,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IACnB,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,wBAAwB,CAAC,CAAC;IACxE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC;QAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;IAClD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Request guard for the hosted MCP server (mcp.sota.io).
3
+ *
4
+ * The hosted `deploy` tool only accepts inline `files`. Its schema does not
5
+ * advertise `directory`, `git_url` or `git_branch`, but a client can send
6
+ * them anyway. A directory deploy would pack the sota-mcp container's own
7
+ * filesystem (process.cwd() or any absolute path) into the caller's
8
+ * project, and git_url would make the server fetch arbitrary URLs. This
9
+ * guard rejects such calls before any tool code runs, independent of how
10
+ * the MCP SDK validates or strips unknown arguments. The deploy tool itself
11
+ * refuses every non-`files` mode in hosted mode as a second layer.
12
+ */
13
+ /** deploy arguments the hosted server refuses. */
14
+ export declare const HOSTED_FORBIDDEN_DEPLOY_ARGS: readonly ["directory", "git_url", "git_branch"];
15
+ export interface HostedRejection {
16
+ /** JSON-RPC id of the offending message, if it had one. */
17
+ id: string | number | null;
18
+ message: string;
19
+ }
20
+ export declare const HOSTED_FILES_ONLY_HINT = "Pass the source inline as `files`, or deploy a directory or a git repository with the local server (npx @sota-io/mcp) or the CLI (`sota deploy`).";
21
+ /**
22
+ * Returns a rejection when any JSON-RPC message in `body` (a single message
23
+ * or a batch) is a `tools/call` of `deploy` carrying a forbidden argument.
24
+ */
25
+ export declare function hostedDeployRejection(body: unknown): HostedRejection | null;
26
+ //# sourceMappingURL=hosted-guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-guard.d.ts","sourceRoot":"","sources":["../../src/lib/hosted-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,kDAAkD;AAClD,eAAO,MAAM,4BAA4B,iDAAkD,CAAC;AAE5F,MAAM,WAAW,eAAe;IAC9B,2DAA2D;IAC3D,EAAE,EAAE,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,sBAAsB,sJACkH,CAAC;AAEtJ;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,OAAO,GAAG,eAAe,GAAG,IAAI,CAuB3E"}
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Request guard for the hosted MCP server (mcp.sota.io).
3
+ *
4
+ * The hosted `deploy` tool only accepts inline `files`. Its schema does not
5
+ * advertise `directory`, `git_url` or `git_branch`, but a client can send
6
+ * them anyway. A directory deploy would pack the sota-mcp container's own
7
+ * filesystem (process.cwd() or any absolute path) into the caller's
8
+ * project, and git_url would make the server fetch arbitrary URLs. This
9
+ * guard rejects such calls before any tool code runs, independent of how
10
+ * the MCP SDK validates or strips unknown arguments. The deploy tool itself
11
+ * refuses every non-`files` mode in hosted mode as a second layer.
12
+ */
13
+ /** deploy arguments the hosted server refuses. */
14
+ export const HOSTED_FORBIDDEN_DEPLOY_ARGS = ['directory', 'git_url', 'git_branch'];
15
+ export const HOSTED_FILES_ONLY_HINT = 'Pass the source inline as `files`, or deploy a directory or a git repository with the local server (npx @sota-io/mcp) or the CLI (`sota deploy`).';
16
+ /**
17
+ * Returns a rejection when any JSON-RPC message in `body` (a single message
18
+ * or a batch) is a `tools/call` of `deploy` carrying a forbidden argument.
19
+ */
20
+ export function hostedDeployRejection(body) {
21
+ const messages = Array.isArray(body) ? body : [body];
22
+ for (const msg of messages) {
23
+ if (!msg || typeof msg !== 'object')
24
+ continue;
25
+ const m = msg;
26
+ if (m.method !== 'tools/call')
27
+ continue;
28
+ const params = m.params;
29
+ if (!params || typeof params !== 'object')
30
+ continue;
31
+ const p = params;
32
+ if (p.name !== 'deploy')
33
+ continue;
34
+ const args = p.arguments;
35
+ if (!args || typeof args !== 'object')
36
+ continue;
37
+ const forbidden = HOSTED_FORBIDDEN_DEPLOY_ARGS.filter((k) => Object.prototype.hasOwnProperty.call(args, k));
38
+ if (forbidden.length === 0)
39
+ continue;
40
+ const id = typeof m.id === 'string' || typeof m.id === 'number' ? m.id : null;
41
+ return {
42
+ id,
43
+ message: `The hosted sota.io MCP server does not accept ${forbidden.map((k) => `\`${k}\``).join(', ')}. ${HOSTED_FILES_ONLY_HINT}`,
44
+ };
45
+ }
46
+ return null;
47
+ }
48
+ //# sourceMappingURL=hosted-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hosted-guard.js","sourceRoot":"","sources":["../../src/lib/hosted-guard.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,kDAAkD;AAClD,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAAC,WAAW,EAAE,SAAS,EAAE,YAAY,CAAU,CAAC;AAQ5F,MAAM,CAAC,MAAM,sBAAsB,GACjC,mJAAmJ,CAAC;AAEtJ;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAa;IACjD,MAAM,QAAQ,GAAG,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IA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+ /**
2
+ * Structured logging without personal data.
3
+ *
4
+ * Every log line of the hosted server goes through `logEvent`, which
5
+ * serialises the fields as one JSON object and then redacts anything that
6
+ * looks like an email address, including emails embedded in upstream error
7
+ * messages. Log user ids (JWT `sub`) to correlate requests, never emails.
8
+ */
9
+ export declare const EMAIL_REDACTED = "[email redacted]";
10
+ export declare function redactEmails(text: string): string;
11
+ export type LogLevel = 'info' | 'warn' | 'error';
12
+ /** Serialise `fields` as a single JSON line with emails redacted. */
13
+ export declare function formatLogLine(fields: Record<string, unknown>): string;
14
+ export declare function logEvent(level: LogLevel, fields: Record<string, unknown>): void;
15
+ /** Error message for a log field, with emails redacted. */
16
+ export declare function errorMessage(err: unknown): string;
17
+ //# sourceMappingURL=log.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/lib/log.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAKH,eAAO,MAAM,cAAc,qBAAqB,CAAC;AAEjD,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAEjD;AAED,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAEjD,qEAAqE;AACrE,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAQrE;AAED,wBAAgB,QAAQ,CAAC,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAO/E;AAED,2DAA2D;AAC3D,wBAAgB,YAAY,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM,CAEjD"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Structured logging without personal data.
3
+ *
4
+ * Every log line of the hosted server goes through `logEvent`, which
5
+ * serialises the fields as one JSON object and then redacts anything that
6
+ * looks like an email address, including emails embedded in upstream error
7
+ * messages. Log user ids (JWT `sub`) to correlate requests, never emails.
8
+ */
9
+ // Deliberately broad: a false positive only costs a redacted log fragment.
10
+ const EMAIL_RE = /[A-Za-z0-9._%+-]+@[A-Za-z0-9-]+(?:\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,}/g;
11
+ export const EMAIL_REDACTED = '[email redacted]';
12
+ export function redactEmails(text) {
13
+ return text.replace(EMAIL_RE, EMAIL_REDACTED);
14
+ }
15
+ /** Serialise `fields` as a single JSON line with emails redacted. */
16
+ export function formatLogLine(fields) {
17
+ let line;
18
+ try {
19
+ line = JSON.stringify(fields);
20
+ }
21
+ catch {
22
+ line = JSON.stringify({ event: 'log_serialisation_failed' });
23
+ }
24
+ return redactEmails(line);
25
+ }
26
+ export function logEvent(level, fields) {
27
+ const line = formatLogLine(fields);
28
+ /* eslint-disable no-console */
29
+ if (level === 'error')
30
+ console.error(line);
31
+ else if (level === 'warn')
32
+ console.warn(line);
33
+ else
34
+ console.log(line);
35
+ /* eslint-enable no-console */
36
+ }
37
+ /** Error message for a log field, with emails redacted. */
38
+ export function errorMessage(err) {
39
+ return redactEmails(err instanceof Error ? err.message : String(err));
40
+ }
41
+ //# sourceMappingURL=log.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/lib/log.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,2EAA2E;AAC3E,MAAM,QAAQ,GAAG,oEAAoE,CAAC;AAEtF,MAAM,CAAC,MAAM,cAAc,GAAG,kBAAkB,CAAC;AAEjD,MAAM,UAAU,YAAY,CAAC,IAAY;IACvC,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;AAChD,CAAC;AAID,qEAAqE;AACrE,MAAM,UAAU,aAAa,CAAC,MAA+B;IAC3D,IAAI,IAAY,CAAC;IACjB,IAAI,CAAC;QACH,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC;IAChC,CAAC;IAAC,MAAM,CAAC;QACP,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,EAAE,KAAK,EAAE,0BAA0B,EAAE,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,YAAY,CAAC,IAAI,CAAC,CAAC;AAC5B,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,KAAe,EAAE,MAA+B;IACvE,MAAM,IAAI,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC;IACnC,+BAA+B;IAC/B,IAAI,KAAK,KAAK,OAAO;QAAE,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;SACtC,IAAI,KAAK,KAAK,MAAM;QAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;;QACzC,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IACvB,8BAA8B;AAChC,CAAC;AAED,2DAA2D;AAC3D,MAAM,UAAU,YAAY,CAAC,GAAY;IACvC,OAAO,YAAY,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;AACxE,CAAC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * The package version, read from package.json at runtime.
3
+ *
4
+ * Both entry points (stdio `index.ts` and hosted `http.ts`) report this
5
+ * version, so /health and the MCP `initialize` handshake always match the
6
+ * code that is actually running. The compiled file lives at
7
+ * dist/lib/version.js, so ../../package.json is the package root in the
8
+ * npm tarball, in a local checkout and in the Docker image (/app).
9
+ */
10
+ export declare function readPackageVersion(): string;
11
+ export declare const PACKAGE_VERSION: string;
12
+ /**
13
+ * Commit and build time of the hosted image (DEVX-4). The Dockerfile turns
14
+ * the GIT_SHA and BUILD_TIME build args into environment variables of the
15
+ * runtime stage. Anything built without them (npm package, local checkout,
16
+ * a plain `docker compose build`) reports "unknown".
17
+ */
18
+ export declare const UNKNOWN_BUILD = "unknown";
19
+ export declare function readBuildValue(name: 'GIT_SHA' | 'BUILD_TIME', env?: NodeJS.ProcessEnv): string;
20
+ export declare const GIT_SHA: string;
21
+ export declare const BUILD_TIME: string;
22
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/lib/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAIH,wBAAgB,kBAAkB,IAAI,MAAM,CAU3C;AAED,eAAO,MAAM,eAAe,QAAuB,CAAC;AAEpD;;;;;GAKG;AACH,eAAO,MAAM,aAAa,YAAY,CAAC;AAEvC,wBAAgB,cAAc,CAAC,IAAI,EAAE,SAAS,GAAG,YAAY,EAAE,GAAG,GAAE,MAAM,CAAC,UAAwB,GAAG,MAAM,CAG3G;AAED,eAAO,MAAM,OAAO,QAA4B,CAAC;AACjD,eAAO,MAAM,UAAU,QAA+B,CAAC"}
@@ -0,0 +1,36 @@
1
+ /**
2
+ * The package version, read from package.json at runtime.
3
+ *
4
+ * Both entry points (stdio `index.ts` and hosted `http.ts`) report this
5
+ * version, so /health and the MCP `initialize` handshake always match the
6
+ * code that is actually running. The compiled file lives at
7
+ * dist/lib/version.js, so ../../package.json is the package root in the
8
+ * npm tarball, in a local checkout and in the Docker image (/app).
9
+ */
10
+ import { readFileSync } from 'node:fs';
11
+ export function readPackageVersion() {
12
+ try {
13
+ const pkg = JSON.parse(readFileSync(new URL('../../package.json', import.meta.url), 'utf8'));
14
+ if (typeof pkg.version === 'string' && pkg.version !== '')
15
+ return pkg.version;
16
+ }
17
+ catch {
18
+ // fall through: a missing package.json is a packaging bug, not a crash
19
+ }
20
+ return '0.0.0-unknown';
21
+ }
22
+ export const PACKAGE_VERSION = readPackageVersion();
23
+ /**
24
+ * Commit and build time of the hosted image (DEVX-4). The Dockerfile turns
25
+ * the GIT_SHA and BUILD_TIME build args into environment variables of the
26
+ * runtime stage. Anything built without them (npm package, local checkout,
27
+ * a plain `docker compose build`) reports "unknown".
28
+ */
29
+ export const UNKNOWN_BUILD = 'unknown';
30
+ export function readBuildValue(name, env = process.env) {
31
+ const value = (env[name] ?? '').trim();
32
+ return value === '' ? UNKNOWN_BUILD : value;
33
+ }
34
+ export const GIT_SHA = readBuildValue('GIT_SHA');
35
+ export const BUILD_TIME = readBuildValue('BUILD_TIME');
36
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/lib/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,MAAM,UAAU,kBAAkB;IAChC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,GAAG,CAAC,oBAAoB,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,MAAM,CAAC,CAE1F,CAAC;QACF,IAAI,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,IAAI,GAAG,CAAC,OAAO,KAAK,EAAE;YAAE,OAAO,GAAG,CAAC,OAAO,CAAC;IAChF,CAAC;IAAC,MAAM,CAAC;QACP,uEAAuE;IACzE,CAAC;IACD,OAAO,eAAe,CAAC;AACzB,CAAC;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,kBAAkB,EAAE,CAAC;AAEpD;;;;;GAKG;AACH,MAAM,CAAC,MAAM,aAAa,GAAG,SAAS,CAAC;AAEvC,MAAM,UAAU,cAAc,CAAC,IAA8B,EAAE,MAAyB,OAAO,CAAC,GAAG;IACjG,MAAM,KAAK,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACvC,OAAO,KAAK,KAAK,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,KAAK,CAAC;AAC9C,CAAC;AAED,MAAM,CAAC,MAAM,OAAO,GAAG,cAAc,CAAC,SAAS,CAAC,CAAC;AACjD,MAAM,CAAC,MAAM,UAAU,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * oauth-proxy.ts — Phase 65/Pattern-A precursor. Transparent reverse proxy
3
+ * in front of Supabase OAuth Server that strips `openid` from the scope
4
+ * parameter on /authorize requests, working around the Supabase OIDC bug
5
+ * (HTTP 500 "Error generating ID token" — error_id 019e41f7-…).
6
+ *
7
+ * Why this exists: removing `openid` from our /.well-known/oauth-protected-
8
+ * resource metadata's `scopes_supported` only works if the client
9
+ * (Claude.ai) actually respects the advertised list. RFC 9728 says it
10
+ * SHOULD, but if the client hardcodes openid it'll still trigger the bug.
11
+ * This proxy is a hard safety net — no matter what scope the client sends,
12
+ * Supabase never sees `openid` in the request.
13
+ *
14
+ * What the proxy does:
15
+ * GET /auth/v1/.well-known/oauth-authorization-server → rewritten metadata
16
+ * POST /auth/v1/oauth/clients/register → transparent forward
17
+ * GET /auth/v1/oauth/authorize?scope=… → strip openid → forward
18
+ * POST /auth/v1/oauth/token → transparent forward
19
+ * GET /auth/v1/oauth/userinfo → transparent forward
20
+ * GET /auth/v1/.well-known/jwks.json → transparent forward
21
+ * any other GET/POST under /auth/v1/ → transparent forward
22
+ *
23
+ * Redirects are followed by curl/SDK clients themselves; our proxy passes
24
+ * the Location header through unchanged (Supabase emits redirects to
25
+ * sota.io/oauth/authorize which is our consent UI and stays valid).
26
+ *
27
+ * Activation: registered on the same Express app as /mcp via mountOAuthProxy().
28
+ */
29
+ import type { Express } from 'express';
30
+ export declare function mountOAuthProxy(app: Express, publicOrigin: string): void;
31
+ //# sourceMappingURL=oauth-proxy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"oauth-proxy.d.ts","sourceRoot":"","sources":["../src/oauth-proxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH,OAAO,KAAK,EAAqB,OAAO,EAAE,MAAM,SAAS,CAAC;AAmI1D,wBAAgB,eAAe,CAAC,GAAG,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,GAAG,IAAI,CAyExE"}
@@ -0,0 +1,212 @@
1
+ /**
2
+ * oauth-proxy.ts — Phase 65/Pattern-A precursor. Transparent reverse proxy
3
+ * in front of Supabase OAuth Server that strips `openid` from the scope
4
+ * parameter on /authorize requests, working around the Supabase OIDC bug
5
+ * (HTTP 500 "Error generating ID token" — error_id 019e41f7-…).
6
+ *
7
+ * Why this exists: removing `openid` from our /.well-known/oauth-protected-
8
+ * resource metadata's `scopes_supported` only works if the client
9
+ * (Claude.ai) actually respects the advertised list. RFC 9728 says it
10
+ * SHOULD, but if the client hardcodes openid it'll still trigger the bug.
11
+ * This proxy is a hard safety net — no matter what scope the client sends,
12
+ * Supabase never sees `openid` in the request.
13
+ *
14
+ * What the proxy does:
15
+ * GET /auth/v1/.well-known/oauth-authorization-server → rewritten metadata
16
+ * POST /auth/v1/oauth/clients/register → transparent forward
17
+ * GET /auth/v1/oauth/authorize?scope=… → strip openid → forward
18
+ * POST /auth/v1/oauth/token → transparent forward
19
+ * GET /auth/v1/oauth/userinfo → transparent forward
20
+ * GET /auth/v1/.well-known/jwks.json → transparent forward
21
+ * any other GET/POST under /auth/v1/ → transparent forward
22
+ *
23
+ * Redirects are followed by curl/SDK clients themselves; our proxy passes
24
+ * the Location header through unchanged (Supabase emits redirects to
25
+ * sota.io/oauth/authorize which is our consent UI and stays valid).
26
+ *
27
+ * Activation: registered on the same Express app as /mcp via mountOAuthProxy().
28
+ */
29
+ import { resolveAuthUpstream } from './lib/auth-config.js';
30
+ // AUTH_SERVER (compose: ${SUPABASE_URL}/auth/v1); default = prod
31
+ // https://auth.sota.io/auth/v1. Invalid values throw here = fail at startup.
32
+ const UPSTREAM = resolveAuthUpstream();
33
+ /**
34
+ * Strip `openid` from a space-separated scope string. Returns the cleaned
35
+ * value, or undefined when nothing remains (caller should omit the param).
36
+ */
37
+ function stripOpenidScope(raw) {
38
+ if (!raw)
39
+ return raw;
40
+ const cleaned = raw
41
+ .split(/\s+/)
42
+ .filter((s) => s.length > 0 && s.toLowerCase() !== 'openid')
43
+ .join(' ');
44
+ return cleaned.length === 0 ? undefined : cleaned;
45
+ }
46
+ /**
47
+ * Build a rewritten OIDC discovery document that points all endpoints at
48
+ * mcp.sota.io's proxy rather than auth.sota.io directly. This is the entry
49
+ * point that makes the proxy actually do anything — Claude.ai reads this
50
+ * once and uses these URLs for the rest of the flow.
51
+ */
52
+ function rewriteMetadata(upstreamMetadata, publicOrigin) {
53
+ const base = `${publicOrigin}/auth/v1`;
54
+ return {
55
+ ...upstreamMetadata,
56
+ issuer: upstreamMetadata.issuer, // keep Supabase's issuer so JWT validation still works
57
+ authorization_endpoint: `${base}/oauth/authorize`,
58
+ token_endpoint: `${base}/oauth/token`,
59
+ userinfo_endpoint: `${base}/oauth/userinfo`,
60
+ jwks_uri: `${base}/.well-known/jwks.json`,
61
+ registration_endpoint: `${base}/oauth/clients/register`,
62
+ // Crucially: drop openid from advertised scopes so well-behaved clients
63
+ // skip it. The /authorize strip-pass is the belt-and-braces backup.
64
+ scopes_supported: Array.isArray(upstreamMetadata.scopes_supported)
65
+ ? upstreamMetadata.scopes_supported.filter((s) => typeof s === 'string' && s.toLowerCase() !== 'openid')
66
+ : ['profile', 'email'],
67
+ };
68
+ }
69
+ /**
70
+ * Forward an HTTP request to Supabase OAuth Server transparently. Preserves
71
+ * method, headers (except Host), query string, and body. Returns the
72
+ * upstream response untouched.
73
+ *
74
+ * Express has already body-parsed POST JSON for us when content-type was
75
+ * application/json (set up at top of http.ts). For x-www-form-urlencoded
76
+ * we need to re-serialise from req.body. Other content types pass through
77
+ * as best we can — DCR and token endpoints use JSON / form-encoded only.
78
+ */
79
+ async function forward(req, targetPath, targetQuery) {
80
+ const url = `${UPSTREAM}${targetPath}${targetQuery ?? ''}`;
81
+ const isForm = typeof req.headers['content-type'] === 'string' &&
82
+ req.headers['content-type'].includes('application/x-www-form-urlencoded');
83
+ // Reconstruct body — express.json() leaves it as a parsed object, so we
84
+ // re-serialise based on the original content-type.
85
+ let body;
86
+ if (req.method !== 'GET' && req.method !== 'HEAD') {
87
+ if (isForm) {
88
+ const params = new URLSearchParams();
89
+ for (const [k, v] of Object.entries(req.body ?? {})) {
90
+ if (typeof v === 'string')
91
+ params.append(k, v);
92
+ else if (Array.isArray(v))
93
+ v.forEach((x) => params.append(k, String(x)));
94
+ }
95
+ body = params.toString();
96
+ }
97
+ else if (req.body && typeof req.body === 'object') {
98
+ body = JSON.stringify(req.body);
99
+ }
100
+ else if (typeof req.body === 'string') {
101
+ body = req.body;
102
+ }
103
+ }
104
+ const headers = {};
105
+ for (const [k, v] of Object.entries(req.headers)) {
106
+ if (typeof v !== 'string')
107
+ continue;
108
+ // Strip hop-by-hop and host headers; the host gets recomputed by fetch.
109
+ if (['host', 'connection', 'content-length', 'accept-encoding'].includes(k.toLowerCase())) {
110
+ continue;
111
+ }
112
+ headers[k] = v;
113
+ }
114
+ const upstreamRes = await fetch(url, {
115
+ method: req.method,
116
+ headers,
117
+ body,
118
+ redirect: 'manual',
119
+ });
120
+ return upstreamRes;
121
+ }
122
+ async function streamUpstreamResponse(upstream, res) {
123
+ const r = upstream;
124
+ // Mirror headers EXCEPT hop-by-hop ones.
125
+ r.headers.forEach((value, key) => {
126
+ if (['content-encoding', 'transfer-encoding', 'connection'].includes(key.toLowerCase())) {
127
+ return;
128
+ }
129
+ res.setHeader(key, value);
130
+ });
131
+ res.status(r.status);
132
+ const buf = Buffer.from(await r.arrayBuffer());
133
+ res.end(buf);
134
+ }
135
+ export function mountOAuthProxy(app, publicOrigin) {
136
+ // 1) Rewritten metadata document.
137
+ app.get('/auth/v1/.well-known/oauth-authorization-server', async (_req, res) => {
138
+ try {
139
+ const upstream = await fetch(`${UPSTREAM}/.well-known/oauth-authorization-server`);
140
+ const json = (await upstream.json());
141
+ const rewritten = rewriteMetadata(json, publicOrigin);
142
+ res.json(rewritten);
143
+ }
144
+ catch (err) {
145
+ res.status(502).json({
146
+ error: 'metadata_fetch_failed',
147
+ message: err instanceof Error ? err.message : String(err),
148
+ });
149
+ }
150
+ });
151
+ // 2) /authorize — strip openid from the scope before forwarding.
152
+ app.get('/auth/v1/oauth/authorize', async (req, res) => {
153
+ try {
154
+ const params = new URLSearchParams();
155
+ for (const [k, v] of Object.entries(req.query)) {
156
+ if (typeof v === 'string')
157
+ params.set(k, v);
158
+ else if (Array.isArray(v) && typeof v[0] === 'string')
159
+ params.set(k, v[0]);
160
+ }
161
+ const cleanedScope = stripOpenidScope(params.get('scope') ?? undefined);
162
+ if (cleanedScope === undefined) {
163
+ params.delete('scope');
164
+ }
165
+ else {
166
+ params.set('scope', cleanedScope);
167
+ }
168
+ const upstream = await forward(req, '/oauth/authorize', '?' + params.toString());
169
+ if (!upstream) {
170
+ res.status(502).end();
171
+ return;
172
+ }
173
+ await streamUpstreamResponse(upstream, res);
174
+ }
175
+ catch (err) {
176
+ res.status(502).json({
177
+ error: 'proxy_error',
178
+ message: err instanceof Error ? err.message : String(err),
179
+ });
180
+ }
181
+ });
182
+ // 3) All other /auth/v1/* paths — transparent forward.
183
+ app.all('/auth/v1/*', async (req, res) => {
184
+ try {
185
+ // Some clients (and SDKs) send scope to other endpoints too; strip it
186
+ // defensively wherever it appears in a query string.
187
+ const url = new URL(`http://x${req.originalUrl}`);
188
+ if (url.searchParams.has('scope')) {
189
+ const cleaned = stripOpenidScope(url.searchParams.get('scope') ?? undefined);
190
+ if (cleaned === undefined)
191
+ url.searchParams.delete('scope');
192
+ else
193
+ url.searchParams.set('scope', cleaned);
194
+ }
195
+ const path = url.pathname.replace(/^\/auth\/v1/, '');
196
+ const query = url.search;
197
+ const upstream = await forward(req, path, query || undefined);
198
+ if (!upstream) {
199
+ res.status(502).end();
200
+ return;
201
+ }
202
+ await streamUpstreamResponse(upstream, res);
203
+ }
204
+ catch (err) {
205
+ res.status(502).json({
206
+ error: 'proxy_error',
207
+ message: err instanceof Error ? err.message : String(err),
208
+ });
209
+ }
210
+ });
211
+ }
212
+ //#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AK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;aAC1D,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"create-account.d.ts","sourceRoot":"","sources":["../../src/tools/create-account.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAcpE,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,QA+K1D"}
1
+ {"version":3,"file":"create-account.d.ts","sourceRoot":"","sources":["../../src/tools/create-account.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAcpE,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,SAAS,QAqM1D"}