@sota-io/mcp 1.4.1 → 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 (54) 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 +79 -0
  19. package/dist/lib/archive-builder.d.ts.map +1 -0
  20. package/dist/lib/archive-builder.js +292 -0
  21. package/dist/lib/archive-builder.js.map +1 -0
  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 +135 -47
  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/dist/tools/projects.d.ts.map +1 -1
  52. package/dist/tools/projects.js +13 -4
  53. package/dist/tools/projects.js.map +1 -1
  54. package/package.json +11 -10
@@ -0,0 +1,292 @@
1
+ /**
2
+ * Archive Builder — turn AI-supplied source into a tar.gz ready for upload.
3
+ *
4
+ * Three input modes for the `deploy` MCP tool:
5
+ * 1. directory: string — existing CLI/Claude-Code flow
6
+ * 2. files: Record<string,string> — inline source from AI agent
7
+ * 3. git_url: string + git_branch?: string — clone a public repo
8
+ *
9
+ * All three produce a tar.gz Buffer that the SDK uploads to
10
+ * `POST /v1/projects/:id/deploy` via multipart/form-data. The backend
11
+ * accepts the multipart upload identically regardless of source.
12
+ *
13
+ * Limits (deliberately generous — we want to lean permissive at launch):
14
+ * files: MAX_INLINE_FILES entries, MAX_INLINE_TOTAL_BYTES total
15
+ * git_url: MAX_CLONE_BYTES of archived files after `git clone --depth=1`
16
+ *
17
+ * The hosted server (mcp.sota.io) only uses `files`; directory and git_url
18
+ * are local (stdio) modes, see tools/deploy.ts and lib/hosted-guard.ts.
19
+ *
20
+ * Security:
21
+ * - .git, node_modules, .DS_Store and the local/secret env files (.env,
22
+ * .env.local, .env.*.local, .envrc; any depth, any case) are left out
23
+ * of every archive, whatever the mode.
24
+ * - git and tar run via execFile (no shell).
25
+ * - Inline file paths are normalised + rejected if they contain ".." or
26
+ * start with "/" or contain NUL.
27
+ * - Symlinks are not honoured for inline files (we only write regular files).
28
+ * - Git clone uses `--depth=1` and `--single-branch` to bound bandwidth.
29
+ * - Both modes write to a fresh /tmp dir which is removed after tar.gz is read.
30
+ */
31
+ import { execFileSync } from 'child_process';
32
+ import { lstatSync, mkdtempSync, mkdirSync, readdirSync, writeFileSync, readFileSync, rmSync, statSync, } from 'fs';
33
+ import { tmpdir } from 'os';
34
+ import { dirname, join, resolve, sep } from 'path';
35
+ /**
36
+ * Names excluded from every archive, at any directory depth, in any case:
37
+ * the local/secret env files `.env`, `.env.local`, `.env.<anything>.local`
38
+ * and direnv's `.envrc`. Committed variants such as `.env.production`,
39
+ * `.env.development`, `.env.test` and `.env.example` are KEPT: sota builds
40
+ * (railpack, docker build) never see set-env values, so apps rely on them
41
+ * for build-time values like NEXT_PUBLIC_*.
42
+ */
43
+ const LOCAL_ENV_FILE = /^\.env(?:(?:\.[^/]+)?\.local|rc)?$/i;
44
+ export function isExcludedName(name) {
45
+ if (name === '.git' || name === 'node_modules' || name === '.DS_Store')
46
+ return true;
47
+ return LOCAL_ENV_FILE.test(name);
48
+ }
49
+ /** Upper bound on inline file count (per single `deploy` call). */
50
+ export const MAX_INLINE_FILES = 200;
51
+ /** Upper bound on combined inline content length, in bytes. */
52
+ export const MAX_INLINE_TOTAL_BYTES = 10 * 1024 * 1024; // 10 MB
53
+ /** Upper bound on a cloned git repo, in bytes: the summed size of the files the tree walk would archive (collectEntries), so excluded paths such as .git do not count. */
54
+ export const MAX_CLONE_BYTES = 200 * 1024 * 1024; // 200 MB
55
+ /** Upper bound on path component count, to defeat absurd nesting attacks. */
56
+ const MAX_PATH_DEPTH = 32;
57
+ export class ArchiveBuilderError extends Error {
58
+ code;
59
+ constructor(code, message) {
60
+ super(message);
61
+ this.code = code;
62
+ this.name = 'ArchiveBuilderError';
63
+ }
64
+ }
65
+ /**
66
+ * Pack a record of file paths → text content into a tar.gz Buffer.
67
+ *
68
+ * Each value is treated as UTF-8 text. Binary assets are not supported in
69
+ * this mode — use `archiveFromGitUrl` for that. The caller is responsible
70
+ * for including framework manifests (package.json, requirements.txt, or a
71
+ * Dockerfile) so the backend's auto-detection picks the right builder.
72
+ */
73
+ export function archiveFromFiles(files) {
74
+ const entries = Object.entries(files);
75
+ if (entries.length === 0) {
76
+ throw new ArchiveBuilderError('empty_files', 'files map cannot be empty');
77
+ }
78
+ if (entries.length > MAX_INLINE_FILES) {
79
+ throw new ArchiveBuilderError('too_many_files', `files map has ${entries.length} entries (max ${MAX_INLINE_FILES})`);
80
+ }
81
+ let totalBytes = 0;
82
+ const sanitised = [];
83
+ for (const [rawPath, content] of entries) {
84
+ const safePath = sanitiseInlinePath(rawPath);
85
+ const buf = Buffer.from(content, 'utf8');
86
+ totalBytes += buf.byteLength;
87
+ if (totalBytes > MAX_INLINE_TOTAL_BYTES) {
88
+ throw new ArchiveBuilderError('inline_too_large', `combined content exceeds ${MAX_INLINE_TOTAL_BYTES} bytes`);
89
+ }
90
+ sanitised.push([safePath, buf]);
91
+ }
92
+ const workdir = mkdtempSync(join(tmpdir(), 'sota-inline-'));
93
+ try {
94
+ for (const [path, buf] of sanitised) {
95
+ const abs = join(workdir, path);
96
+ mkdirSync(dirname(abs), { recursive: true });
97
+ writeFileSync(abs, buf);
98
+ }
99
+ return tarGzWorkdir(workdir);
100
+ }
101
+ finally {
102
+ rmSync(workdir, { recursive: true, force: true });
103
+ }
104
+ }
105
+ /**
106
+ * `git clone --depth=1` the given URL (optionally on a specified branch),
107
+ * then pack the resulting workdir into a tar.gz Buffer. Only public repos
108
+ * are supported in v1 — there is no credential plumbing.
109
+ *
110
+ * Rejects URLs that don't begin with https://, http://, git://, ssh://, or
111
+ * the scp-like git@host:path form, to keep the surface predictable.
112
+ */
113
+ export function archiveFromGitUrl(gitUrl, gitBranch) {
114
+ const url = gitUrl.trim();
115
+ if (!isPlausibleGitURL(url)) {
116
+ throw new ArchiveBuilderError('bad_git_url', `git_url must look like a URL (https://, git://, ssh://, or git@host:path) — got: ${url.slice(0, 80)}`);
117
+ }
118
+ if (url.length > 2000) {
119
+ throw new ArchiveBuilderError('bad_git_url', 'git_url too long (max 2000 chars)');
120
+ }
121
+ const branch = gitBranch ? gitBranch.trim() : '';
122
+ if (branch && !/^[\w./\-]{1,255}$/.test(branch)) {
123
+ throw new ArchiveBuilderError('bad_git_branch', 'git_branch contains invalid characters or exceeds 255 chars');
124
+ }
125
+ const workdir = mkdtempSync(join(tmpdir(), 'sota-git-'));
126
+ try {
127
+ // Cap clone bandwidth/time. `--depth=1` cuts history to the tip commit.
128
+ // `--single-branch` avoids fetching all refs.
129
+ const args = ['clone', '--depth=1', '--single-branch'];
130
+ if (branch) {
131
+ args.push('--branch', branch);
132
+ }
133
+ args.push('--', url, workdir);
134
+ try {
135
+ execFileSync('git', args, {
136
+ stdio: 'pipe',
137
+ timeout: 120_000,
138
+ });
139
+ }
140
+ catch (err) {
141
+ const detail = err instanceof Error ? err.message : String(err);
142
+ throw new ArchiveBuilderError('git_clone_failed', `git clone failed (URL=${url.slice(0, 120)}${branch ? `, branch=${branch}` : ''}): ${detail.slice(0, 300)}`);
143
+ }
144
+ // Hard size cap: refuse repos that ballooned past MAX_CLONE_BYTES.
145
+ const sizeBytes = collectEntries(workdir).totalBytes;
146
+ if (sizeBytes > MAX_CLONE_BYTES) {
147
+ throw new ArchiveBuilderError('clone_too_large', `cloned repo is ${(sizeBytes / 1024 / 1024).toFixed(1)} MB (max ${(MAX_CLONE_BYTES / 1024 / 1024).toFixed(0)} MB)`);
148
+ }
149
+ return tarGzWorkdir(workdir);
150
+ }
151
+ finally {
152
+ rmSync(workdir, { recursive: true, force: true });
153
+ }
154
+ }
155
+ /**
156
+ * Pack an existing local directory into a tar.gz Buffer using the same
157
+ * ignore rules as every other mode (see isExcludedName: .git, node_modules,
158
+ * .DS_Store and the local/secret .env files). Exported so the deploy tool can re-use a
159
+ * single code path for archive construction.
160
+ */
161
+ export function archiveFromDirectory(dir) {
162
+ const abs = resolve(dir);
163
+ let isDir = false;
164
+ try {
165
+ isDir = statSync(abs).isDirectory();
166
+ }
167
+ catch {
168
+ throw new ArchiveBuilderError('not_found', `Directory not found: ${abs}`);
169
+ }
170
+ if (!isDir) {
171
+ throw new ArchiveBuilderError('not_a_directory', `Not a directory: ${abs}`);
172
+ }
173
+ return tarGzWorkdir(abs);
174
+ }
175
+ /**
176
+ * Walk `root` and return the archive entries ("./rel/path", parents before
177
+ * children) plus the byte size of the regular files. Excluded names are
178
+ * skipped at every depth, and excluded directories are not descended into.
179
+ * Symlinks are archived as links and never followed.
180
+ */
181
+ export function collectEntries(root) {
182
+ const entries = [];
183
+ let totalBytes = 0;
184
+ const walk = (absDir, relDir) => {
185
+ const dirents = readdirSync(absDir, { withFileTypes: true }).sort((a, b) => a.name < b.name ? -1 : a.name > b.name ? 1 : 0);
186
+ for (const d of dirents) {
187
+ if (isExcludedName(d.name))
188
+ continue;
189
+ const abs = join(absDir, d.name);
190
+ const rel = `${relDir}/${d.name}`;
191
+ entries.push(rel);
192
+ if (d.isDirectory()) {
193
+ walk(abs, rel);
194
+ }
195
+ else if (d.isFile()) {
196
+ totalBytes += lstatSync(abs).size;
197
+ }
198
+ }
199
+ };
200
+ walk(root, '.');
201
+ return { entries, totalBytes };
202
+ }
203
+ function tarGzWorkdir(workdir) {
204
+ const { entries } = collectEntries(workdir);
205
+ // The explicit NUL-separated file list (instead of tar --exclude patterns)
206
+ // makes the exclusions identical on GNU tar and bsdtar (macOS, Windows)
207
+ // and case-insensitive for the .env names.
208
+ const scratch = mkdtempSync(join(tmpdir(), 'sota-deploy-'));
209
+ const archivePath = join(scratch, 'source.tar.gz');
210
+ const listPath = join(scratch, 'files.list');
211
+ try {
212
+ writeFileSync(listPath, entries.map((e) => `${e}\0`).join(''));
213
+ try {
214
+ execFileSync('tar', ['-czf', archivePath, '-C', workdir, '--no-recursion', '--null', '-T', listPath], { stdio: 'pipe' });
215
+ }
216
+ catch (err) {
217
+ if (!isUnknownNullOption(err))
218
+ throw tarFailed(err);
219
+ // BusyBox tar (Alpine) has no --null. It reads the list line by line
220
+ // and takes every line literally, so a newline-separated list is the
221
+ // same thing as long as no name contains a newline.
222
+ if (entries.some((e) => e.includes('\n'))) {
223
+ throw new ArchiveBuilderError('tar_failed', 'a file name contains a line break, and the tar on this system (BusyBox) cannot pack such names; rename the file or install GNU tar');
224
+ }
225
+ rmSync(archivePath, { force: true });
226
+ writeFileSync(listPath, entries.map((e) => `${e}\n`).join(''));
227
+ try {
228
+ execFileSync('tar', ['-czf', archivePath, '-C', workdir, '--no-recursion', '-T', listPath], { stdio: 'pipe' });
229
+ }
230
+ catch (err2) {
231
+ throw tarFailed(err2);
232
+ }
233
+ }
234
+ return readFileSync(archivePath);
235
+ }
236
+ finally {
237
+ rmSync(scratch, { recursive: true, force: true });
238
+ }
239
+ }
240
+ function tarStderr(err) {
241
+ const raw = err?.stderr;
242
+ return raw ? raw.toString() : err instanceof Error ? err.message : String(err);
243
+ }
244
+ /** True when tar refused to start because it does not know `--null`. */
245
+ export function isUnknownNullOption(err) {
246
+ const text = tarStderr(err);
247
+ return /(unrecognized|unknown|invalid|illegal) option/i.test(text) && /null/i.test(text);
248
+ }
249
+ function tarFailed(err) {
250
+ return new ArchiveBuilderError('tar_failed', `could not pack the source archive: ${tarStderr(err).trim().slice(0, 300)}`);
251
+ }
252
+ function sanitiseInlinePath(raw) {
253
+ if (!raw || typeof raw !== 'string') {
254
+ throw new ArchiveBuilderError('bad_path', 'file path must be a non-empty string');
255
+ }
256
+ if (raw.includes('\0')) {
257
+ throw new ArchiveBuilderError('bad_path', 'file path contains NUL byte');
258
+ }
259
+ if (raw.length > 1024) {
260
+ throw new ArchiveBuilderError('bad_path', `file path too long (max 1024 chars): ${raw.slice(0, 80)}…`);
261
+ }
262
+ // Strip leading "./" and "/"; reject ".." segments.
263
+ let p = raw.replace(/^\.?\//, '').replace(/\\/g, '/');
264
+ if (p.startsWith('/')) {
265
+ p = p.slice(1);
266
+ }
267
+ if (p === '' || p === '.' || p === '..') {
268
+ throw new ArchiveBuilderError('bad_path', `invalid file path: ${raw}`);
269
+ }
270
+ const segments = p.split('/');
271
+ if (segments.length > MAX_PATH_DEPTH) {
272
+ throw new ArchiveBuilderError('bad_path', `path too deep (${segments.length} segments, max ${MAX_PATH_DEPTH}): ${raw}`);
273
+ }
274
+ for (const seg of segments) {
275
+ if (seg === '' || seg === '.' || seg === '..') {
276
+ throw new ArchiveBuilderError('bad_path', `invalid path segment in: ${raw}`);
277
+ }
278
+ }
279
+ return segments.join(sep);
280
+ }
281
+ function isPlausibleGitURL(s) {
282
+ if (s.startsWith('https://') || s.startsWith('http://'))
283
+ return true;
284
+ if (s.startsWith('git://'))
285
+ return true;
286
+ if (s.startsWith('ssh://'))
287
+ return true;
288
+ if (s.startsWith('git@') && s.includes(':'))
289
+ return true;
290
+ return false;
291
+ }
292
+ //# sourceMappingURL=archive-builder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"archive-builder.js","sourceRoot":"","sources":["../../src/lib/archive-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EACL,SAAS,EACT,WAAW,EACX,SAAS,EACT,WAAW,EACX,aAAa,EACb,YAAY,EACZ,MAAM,EACN,QAAQ,GACT,MAAM,IAAI,CAAC;AACZ,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAC5B,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,MAAM,CAAC;AAEnD;;;;;;;GAOG;AACH,MAAM,cAAc,GAAG,qCAAqC,CAAC;AAE7D,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,IAAI,IAAI,KAAK,MAAM,IAAI,IAAI,KAAK,cAAc,IAAI,IAAI,KAAK,WAAW;QAAE,OAAO,IAAI,CAAC;IACpF,OAAO,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AACnC,CAAC;AAED,mEAAmE;AACnE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C,MAAM,IAAI,mBAAmB,CAAC,UAAU,EAAE,4BAA4B,GAAG,EAAE,CAAC,CAAC;QAC/E,CAAC;IACH,CAAC;IACD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAED,SAAS,iBAAiB,CAAC,CAAS;IAClC,IAAI,CAAC,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,UAAU,CAAC,SAAS,CAAC;QAAE,OAAO,IAAI,CAAC;IACrE,IAAI,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,IAAI,CAAC,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IACxC,IAAI,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IACzD,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -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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IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QACpE,IAAI,YAAY,KAAK,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC;YAChD,MAAM,IAAI,KAAK,CAAC,yBAAyB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,8BAA8B,CAAC,CAAC;QAC9F,CAAC;QACD,IAAI,GAAG,CAAC,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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C,IAAI,CAAC;QAC9E,OAAO;YACL,EAAE;YACF,OAAO,EAAE,iDAAiD,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,sBAAsB,EAAE;SACnI,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
@@ -0,0 +1,17 @@
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
+ 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"}