@sota-io/mcp 1.5.0 → 1.7.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.
- package/CLAUDE.md +19 -4
- package/README.md +11 -4
- package/dist/auth/token-bridge.d.ts +16 -0
- package/dist/auth/token-bridge.d.ts.map +1 -1
- package/dist/auth/token-bridge.js +49 -9
- package/dist/auth/token-bridge.js.map +1 -1
- package/dist/auth/verify-jwt.js +6 -6
- package/dist/auth/verify-jwt.js.map +1 -1
- package/dist/http-app.d.ts +27 -0
- package/dist/http-app.d.ts.map +1 -0
- package/dist/http-app.js +324 -0
- package/dist/http-app.js.map +1 -0
- package/dist/http.d.ts +3 -15
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +13 -251
- package/dist/http.js.map +1 -1
- package/dist/index.js +11 -4
- package/dist/index.js.map +1 -1
- package/dist/lib/account.d.ts +63 -0
- package/dist/lib/account.d.ts.map +1 -0
- package/dist/lib/account.js +64 -0
- package/dist/lib/account.js.map +1 -0
- package/dist/lib/archive-builder.d.ts +39 -5
- package/dist/lib/archive-builder.d.ts.map +1 -1
- package/dist/lib/archive-builder.js +131 -37
- package/dist/lib/archive-builder.js.map +1 -1
- package/dist/lib/auth-config.d.ts +37 -0
- package/dist/lib/auth-config.d.ts.map +1 -0
- package/dist/lib/auth-config.js +95 -0
- package/dist/lib/auth-config.js.map +1 -0
- package/dist/lib/guide.d.ts +33 -0
- package/dist/lib/guide.d.ts.map +1 -0
- package/dist/lib/guide.js +82 -0
- package/dist/lib/guide.js.map +1 -0
- package/dist/lib/hosted-guard.d.ts +26 -0
- package/dist/lib/hosted-guard.d.ts.map +1 -0
- package/dist/lib/hosted-guard.js +48 -0
- package/dist/lib/hosted-guard.js.map +1 -0
- package/dist/lib/ignore.d.ts +16 -0
- package/dist/lib/ignore.d.ts.map +1 -0
- package/dist/lib/ignore.js +131 -0
- package/dist/lib/ignore.js.map +1 -0
- package/dist/lib/log.d.ts +17 -0
- package/dist/lib/log.d.ts.map +1 -0
- package/dist/lib/log.js +41 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/project-url.d.ts +14 -0
- package/dist/lib/project-url.d.ts.map +1 -0
- package/dist/lib/project-url.js +16 -0
- package/dist/lib/project-url.js.map +1 -0
- package/dist/lib/version.d.ts +22 -0
- package/dist/lib/version.d.ts.map +1 -0
- package/dist/lib/version.js +36 -0
- package/dist/lib/version.js.map +1 -0
- package/dist/oauth-proxy.d.ts +31 -0
- package/dist/oauth-proxy.d.ts.map +1 -0
- package/dist/oauth-proxy.js +212 -0
- package/dist/oauth-proxy.js.map +1 -0
- package/dist/tools/account.d.ts +10 -0
- package/dist/tools/account.d.ts.map +1 -0
- package/dist/tools/account.js +104 -0
- package/dist/tools/account.js.map +1 -0
- package/dist/tools/create-account.d.ts.map +1 -1
- package/dist/tools/create-account.js +23 -1
- package/dist/tools/create-account.js.map +1 -1
- package/dist/tools/deploy.d.ts +19 -1
- package/dist/tools/deploy.d.ts.map +1 -1
- package/dist/tools/deploy.js +129 -77
- package/dist/tools/deploy.js.map +1 -1
- package/dist/tools/env.js +2 -2
- package/dist/tools/env.js.map +1 -1
- package/dist/tools/logs.js +1 -1
- package/dist/tools/logs.js.map +1 -1
- package/dist/tools/projects.d.ts +8 -1
- package/dist/tools/projects.d.ts.map +1 -1
- package/dist/tools/projects.js +13 -5
- package/dist/tools/projects.js.map +1 -1
- package/dist/tools/status.d.ts.map +1 -1
- package/dist/tools/status.js +8 -3
- package/dist/tools/status.js.map +1 -1
- package/package.json +1 -1
package/CLAUDE.md
CHANGED
|
@@ -29,8 +29,8 @@ sota.io is an EU-native DevOps PaaS. Deploy any web app and get a live URL at `{
|
|
|
29
29
|
|
|
30
30
|
## Database — How It Works
|
|
31
31
|
|
|
32
|
-
1. Create a project
|
|
33
|
-
2. Deploy your app → `DATABASE_URL`
|
|
32
|
+
1. Create a project.
|
|
33
|
+
2. Deploy your app → the first deploy creates the PostgreSQL 17 database and injects `DATABASE_URL` into the container.
|
|
34
34
|
3. Your app reads `DATABASE_URL` from the environment — that's it.
|
|
35
35
|
|
|
36
36
|
You do NOT need to:
|
|
@@ -57,7 +57,9 @@ Full migration guide: https://sota.io/docs/guides/postgresql
|
|
|
57
57
|
- `DATABASE_URL` — PostgreSQL connection string (auto-injected).
|
|
58
58
|
- Custom vars set via `set-env` tool are encrypted at rest (AES-256-GCM).
|
|
59
59
|
- Changing env vars does NOT auto-redeploy. Deploy again to apply.
|
|
60
|
-
- Next.js `NEXT_PUBLIC_*`
|
|
60
|
+
- `set-env` values are runtime only. Next.js `NEXT_PUBLIC_*` (build-time) values belong in a committed file such as `.env.production`.
|
|
61
|
+
- Secrets never go into an uploaded file. A folder deploy uses `.sotaignore` (or the `.gitignore`, which never drops `.env.production` or `.env.example`); `.env`, `.env.local`, `.env.*.local` and `.envrc` are always left out.
|
|
62
|
+
- Enterprise: apps on the same server can call each other without the sign-in and can forge identity headers; protect app-to-app calls with your own shared secret.
|
|
61
63
|
|
|
62
64
|
## Custom Domains
|
|
63
65
|
|
|
@@ -74,9 +76,22 @@ Manage via API:
|
|
|
74
76
|
- `GET /v1/projects/:id/domains/:domainId` — Get domain with DNS instructions
|
|
75
77
|
- `DELETE /v1/projects/:id/domains/:domainId` — Remove domain
|
|
76
78
|
|
|
79
|
+
## sota Enterprise accounts
|
|
80
|
+
|
|
81
|
+
Call the `get-account` tool first. On a sota Enterprise account (company label `<label>`):
|
|
82
|
+
|
|
83
|
+
- The app lives at `https://<app>.<label>.sota.io` behind the company's Microsoft 365 sign-in (sota Access). Never build a login.
|
|
84
|
+
- Read `X-Sota-Access-User-Id`, `X-Sota-Access-Email` (lower-case it) and `X-Sota-Access-Name`; no role in the headers.
|
|
85
|
+
- Fail closed (401) without `X-Sota-Access-User-Id`, EXCEPT `GET /health` (200) and `GET /` (2xx/3xx, no data): the health gate and the edge check call them without identity.
|
|
86
|
+
- Sign out: `/.sota/access/logout`. No public paths yet (no webhooks from outside).
|
|
87
|
+
- After a deploy nobody can open the app until the owner approves people and ticks the app under Users & access in the dashboard. MCP cannot do that: tell the human.
|
|
88
|
+
|
|
89
|
+
Full checklist: the `enterprise-app-checklist` prompt or https://sota.io/docs/enterprise/build-with-ai
|
|
90
|
+
|
|
77
91
|
## Deployment Workflow for AI Agents
|
|
78
92
|
|
|
79
93
|
```
|
|
94
|
+
0. get-account → Enterprise or not, limits, contract
|
|
80
95
|
1. create-project "My App" → get project_id
|
|
81
96
|
2. (write your app code) → must listen on PORT
|
|
82
97
|
3. deploy project_id ./my-app → uploads & builds
|
|
@@ -120,7 +135,7 @@ module.exports = { output: 'standalone' }
|
|
|
120
135
|
| Build fails | Check `get-logs` for missing dependencies or build errors. |
|
|
121
136
|
| App not accessible | Use `get-status` — must show "running". Check health check (60s timeout). |
|
|
122
137
|
| Env vars not applied | Changing env vars requires redeployment. Call `deploy` again. |
|
|
123
|
-
| Next.js NEXT_PUBLIC_* empty |
|
|
138
|
+
| Next.js NEXT_PUBLIC_* empty | `set-env` values are not visible at build time; put them in a committed `.env.production`. |
|
|
124
139
|
| Migrations not running | Start script must chain migration before server. Example: `"start": "npx prisma db push && node server.js"` |
|
|
125
140
|
| `prepared statement already exists` | PgBouncer conflict — add `?pgbouncer=true` to DATABASE_URL in Prisma schema. |
|
|
126
141
|
|
package/README.md
CHANGED
|
@@ -147,8 +147,9 @@ Edit `~/.codeium/windsurf/mcp_config.json`:
|
|
|
147
147
|
|
|
148
148
|
| Tool | Description | Parameters |
|
|
149
149
|
|------|-------------|------------|
|
|
150
|
-
| `
|
|
151
|
-
| `
|
|
150
|
+
| `get-account` | Plan limits, Enterprise facts and the build contract (call first) | *(none)* |
|
|
151
|
+
| `deploy` | Deploy an app | `project_id`, one of `files` / `git_url` / `directory` |
|
|
152
|
+
| `get-logs` | Get the build and deploy log | `project_id`, `deployment_id?` |
|
|
152
153
|
| `set-env` | Set environment variable | `project_id`, `key`, `value` |
|
|
153
154
|
| `get-env` | List environment variables | `project_id` |
|
|
154
155
|
| `rollback` | Rollback to previous deployment | `project_id` |
|
|
@@ -163,20 +164,26 @@ Edit `~/.codeium/windsurf/mcp_config.json`:
|
|
|
163
164
|
|
|
164
165
|
### `deploy`
|
|
165
166
|
|
|
166
|
-
Deploy an application to sota.io.
|
|
167
|
+
Deploy an application to sota.io. Builds a tar.gz archive from one source and uploads it.
|
|
167
168
|
|
|
168
169
|
| Parameter | Type | Required | Description |
|
|
169
170
|
|-----------|------|----------|-------------|
|
|
170
171
|
| `project_id` | string | Yes | Project ID to deploy to |
|
|
172
|
+
| `files` | object | No | Map of relative path to UTF-8 content (inline source) |
|
|
173
|
+
| `git_url` | string | No | Public git repository to shallow-clone with the local `git` (`git_branch` optional) |
|
|
171
174
|
| `directory` | string | No | Directory to deploy (defaults to current working directory) |
|
|
172
175
|
|
|
176
|
+
`.git/`, `node_modules/`, `.DS_Store` and the local/secret env files `.env`, `.env.local`, `.env.*.local` and `.envrc` (any depth, any case) are never archived; set runtime secrets with `set-env`. Committed variants such as `.env.production`, `.env.development`, `.env.test` and `.env.example` are kept, because builds do not see `set-env` values (e.g. `NEXT_PUBLIC_*`).
|
|
177
|
+
|
|
178
|
+
The hosted server (`https://mcp.sota.io/mcp`) accepts `files` only: it has no access to your filesystem, and it rejects `directory` and `git_url`. Use this local server or `sota deploy` for those.
|
|
179
|
+
|
|
173
180
|
```
|
|
174
181
|
"Deploy my app in the current directory to sota.io"
|
|
175
182
|
```
|
|
176
183
|
|
|
177
184
|
### `get-logs`
|
|
178
185
|
|
|
179
|
-
Get build and
|
|
186
|
+
Get the build and deploy log of a deployment (no runtime logs). If no deployment_id is provided, returns logs for the latest deployment.
|
|
180
187
|
|
|
181
188
|
| Parameter | Type | Required | Description |
|
|
182
189
|
|-----------|------|----------|-------------|
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TLS settings for the pg pool from DATABASE_URL.
|
|
3
|
+
*
|
|
4
|
+
* - `sslmode=verify-full&sslrootcert=<file>` (the self-hosted platform DB,
|
|
5
|
+
* GDPR-3): the server certificate must chain to <file> and name the URL's
|
|
6
|
+
* host (an IP address is checked against the certificate's IP SANs; pg
|
|
7
|
+
* itself sends no SNI for an IP, so the check is done here explicitly).
|
|
8
|
+
* - anything else (the Supabase pooler, whose CA chain pg cannot verify by
|
|
9
|
+
* default): encrypted, not verified, as before.
|
|
10
|
+
* Both parameters are removed from the connection string: the ssl object is
|
|
11
|
+
* the only TLS input pg gets.
|
|
12
|
+
*/
|
|
13
|
+
export declare function poolTls(url: string, readFile?: (p: string) => string): {
|
|
14
|
+
connectionString: string;
|
|
15
|
+
ssl: Record<string, unknown>;
|
|
16
|
+
};
|
|
1
17
|
export interface BridgeResult {
|
|
2
18
|
/** The sota_xxx key plaintext to forward to sota-api on this request */
|
|
3
19
|
apiKey: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-bridge.d.ts","sourceRoot":"","sources":["../../src/auth/token-bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"token-bridge.d.ts","sourceRoot":"","sources":["../../src/auth/token-bridge.ts"],"names":[],"mappings":"AA6CA;;;;;;;;;;;GAWG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,GAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAA0C,GAAG;IACzG,gBAAgB,EAAE,MAAM,CAAC;IACzB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAC9B,CAsBA;AAoDD,MAAM,WAAW,YAAY;IAC3B,wEAAwE;IACxE,MAAM,EAAE,MAAM,CAAC;IACf,2EAA2E;IAC3E,OAAO,EAAE,OAAO,CAAC;IACjB,yFAAyF;IACzF,OAAO,EAAE,OAAO,CAAC;CAClB;AAED;;;;;;;;GAQG;AACH,wBAAsB,mBAAmB,CACvC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,YAAY,CAAC,CAyBvB;AAED;;;;;;;GAOG;AACH,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,YAAY,CAAC,CAqCvB"}
|
|
@@ -36,28 +36,64 @@
|
|
|
36
36
|
* key is current.
|
|
37
37
|
*/
|
|
38
38
|
import crypto from "node:crypto";
|
|
39
|
+
import fs from "node:fs";
|
|
40
|
+
import tls from "node:tls";
|
|
39
41
|
import { Pool } from "pg";
|
|
42
|
+
import { errorMessage, logEvent } from "../lib/log.js";
|
|
40
43
|
const DATABASE_URL = process.env.DATABASE_URL ?? "";
|
|
44
|
+
/**
|
|
45
|
+
* TLS settings for the pg pool from DATABASE_URL.
|
|
46
|
+
*
|
|
47
|
+
* - `sslmode=verify-full&sslrootcert=<file>` (the self-hosted platform DB,
|
|
48
|
+
* GDPR-3): the server certificate must chain to <file> and name the URL's
|
|
49
|
+
* host (an IP address is checked against the certificate's IP SANs; pg
|
|
50
|
+
* itself sends no SNI for an IP, so the check is done here explicitly).
|
|
51
|
+
* - anything else (the Supabase pooler, whose CA chain pg cannot verify by
|
|
52
|
+
* default): encrypted, not verified, as before.
|
|
53
|
+
* Both parameters are removed from the connection string: the ssl object is
|
|
54
|
+
* the only TLS input pg gets.
|
|
55
|
+
*/
|
|
56
|
+
export function poolTls(url, readFile = (p) => fs.readFileSync(p, "utf8")) {
|
|
57
|
+
const permissive = { rejectUnauthorized: false, require: true };
|
|
58
|
+
let u;
|
|
59
|
+
try {
|
|
60
|
+
u = new URL(url);
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return { connectionString: url.replace(/[?&]sslmode=[^&]*/i, ""), ssl: permissive };
|
|
64
|
+
}
|
|
65
|
+
const mode = u.searchParams.get("sslmode");
|
|
66
|
+
const rootcert = u.searchParams.get("sslrootcert");
|
|
67
|
+
u.searchParams.delete("sslmode");
|
|
68
|
+
u.searchParams.delete("sslrootcert");
|
|
69
|
+
const connectionString = u.toString();
|
|
70
|
+
if (mode === "verify-full" || mode === "verify-ca") {
|
|
71
|
+
if (!rootcert)
|
|
72
|
+
throw new Error(`DATABASE_URL: sslmode=${mode} needs sslrootcert=<file>`);
|
|
73
|
+
const host = u.hostname.replace(/^\[|\]$/g, "");
|
|
74
|
+
const ssl = { ca: readFile(rootcert), rejectUnauthorized: true };
|
|
75
|
+
ssl.checkServerIdentity =
|
|
76
|
+
mode === "verify-full" ? (_h, cert) => tls.checkServerIdentity(host, cert) : () => undefined;
|
|
77
|
+
return { connectionString, ssl };
|
|
78
|
+
}
|
|
79
|
+
return { connectionString, ssl: permissive };
|
|
80
|
+
}
|
|
41
81
|
let pool = null;
|
|
42
82
|
function getPool() {
|
|
43
83
|
if (!pool) {
|
|
44
84
|
if (!DATABASE_URL) {
|
|
45
85
|
throw new Error("DATABASE_URL not configured — sota-mcp cannot bridge tokens to API keys");
|
|
46
86
|
}
|
|
47
|
-
|
|
48
|
-
// ?sslmode= from the URL and force a permissive TLS config explicitly,
|
|
49
|
-
// matching what the rest of the sota.io stack does.
|
|
50
|
-
const cleanUrl = DATABASE_URL.replace(/[?&]sslmode=[^&]*/i, "");
|
|
87
|
+
const { connectionString, ssl } = poolTls(DATABASE_URL);
|
|
51
88
|
pool = new Pool({
|
|
52
|
-
connectionString
|
|
89
|
+
connectionString,
|
|
53
90
|
max: 5,
|
|
54
91
|
idleTimeoutMillis: 30_000,
|
|
55
|
-
ssl:
|
|
92
|
+
ssl: ssl,
|
|
56
93
|
});
|
|
57
94
|
pool.on("error", (err) => {
|
|
58
95
|
// Best-effort logging; pool keeps working across single-conn errors
|
|
59
|
-
|
|
60
|
-
console.error("pg pool error:", err.message);
|
|
96
|
+
logEvent("error", { event: "pg_pool_error", error_message: errorMessage(err) });
|
|
61
97
|
});
|
|
62
98
|
}
|
|
63
99
|
return pool;
|
|
@@ -98,7 +134,11 @@ function generateKey() {
|
|
|
98
134
|
export async function provisionPlanAndKey(userId) {
|
|
99
135
|
const client = await getPool().connect();
|
|
100
136
|
try {
|
|
101
|
-
// Free-tier defaults (mirrors
|
|
137
|
+
// Free-tier defaults (mirrors the free row of the API's plans catalog,
|
|
138
|
+
// migration 039 / model.DefaultPlans).
|
|
139
|
+
// TODO(BILL-3 PR 3 / MCP-2): this insert goes away when the bridge stops
|
|
140
|
+
// writing plans; until then a change of the free row's limits must be
|
|
141
|
+
// mirrored here.
|
|
102
142
|
await client.query(`INSERT INTO user_plans (
|
|
103
143
|
user_id, plan, max_projects, max_memory_mb, max_cpu_millicores,
|
|
104
144
|
max_databases, max_custom_domains, max_builds_per_day,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-bridge.js","sourceRoot":"","sources":["../../src/auth/token-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"token-bridge.js","sourceRoot":"","sources":["../../src/auth/token-bridge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,EAAE,IAAI,EAAE,MAAM,IAAI,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEvD,MAAM,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,EAAE,CAAC;AAEpD;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,OAAO,CAAC,GAAW,EAAE,WAAkC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC;IAItG,MAAM,UAAU,GAAG,EAAE,kBAAkB,EAAE,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;IAChE,I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,OAAO,EAAE,CAAC;IACnB,CAAC;AACH,CAAC"}
|
package/dist/auth/verify-jwt.js
CHANGED
|
@@ -8,8 +8,8 @@
|
|
|
8
8
|
* Acceptance criteria for a valid token (RFC 8707 audience binding partially):
|
|
9
9
|
* - signature verifies with the configured HS256 secret
|
|
10
10
|
* - exp not in the past, nbf not in the future
|
|
11
|
-
* - iss
|
|
12
|
-
*
|
|
11
|
+
* - iss is one of the accepted issuers (env SUPABASE_JWT_ISSUERS + the
|
|
12
|
+
* AUTH_SERVER upstream; default: we accept BOTH the project-ref URL and the custom-domain URL — Supabase
|
|
13
13
|
* Custom Domain doesn't rewrite the iss claim in May 2026, see Phase 56
|
|
14
14
|
* SUMMARY.md "Caveats" section)
|
|
15
15
|
* - sub is a non-empty UUID-shaped string
|
|
@@ -21,11 +21,11 @@
|
|
|
21
21
|
* block every incoming token)
|
|
22
22
|
*/
|
|
23
23
|
import { jwtVerify, errors as joseErrors } from "jose";
|
|
24
|
+
import { resolveAcceptedIssuers } from "../lib/auth-config.js";
|
|
24
25
|
const SUPABASE_JWT_SECRET = process.env.SUPABASE_JWT_SECRET ?? "";
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
];
|
|
26
|
+
// SUPABASE_JWT_ISSUERS (default: the two prod issuers) plus the AUTH_SERVER
|
|
27
|
+
// upstream; see lib/auth-config.ts. Invalid values throw = fail at startup.
|
|
28
|
+
const ACCEPTED_ISSUERS = resolveAcceptedIssuers();
|
|
29
29
|
if (!SUPABASE_JWT_SECRET) {
|
|
30
30
|
// Server still boots, but every incoming token will fail validation.
|
|
31
31
|
// This keeps health checks alive while signalling a missing config.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"verify-jwt.js","sourceRoot":"","sources":["../../src/auth/verify-jwt.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,UAAU,EAAE,MAAM,MAAM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ACpB,CAAC;QACJ,CAAC;QACD,MAAM,IAAI,oBAAoB,CAC5B,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAChD,SAAS,CACV,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sota.io MCP Server — HTTP Transport (remote)
|
|
3
|
+
*
|
|
4
|
+
* Streamable HTTP variant of the existing stdio MCP server, exposed via
|
|
5
|
+
* mcp.sota.io/mcp for one-click installation from Claude Desktop and
|
|
6
|
+
* Claude.ai. The entry point is http.ts; this module builds the Express app
|
|
7
|
+
* so tests can run it on an ephemeral port.
|
|
8
|
+
*
|
|
9
|
+
* Hosted differences from stdio (MCP-1): `deploy` accepts inline `files`
|
|
10
|
+
* only (no `directory`, no `git_url`), enforced by the tool schema, by
|
|
11
|
+
* hostedDeployRejection() before any tool runs and by the tool itself. Logs
|
|
12
|
+
* carry user ids, never emails.
|
|
13
|
+
*
|
|
14
|
+
* Phase 57-01 (this file): scaffold + transport + RFC 9728 metadata.
|
|
15
|
+
* Auth is currently a pass-through Bearer API key — clients send their
|
|
16
|
+
* existing sota_xxx key as `Authorization: Bearer <key>` and it gets
|
|
17
|
+
* forwarded to sota-api. No OAuth validation yet.
|
|
18
|
+
*
|
|
19
|
+
* Phase 57-02 (next): OAuth 2.1 + JWT validation against Supabase JWKS,
|
|
20
|
+
* token-to-API-key bridge with `source=claude` audit tagging.
|
|
21
|
+
*
|
|
22
|
+
* Phase 57-03 (next): `create_account` tool for net-new user signup from
|
|
23
|
+
* inside Claude + plan-based capability gating.
|
|
24
|
+
*/
|
|
25
|
+
export declare const PUBLIC_ORIGIN: string;
|
|
26
|
+
export declare const app: import("express-serve-static-core").Express;
|
|
27
|
+
//# sourceMappingURL=http-app.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-app.d.ts","sourceRoot":"","sources":["../src/http-app.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AA2DH,eAAO,MAAM,aAAa,QAAqD,CAAC;AAKhF,eAAO,MAAM,GAAG,6CAAY,CAAC"}
|
package/dist/http-app.js
ADDED
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* sota.io MCP Server — HTTP Transport (remote)
|
|
3
|
+
*
|
|
4
|
+
* Streamable HTTP variant of the existing stdio MCP server, exposed via
|
|
5
|
+
* mcp.sota.io/mcp for one-click installation from Claude Desktop and
|
|
6
|
+
* Claude.ai. The entry point is http.ts; this module builds the Express app
|
|
7
|
+
* so tests can run it on an ephemeral port.
|
|
8
|
+
*
|
|
9
|
+
* Hosted differences from stdio (MCP-1): `deploy` accepts inline `files`
|
|
10
|
+
* only (no `directory`, no `git_url`), enforced by the tool schema, by
|
|
11
|
+
* hostedDeployRejection() before any tool runs and by the tool itself. Logs
|
|
12
|
+
* carry user ids, never emails.
|
|
13
|
+
*
|
|
14
|
+
* Phase 57-01 (this file): scaffold + transport + RFC 9728 metadata.
|
|
15
|
+
* Auth is currently a pass-through Bearer API key — clients send their
|
|
16
|
+
* existing sota_xxx key as `Authorization: Bearer <key>` and it gets
|
|
17
|
+
* forwarded to sota-api. No OAuth validation yet.
|
|
18
|
+
*
|
|
19
|
+
* Phase 57-02 (next): OAuth 2.1 + JWT validation against Supabase JWKS,
|
|
20
|
+
* token-to-API-key bridge with `source=claude` audit tagging.
|
|
21
|
+
*
|
|
22
|
+
* Phase 57-03 (next): `create_account` tool for net-new user signup from
|
|
23
|
+
* inside Claude + plan-based capability gating.
|
|
24
|
+
*/
|
|
25
|
+
import crypto from 'node:crypto';
|
|
26
|
+
import express from 'express';
|
|
27
|
+
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
28
|
+
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
29
|
+
import { SotaClient } from '@sota-io/sdk';
|
|
30
|
+
import { registerProjectTools } from './tools/projects.js';
|
|
31
|
+
import { registerDeployTool } from './tools/deploy.js';
|
|
32
|
+
import { registerLogsTool } from './tools/logs.js';
|
|
33
|
+
import { registerEnvTools } from './tools/env.js';
|
|
34
|
+
import { registerRollbackTool } from './tools/rollback.js';
|
|
35
|
+
import { registerStatusTool } from './tools/status.js';
|
|
36
|
+
import { registerDomainTools } from './tools/domains.js';
|
|
37
|
+
import { verifyJwt, JwtVerificationError } from './auth/verify-jwt.js';
|
|
38
|
+
import { getOrProvisionApiKey } from './auth/token-bridge.js';
|
|
39
|
+
import { registerCreateAccountTool } from './tools/create-account.js';
|
|
40
|
+
import { mountOAuthProxy } from './oauth-proxy.js';
|
|
41
|
+
import { hostedDeployRejection } from './lib/hosted-guard.js';
|
|
42
|
+
import { errorMessage, logEvent } from './lib/log.js';
|
|
43
|
+
import { BUILD_TIME, GIT_SHA, PACKAGE_VERSION } from './lib/version.js';
|
|
44
|
+
import { registerAccountTool, registerChecklistPrompt } from './tools/account.js';
|
|
45
|
+
import { accountReader } from './lib/account.js';
|
|
46
|
+
import { SERVER_INSTRUCTIONS } from './lib/guide.js';
|
|
47
|
+
// Tools that may be invoked WITHOUT authentication. Currently only
|
|
48
|
+
// create_account — net-new users obviously don't have an API key yet.
|
|
49
|
+
// Discovery requests (initialize, tools/list) are also allowed
|
|
50
|
+
// unauthenticated so Claude can fetch capabilities before OAuth.
|
|
51
|
+
const UNAUTHENTICATED_TOOLS = new Set(['create_account']);
|
|
52
|
+
// MCP handshake + tools/list are reachable without auth so Claude.ai's
|
|
53
|
+
// connector UI can render the tool catalogue (it shows "Konnektor hat keine
|
|
54
|
+
// Tools verfügbar" otherwise — a dead-end state for the user). The
|
|
55
|
+
// per-tool-call 401 + WWW-Authenticate is the actual OAuth trigger.
|
|
56
|
+
// prompts/list and prompts/get serve only the static Enterprise checklist
|
|
57
|
+
// (no API call, no account data), so they need no token either (261125-mcg).
|
|
58
|
+
const UNAUTHENTICATED_METHODS = new Set([
|
|
59
|
+
'initialize',
|
|
60
|
+
'notifications/initialized',
|
|
61
|
+
'tools/list',
|
|
62
|
+
'prompts/list',
|
|
63
|
+
'prompts/get',
|
|
64
|
+
]);
|
|
65
|
+
function isUnauthenticatedAllowed(body) {
|
|
66
|
+
if (!body || typeof body !== 'object')
|
|
67
|
+
return false;
|
|
68
|
+
const b = body;
|
|
69
|
+
const method = typeof b.method === 'string' ? b.method : '';
|
|
70
|
+
if (UNAUTHENTICATED_METHODS.has(method))
|
|
71
|
+
return true;
|
|
72
|
+
if (method === 'tools/call') {
|
|
73
|
+
const params = (b.params ?? {});
|
|
74
|
+
const name = typeof params.name === 'string' ? params.name : '';
|
|
75
|
+
return UNAUTHENTICATED_TOOLS.has(name);
|
|
76
|
+
}
|
|
77
|
+
return false;
|
|
78
|
+
}
|
|
79
|
+
const SOTA_API_URL = process.env.SOTA_API_URL ?? 'https://api.sota.io';
|
|
80
|
+
export const PUBLIC_ORIGIN = process.env.PUBLIC_ORIGIN ?? 'https://mcp.sota.io';
|
|
81
|
+
// Always the version of the running package (package.json), never an env
|
|
82
|
+
// override: /health must say which code is deployed.
|
|
83
|
+
const VERSION = PACKAGE_VERSION;
|
|
84
|
+
export const app = express();
|
|
85
|
+
app.use(express.json({ limit: '4mb' }));
|
|
86
|
+
// Required for the /auth/v1/oauth/token proxy passthrough — Supabase's
|
|
87
|
+
// token endpoint expects application/x-www-form-urlencoded bodies.
|
|
88
|
+
app.use(express.urlencoded({ extended: true, limit: '64kb' }));
|
|
89
|
+
// Phase-65/Pattern-A precursor: transparent reverse proxy in front of
|
|
90
|
+
// Supabase OAuth Server that strips the `openid` scope before forwarding.
|
|
91
|
+
// Activated regardless of metadata-advertised scopes — see oauth-proxy.ts.
|
|
92
|
+
mountOAuthProxy(app, PUBLIC_ORIGIN);
|
|
93
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
94
|
+
// /health — Traefik / Docker healthcheck target
|
|
95
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
96
|
+
app.get('/health', (_req, res) => {
|
|
97
|
+
res.json({
|
|
98
|
+
ok: true,
|
|
99
|
+
service: 'sota-mcp',
|
|
100
|
+
version: VERSION,
|
|
101
|
+
// DEVX-4: which commit this image was built from ("unknown" without the
|
|
102
|
+
// GIT_SHA/BUILD_TIME build args). `version` stays the package version.
|
|
103
|
+
commit: GIT_SHA,
|
|
104
|
+
built_at: BUILD_TIME,
|
|
105
|
+
transport: 'streamable-http',
|
|
106
|
+
ts: new Date().toISOString(),
|
|
107
|
+
});
|
|
108
|
+
});
|
|
109
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
110
|
+
// RFC 9728 Protected Resource Metadata
|
|
111
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
112
|
+
// MCP clients fetch this BEFORE attempting auth. It points them at the
|
|
113
|
+
// Authorization Server (Supabase) and declares the audience binding.
|
|
114
|
+
// Spec: https://datatracker.ietf.org/doc/html/rfc9728
|
|
115
|
+
// MCP requirement: https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization
|
|
116
|
+
app.get('/.well-known/oauth-protected-resource', (_req, res) => {
|
|
117
|
+
res.json({
|
|
118
|
+
resource: PUBLIC_ORIGIN,
|
|
119
|
+
// Point clients at OUR proxy instead of auth.sota.io directly. The
|
|
120
|
+
// proxy strips `openid` from /authorize requests so Supabase never
|
|
121
|
+
// sees it — works around the Supabase OAuth Server 500 bug regardless
|
|
122
|
+
// of whether the client respects scopes_supported. The token is still
|
|
123
|
+
// signed by Supabase (we don't mint our own) so existing JWT
|
|
124
|
+
// validation against the Supabase issuer keeps working.
|
|
125
|
+
authorization_servers: [`${PUBLIC_ORIGIN}/auth/v1`],
|
|
126
|
+
bearer_methods_supported: ['header'],
|
|
127
|
+
resource_documentation: 'https://sota.io/docs/integrations/claude',
|
|
128
|
+
// 'openid' deliberately omitted: Supabase OAuth Server (May 2026)
|
|
129
|
+
// returns a 500 "Error generating ID token" on /oauth/token when the
|
|
130
|
+
// openid scope is requested. Without openid we get a working access
|
|
131
|
+
// token (HS256-signed JWT, iss=supabase, aud=authenticated) and the
|
|
132
|
+
// MCP flow completes end-to-end. Re-add openid once Supabase fixes
|
|
133
|
+
// their OIDC implementation; for now, identity claims (email, sub)
|
|
134
|
+
// ride along on the access token without an explicit ID token.
|
|
135
|
+
scopes_supported: ['profile', 'email'],
|
|
136
|
+
resource_signing_alg_values_supported: ['RS256', 'ES256'],
|
|
137
|
+
});
|
|
138
|
+
});
|
|
139
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
140
|
+
// /mcp — Streamable HTTP transport endpoint
|
|
141
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
142
|
+
// Stateless mode: every request gets a fresh McpServer + transport instance.
|
|
143
|
+
// Adequate for low-traffic; revisit if we see > 100 RPS sustained.
|
|
144
|
+
function unauthorized(res, reason, detail) {
|
|
145
|
+
res
|
|
146
|
+
.status(401)
|
|
147
|
+
.header('WWW-Authenticate', `Bearer realm="${PUBLIC_ORIGIN}", error="${reason}", resource_metadata="${PUBLIC_ORIGIN}/.well-known/oauth-protected-resource"`)
|
|
148
|
+
.json({ error: 'unauthorized', reason, detail });
|
|
149
|
+
}
|
|
150
|
+
async function handleMcpRequest(req, res) {
|
|
151
|
+
// ── MCP-1: the hosted deploy tool never takes directory / git_url ──
|
|
152
|
+
// Checked before auth and before the SDK parses the call, so no tool code
|
|
153
|
+
// runs for such a request whatever the token or the SDK's argument
|
|
154
|
+
// handling. JSON-RPC "invalid params" in an HTTP 400.
|
|
155
|
+
const rejection = hostedDeployRejection(req.body);
|
|
156
|
+
if (rejection) {
|
|
157
|
+
logEvent('warn', { event: 'hosted_deploy_mode_rejected', request_id: crypto.randomUUID() });
|
|
158
|
+
res.status(400).json({
|
|
159
|
+
jsonrpc: '2.0',
|
|
160
|
+
error: { code: -32602, message: rejection.message },
|
|
161
|
+
id: rejection.id,
|
|
162
|
+
});
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
// ── 57-02 Auth: OAuth JWT validation + token-to-key bridge ──
|
|
166
|
+
// Accept Bearer <jwt> (Claude/MCP path) OR Bearer <sota_xxx> (testing/CLI path).
|
|
167
|
+
// sota_-prefixed tokens skip JWT validation and pass through directly.
|
|
168
|
+
const authHeader = req.headers.authorization ?? '';
|
|
169
|
+
const rawToken = authHeader.startsWith('Bearer ')
|
|
170
|
+
? authHeader.slice('Bearer '.length).trim()
|
|
171
|
+
: '';
|
|
172
|
+
const startedAt = Date.now();
|
|
173
|
+
const auditMeta = {
|
|
174
|
+
request_id: crypto.randomUUID(),
|
|
175
|
+
started_at: new Date(startedAt).toISOString(),
|
|
176
|
+
};
|
|
177
|
+
// Anonymous path for discovery + create_account. The MCP server is still
|
|
178
|
+
// constructed, but with a "phantom" apiKey that never reaches sota-api
|
|
179
|
+
// (only the create_account tool is registered and it doesn't use SotaClient).
|
|
180
|
+
let apiKey = '';
|
|
181
|
+
const allowAnonymous = !rawToken && isUnauthenticatedAllowed(req.body);
|
|
182
|
+
if (!rawToken && !allowAnonymous) {
|
|
183
|
+
unauthorized(res, 'missing_token', 'Pass Authorization: Bearer <jwt>');
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (allowAnonymous) {
|
|
187
|
+
auditMeta.auth_path = 'anonymous';
|
|
188
|
+
apiKey = 'anonymous';
|
|
189
|
+
}
|
|
190
|
+
else if (rawToken.startsWith('sota_')) {
|
|
191
|
+
// Direct API-key path — legacy testing + CLI use, no OAuth involved.
|
|
192
|
+
apiKey = rawToken;
|
|
193
|
+
auditMeta.auth_path = 'direct_api_key';
|
|
194
|
+
auditMeta.key_prefix = rawToken.slice(0, 13);
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
// JWT path — Claude OAuth
|
|
198
|
+
try {
|
|
199
|
+
const claims = await verifyJwt(rawToken);
|
|
200
|
+
auditMeta.auth_path = 'jwt';
|
|
201
|
+
auditMeta.user_id = claims.sub;
|
|
202
|
+
auditMeta.iss = claims.iss;
|
|
203
|
+
const bridge = await getOrProvisionApiKey(claims.sub);
|
|
204
|
+
apiKey = bridge.apiKey;
|
|
205
|
+
auditMeta.key_provisioned = bridge.created;
|
|
206
|
+
auditMeta.key_rotated = bridge.rotated;
|
|
207
|
+
}
|
|
208
|
+
catch (err) {
|
|
209
|
+
if (err instanceof JwtVerificationError) {
|
|
210
|
+
logEvent('info', {
|
|
211
|
+
...auditMeta,
|
|
212
|
+
event: 'auth_failed',
|
|
213
|
+
error_code: err.code,
|
|
214
|
+
error_message: errorMessage(err),
|
|
215
|
+
});
|
|
216
|
+
unauthorized(res, err.code, err.message);
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
// Database / network problem during bridge — surface as 503, not 401
|
|
220
|
+
logEvent('error', {
|
|
221
|
+
...auditMeta,
|
|
222
|
+
event: 'bridge_error',
|
|
223
|
+
error_message: errorMessage(err),
|
|
224
|
+
});
|
|
225
|
+
res.status(503).json({
|
|
226
|
+
error: 'bridge_unavailable',
|
|
227
|
+
message: 'Could not provision an API key for this Claude session — try again in a moment.',
|
|
228
|
+
});
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
// Build a fresh MCP server per request (stateless mode).
|
|
233
|
+
const server = new McpServer({
|
|
234
|
+
name: 'sota',
|
|
235
|
+
version: VERSION,
|
|
236
|
+
title: 'sota.io',
|
|
237
|
+
}, { instructions: SERVER_INSTRUCTIONS });
|
|
238
|
+
// ALL tools are always registered so they show up in tools/list, regardless
|
|
239
|
+
// of whether the current request is authenticated. Why: when a client like
|
|
240
|
+
// Claude.ai discovers an MCP connector, it asks tools/list once. If we hide
|
|
241
|
+
// the 13 authenticated tools from that listing, the LLM only sees
|
|
242
|
+
// create_account and never tries to call deploy/list-projects/etc — which
|
|
243
|
+
// means the per-tool 401 → OAuth-redirect dance never triggers. The user
|
|
244
|
+
// is then stuck with one tool and no way to elevate.
|
|
245
|
+
//
|
|
246
|
+
// With all tools registered, the LLM sees the full catalog. When the user
|
|
247
|
+
// asks for any non-create_account tool, the tools/call middleware (above)
|
|
248
|
+
// returns 401 with WWW-Authenticate — that's the signal Claude.ai needs to
|
|
249
|
+
// open the OAuth popup. After OAuth completes, the retry has a valid token
|
|
250
|
+
// and the tool runs against api.sota.io with the user's real key.
|
|
251
|
+
//
|
|
252
|
+
// The phantom apiKey "anonymous" passed to SotaClient never actually hits
|
|
253
|
+
// api.sota.io because the middleware rejects unauthenticated tools/call
|
|
254
|
+
// for non-create_account before reaching the handler.
|
|
255
|
+
registerCreateAccountTool(server);
|
|
256
|
+
const client = new SotaClient({ apiKey: apiKey || 'anonymous', baseUrl: SOTA_API_URL });
|
|
257
|
+
const readAccount = accountReader(SOTA_API_URL, apiKey || 'anonymous');
|
|
258
|
+
registerAccountTool(server, readAccount);
|
|
259
|
+
registerChecklistPrompt(server);
|
|
260
|
+
registerProjectTools(server, client, { readAccount });
|
|
261
|
+
registerDeployTool(server, client, { hosted: true, readAccount });
|
|
262
|
+
registerLogsTool(server, client);
|
|
263
|
+
registerEnvTools(server, client);
|
|
264
|
+
registerRollbackTool(server, client);
|
|
265
|
+
registerStatusTool(server, client);
|
|
266
|
+
registerDomainTools(server, client);
|
|
267
|
+
// Stateless transport — no session header required.
|
|
268
|
+
const transport = new StreamableHTTPServerTransport({
|
|
269
|
+
sessionIdGenerator: undefined,
|
|
270
|
+
});
|
|
271
|
+
res.on('close', () => {
|
|
272
|
+
transport.close().catch(() => { });
|
|
273
|
+
server.close().catch(() => { });
|
|
274
|
+
});
|
|
275
|
+
try {
|
|
276
|
+
await server.connect(transport);
|
|
277
|
+
await transport.handleRequest(req, res, req.body);
|
|
278
|
+
// Structured audit log per request: user id (JWT sub), never the email.
|
|
279
|
+
logEvent('info', {
|
|
280
|
+
...auditMeta,
|
|
281
|
+
event: 'mcp_request',
|
|
282
|
+
method: req.body?.method,
|
|
283
|
+
duration_ms: Date.now() - startedAt,
|
|
284
|
+
});
|
|
285
|
+
}
|
|
286
|
+
catch (err) {
|
|
287
|
+
logEvent('error', {
|
|
288
|
+
...auditMeta,
|
|
289
|
+
event: 'mcp_error',
|
|
290
|
+
error_message: errorMessage(err),
|
|
291
|
+
duration_ms: Date.now() - startedAt,
|
|
292
|
+
});
|
|
293
|
+
if (!res.headersSent) {
|
|
294
|
+
res.status(500).json({
|
|
295
|
+
jsonrpc: '2.0',
|
|
296
|
+
error: { code: -32603, message: err instanceof Error ? err.message : String(err) },
|
|
297
|
+
id: null,
|
|
298
|
+
});
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
app.post('/mcp', handleMcpRequest);
|
|
303
|
+
app.get('/mcp', (_req, res) => {
|
|
304
|
+
// GET on /mcp without an active session = 405 Method Not Allowed.
|
|
305
|
+
// (Stateful mode would use GET for the SSE response stream; we're stateless.)
|
|
306
|
+
res.status(405).json({ error: 'method_not_allowed', allowed: 'POST' });
|
|
307
|
+
});
|
|
308
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
309
|
+
// Root index for humans hitting mcp.sota.io directly
|
|
310
|
+
// ───────────────────────────────────────────────────────────────────────────
|
|
311
|
+
app.get('/', (_req, res) => {
|
|
312
|
+
res.json({
|
|
313
|
+
service: 'sota-mcp',
|
|
314
|
+
version: VERSION,
|
|
315
|
+
description: 'MCP server for sota.io — EU-native PaaS. Use the Streamable HTTP transport at /mcp.',
|
|
316
|
+
docs: 'https://sota.io/docs/integrations/claude',
|
|
317
|
+
endpoints: {
|
|
318
|
+
health: `${PUBLIC_ORIGIN}/health`,
|
|
319
|
+
mcp: `${PUBLIC_ORIGIN}/mcp`,
|
|
320
|
+
protected_resource_metadata: `${PUBLIC_ORIGIN}/.well-known/oauth-protected-resource`,
|
|
321
|
+
},
|
|
322
|
+
});
|
|
323
|
+
});
|
|
324
|
+
//# sourceMappingURL=http-app.js.map
|