@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.
- package/README.md +8 -2
- 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 +310 -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 +2 -1
- package/dist/index.js.map +1 -1
- package/dist/lib/archive-builder.d.ts +79 -0
- package/dist/lib/archive-builder.d.ts.map +1 -0
- package/dist/lib/archive-builder.js +292 -0
- package/dist/lib/archive-builder.js.map +1 -0
- 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/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/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/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/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 +11 -1
- package/dist/tools/deploy.d.ts.map +1 -1
- package/dist/tools/deploy.js +135 -47
- package/dist/tools/deploy.js.map +1 -1
- package/dist/tools/env.js +1 -1
- package/dist/tools/env.js.map +1 -1
- package/dist/tools/projects.d.ts.map +1 -1
- package/dist/tools/projects.js +13 -4
- package/dist/tools/projects.js.map +1 -1
- package/package.json +11 -10
package/dist/http.js
CHANGED
|
@@ -1,259 +1,21 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* sota.io MCP Server — HTTP
|
|
3
|
+
* sota.io MCP Server — HTTP entry point (mcp.sota.io).
|
|
4
4
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* and Claude.ai.
|
|
8
|
-
*
|
|
9
|
-
* Phase 57-01 (this file): scaffold + transport + RFC 9728 metadata.
|
|
10
|
-
* Auth is currently a pass-through Bearer API key — clients send their
|
|
11
|
-
* existing sota_xxx key as `Authorization: Bearer <key>` and it gets
|
|
12
|
-
* forwarded to sota-api. No OAuth validation yet.
|
|
13
|
-
*
|
|
14
|
-
* Phase 57-02 (next): OAuth 2.1 + JWT validation against Supabase JWKS,
|
|
15
|
-
* token-to-API-key bridge with `source=claude` audit tagging.
|
|
16
|
-
*
|
|
17
|
-
* Phase 57-03 (next): `create_account` tool for net-new user signup from
|
|
18
|
-
* inside Claude + plan-based capability gating.
|
|
5
|
+
* The Express app lives in http-app.ts so tests can start it on an
|
|
6
|
+
* ephemeral port; this file only binds it.
|
|
19
7
|
*/
|
|
20
|
-
import
|
|
21
|
-
import
|
|
22
|
-
import {
|
|
23
|
-
import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/streamableHttp.js';
|
|
24
|
-
import { SotaClient } from '@sota-io/sdk';
|
|
25
|
-
import { registerProjectTools } from './tools/projects.js';
|
|
26
|
-
import { registerDeployTool } from './tools/deploy.js';
|
|
27
|
-
import { registerLogsTool } from './tools/logs.js';
|
|
28
|
-
import { registerEnvTools } from './tools/env.js';
|
|
29
|
-
import { registerRollbackTool } from './tools/rollback.js';
|
|
30
|
-
import { registerStatusTool } from './tools/status.js';
|
|
31
|
-
import { registerDomainTools } from './tools/domains.js';
|
|
32
|
-
import { verifyJwt, JwtVerificationError } from './auth/verify-jwt.js';
|
|
33
|
-
import { getOrProvisionApiKey } from './auth/token-bridge.js';
|
|
34
|
-
import { registerCreateAccountTool } from './tools/create-account.js';
|
|
35
|
-
// Tools that may be invoked WITHOUT authentication. Currently only
|
|
36
|
-
// create_account — net-new users obviously don't have an API key yet.
|
|
37
|
-
// Discovery requests (initialize, tools/list) are also allowed
|
|
38
|
-
// unauthenticated so Claude can fetch capabilities before OAuth.
|
|
39
|
-
const UNAUTHENTICATED_TOOLS = new Set(['create_account']);
|
|
40
|
-
const UNAUTHENTICATED_METHODS = new Set(['initialize', 'notifications/initialized', 'tools/list']);
|
|
41
|
-
function isUnauthenticatedAllowed(body) {
|
|
42
|
-
if (!body || typeof body !== 'object')
|
|
43
|
-
return false;
|
|
44
|
-
const b = body;
|
|
45
|
-
const method = typeof b.method === 'string' ? b.method : '';
|
|
46
|
-
if (UNAUTHENTICATED_METHODS.has(method))
|
|
47
|
-
return true;
|
|
48
|
-
if (method === 'tools/call') {
|
|
49
|
-
const params = (b.params ?? {});
|
|
50
|
-
const name = typeof params.name === 'string' ? params.name : '';
|
|
51
|
-
return UNAUTHENTICATED_TOOLS.has(name);
|
|
52
|
-
}
|
|
53
|
-
return false;
|
|
54
|
-
}
|
|
8
|
+
import { app, PUBLIC_ORIGIN } from './http-app.js';
|
|
9
|
+
import { logEvent } from './lib/log.js';
|
|
10
|
+
import { GIT_SHA, PACKAGE_VERSION } from './lib/version.js';
|
|
55
11
|
const PORT = Number(process.env.PORT ?? 8080);
|
|
56
|
-
const SOTA_API_URL = process.env.SOTA_API_URL ?? 'https://api.sota.io';
|
|
57
|
-
const PUBLIC_ORIGIN = process.env.PUBLIC_ORIGIN ?? 'https://mcp.sota.io';
|
|
58
|
-
const AUTH_SERVER = process.env.AUTH_SERVER ?? 'https://auth.sota.io/auth/v1';
|
|
59
|
-
const VERSION = process.env.MCP_SERVER_VERSION ?? '1.4.0-pre';
|
|
60
|
-
const app = express();
|
|
61
|
-
app.use(express.json({ limit: '4mb' }));
|
|
62
|
-
// ───────────────────────────────────────────────────────────────────────────
|
|
63
|
-
// /health — Traefik / Docker healthcheck target
|
|
64
|
-
// ───────────────────────────────────────────────────────────────────────────
|
|
65
|
-
app.get('/health', (_req, res) => {
|
|
66
|
-
res.json({
|
|
67
|
-
ok: true,
|
|
68
|
-
service: 'sota-mcp',
|
|
69
|
-
version: VERSION,
|
|
70
|
-
transport: 'streamable-http',
|
|
71
|
-
ts: new Date().toISOString(),
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
// ───────────────────────────────────────────────────────────────────────────
|
|
75
|
-
// RFC 9728 Protected Resource Metadata
|
|
76
|
-
// ───────────────────────────────────────────────────────────────────────────
|
|
77
|
-
// MCP clients fetch this BEFORE attempting auth. It points them at the
|
|
78
|
-
// Authorization Server (Supabase) and declares the audience binding.
|
|
79
|
-
// Spec: https://datatracker.ietf.org/doc/html/rfc9728
|
|
80
|
-
// MCP requirement: https://modelcontextprotocol.io/specification/2025-06-18/basic/authorization
|
|
81
|
-
app.get('/.well-known/oauth-protected-resource', (_req, res) => {
|
|
82
|
-
res.json({
|
|
83
|
-
resource: PUBLIC_ORIGIN,
|
|
84
|
-
authorization_servers: [AUTH_SERVER],
|
|
85
|
-
bearer_methods_supported: ['header'],
|
|
86
|
-
resource_documentation: 'https://sota.io/docs/integrations/claude',
|
|
87
|
-
scopes_supported: ['openid', 'profile', 'email'],
|
|
88
|
-
resource_signing_alg_values_supported: ['RS256', 'ES256'],
|
|
89
|
-
});
|
|
90
|
-
});
|
|
91
|
-
// ───────────────────────────────────────────────────────────────────────────
|
|
92
|
-
// /mcp — Streamable HTTP transport endpoint
|
|
93
|
-
// ───────────────────────────────────────────────────────────────────────────
|
|
94
|
-
// Stateless mode: every request gets a fresh McpServer + transport instance.
|
|
95
|
-
// Adequate for low-traffic; revisit if we see > 100 RPS sustained.
|
|
96
|
-
function unauthorized(res, reason, detail) {
|
|
97
|
-
res
|
|
98
|
-
.status(401)
|
|
99
|
-
.header('WWW-Authenticate', `Bearer realm="${PUBLIC_ORIGIN}", error="${reason}", resource_metadata="${PUBLIC_ORIGIN}/.well-known/oauth-protected-resource"`)
|
|
100
|
-
.json({ error: 'unauthorized', reason, detail });
|
|
101
|
-
}
|
|
102
|
-
async function handleMcpRequest(req, res) {
|
|
103
|
-
// ── 57-02 Auth: OAuth JWT validation + token-to-key bridge ──
|
|
104
|
-
// Accept Bearer <jwt> (Claude/MCP path) OR Bearer <sota_xxx> (testing/CLI path).
|
|
105
|
-
// sota_-prefixed tokens skip JWT validation and pass through directly.
|
|
106
|
-
const authHeader = req.headers.authorization ?? '';
|
|
107
|
-
const rawToken = authHeader.startsWith('Bearer ')
|
|
108
|
-
? authHeader.slice('Bearer '.length).trim()
|
|
109
|
-
: '';
|
|
110
|
-
const startedAt = Date.now();
|
|
111
|
-
const auditMeta = {
|
|
112
|
-
request_id: crypto.randomUUID(),
|
|
113
|
-
started_at: new Date(startedAt).toISOString(),
|
|
114
|
-
};
|
|
115
|
-
// Anonymous path for discovery + create_account. The MCP server is still
|
|
116
|
-
// constructed, but with a "phantom" apiKey that never reaches sota-api
|
|
117
|
-
// (only the create_account tool is registered and it doesn't use SotaClient).
|
|
118
|
-
let apiKey = '';
|
|
119
|
-
const allowAnonymous = !rawToken && isUnauthenticatedAllowed(req.body);
|
|
120
|
-
if (!rawToken && !allowAnonymous) {
|
|
121
|
-
unauthorized(res, 'missing_token', 'Pass Authorization: Bearer <jwt>');
|
|
122
|
-
return;
|
|
123
|
-
}
|
|
124
|
-
if (allowAnonymous) {
|
|
125
|
-
auditMeta.auth_path = 'anonymous';
|
|
126
|
-
apiKey = 'anonymous';
|
|
127
|
-
}
|
|
128
|
-
else if (rawToken.startsWith('sota_')) {
|
|
129
|
-
// Direct API-key path — legacy testing + CLI use, no OAuth involved.
|
|
130
|
-
apiKey = rawToken;
|
|
131
|
-
auditMeta.auth_path = 'direct_api_key';
|
|
132
|
-
auditMeta.key_prefix = rawToken.slice(0, 13);
|
|
133
|
-
}
|
|
134
|
-
else {
|
|
135
|
-
// JWT path — Claude OAuth
|
|
136
|
-
try {
|
|
137
|
-
const claims = await verifyJwt(rawToken);
|
|
138
|
-
auditMeta.auth_path = 'jwt';
|
|
139
|
-
auditMeta.user_id = claims.sub;
|
|
140
|
-
auditMeta.email = claims.email;
|
|
141
|
-
auditMeta.iss = claims.iss;
|
|
142
|
-
const bridge = await getOrProvisionApiKey(claims.sub);
|
|
143
|
-
apiKey = bridge.apiKey;
|
|
144
|
-
auditMeta.key_provisioned = bridge.created;
|
|
145
|
-
auditMeta.key_rotated = bridge.rotated;
|
|
146
|
-
}
|
|
147
|
-
catch (err) {
|
|
148
|
-
if (err instanceof JwtVerificationError) {
|
|
149
|
-
// eslint-disable-next-line no-console
|
|
150
|
-
console.log(JSON.stringify({
|
|
151
|
-
...auditMeta,
|
|
152
|
-
event: 'auth_failed',
|
|
153
|
-
error_code: err.code,
|
|
154
|
-
error_message: err.message,
|
|
155
|
-
}));
|
|
156
|
-
unauthorized(res, err.code, err.message);
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
// Database / network problem during bridge — surface as 503, not 401
|
|
160
|
-
// eslint-disable-next-line no-console
|
|
161
|
-
console.error(JSON.stringify({
|
|
162
|
-
...auditMeta,
|
|
163
|
-
event: 'bridge_error',
|
|
164
|
-
error_message: err instanceof Error ? err.message : String(err),
|
|
165
|
-
}));
|
|
166
|
-
res.status(503).json({
|
|
167
|
-
error: 'bridge_unavailable',
|
|
168
|
-
message: 'Could not provision an API key for this Claude session — try again in a moment.',
|
|
169
|
-
});
|
|
170
|
-
return;
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
// Build a fresh MCP server per request (stateless mode).
|
|
174
|
-
const server = new McpServer({
|
|
175
|
-
name: 'sota',
|
|
176
|
-
version: VERSION,
|
|
177
|
-
title: 'sota.io',
|
|
178
|
-
});
|
|
179
|
-
// create_account is registered ALWAYS — it's the wedge tool that lets
|
|
180
|
-
// brand-new users sign up from inside Claude before they have an API key.
|
|
181
|
-
registerCreateAccountTool(server);
|
|
182
|
-
// The sota-api-backed tools are only registered when the request carries
|
|
183
|
-
// valid auth. For anonymous requests (initialize / tools/list / tools/call
|
|
184
|
-
// create_account), the user just sees create_account in the catalog.
|
|
185
|
-
if (!allowAnonymous) {
|
|
186
|
-
const client = new SotaClient({ apiKey, baseUrl: SOTA_API_URL });
|
|
187
|
-
registerProjectTools(server, client);
|
|
188
|
-
registerDeployTool(server, client);
|
|
189
|
-
registerLogsTool(server, client);
|
|
190
|
-
registerEnvTools(server, client);
|
|
191
|
-
registerRollbackTool(server, client);
|
|
192
|
-
registerStatusTool(server, client);
|
|
193
|
-
registerDomainTools(server, client);
|
|
194
|
-
}
|
|
195
|
-
// Stateless transport — no session header required.
|
|
196
|
-
const transport = new StreamableHTTPServerTransport({
|
|
197
|
-
sessionIdGenerator: undefined,
|
|
198
|
-
});
|
|
199
|
-
res.on('close', () => {
|
|
200
|
-
transport.close().catch(() => { });
|
|
201
|
-
server.close().catch(() => { });
|
|
202
|
-
});
|
|
203
|
-
try {
|
|
204
|
-
await server.connect(transport);
|
|
205
|
-
await transport.handleRequest(req, res, req.body);
|
|
206
|
-
// Structured audit log per request (Claude path only — direct API key calls don't audit here)
|
|
207
|
-
// eslint-disable-next-line no-console
|
|
208
|
-
console.log(JSON.stringify({
|
|
209
|
-
...auditMeta,
|
|
210
|
-
event: 'mcp_request',
|
|
211
|
-
method: req.body?.method,
|
|
212
|
-
duration_ms: Date.now() - startedAt,
|
|
213
|
-
}));
|
|
214
|
-
}
|
|
215
|
-
catch (err) {
|
|
216
|
-
// eslint-disable-next-line no-console
|
|
217
|
-
console.error(JSON.stringify({
|
|
218
|
-
...auditMeta,
|
|
219
|
-
event: 'mcp_error',
|
|
220
|
-
error_message: err instanceof Error ? err.message : String(err),
|
|
221
|
-
duration_ms: Date.now() - startedAt,
|
|
222
|
-
}));
|
|
223
|
-
if (!res.headersSent) {
|
|
224
|
-
res.status(500).json({
|
|
225
|
-
jsonrpc: '2.0',
|
|
226
|
-
error: { code: -32603, message: err instanceof Error ? err.message : String(err) },
|
|
227
|
-
id: null,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
}
|
|
232
|
-
app.post('/mcp', handleMcpRequest);
|
|
233
|
-
app.get('/mcp', (_req, res) => {
|
|
234
|
-
// GET on /mcp without an active session = 405 Method Not Allowed.
|
|
235
|
-
// (Stateful mode would use GET for the SSE response stream; we're stateless.)
|
|
236
|
-
res.status(405).json({ error: 'method_not_allowed', allowed: 'POST' });
|
|
237
|
-
});
|
|
238
|
-
// ───────────────────────────────────────────────────────────────────────────
|
|
239
|
-
// Root index for humans hitting mcp.sota.io directly
|
|
240
|
-
// ───────────────────────────────────────────────────────────────────────────
|
|
241
|
-
app.get('/', (_req, res) => {
|
|
242
|
-
res.json({
|
|
243
|
-
service: 'sota-mcp',
|
|
244
|
-
version: VERSION,
|
|
245
|
-
description: 'MCP server for sota.io — EU-native PaaS. Use the Streamable HTTP transport at /mcp.',
|
|
246
|
-
docs: 'https://sota.io/docs/integrations/claude',
|
|
247
|
-
endpoints: {
|
|
248
|
-
health: `${PUBLIC_ORIGIN}/health`,
|
|
249
|
-
mcp: `${PUBLIC_ORIGIN}/mcp`,
|
|
250
|
-
protected_resource_metadata: `${PUBLIC_ORIGIN}/.well-known/oauth-protected-resource`,
|
|
251
|
-
},
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
// ───────────────────────────────────────────────────────────────────────────
|
|
255
12
|
app.listen(PORT, '0.0.0.0', () => {
|
|
256
|
-
|
|
257
|
-
|
|
13
|
+
logEvent('info', {
|
|
14
|
+
event: 'listening',
|
|
15
|
+
version: PACKAGE_VERSION,
|
|
16
|
+
commit: GIT_SHA,
|
|
17
|
+
url: `http://0.0.0.0:${PORT}`,
|
|
18
|
+
public_origin: PUBLIC_ORIGIN,
|
|
19
|
+
});
|
|
258
20
|
});
|
|
259
21
|
//# sourceMappingURL=http.js.map
|
package/dist/http.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";AAEA
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";AAEA;;;;;GAKG;AAEH,OAAO,EAAE,GAAG,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACnD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAE5D,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,CAAC,CAAC;AAE9C,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE;IAC/B,QAAQ,CAAC,MAAM,EAAE;QACf,KAAK,EAAE,WAAW;QAClB,OAAO,EAAE,eAAe;QACxB,MAAM,EAAE,OAAO;QACf,GAAG,EAAE,kBAAkB,IAAI,EAAE;QAC7B,aAAa,EAAE,aAAa;KAC7B,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -33,6 +33,7 @@ import { registerEnvTools } from './tools/env.js';
|
|
|
33
33
|
import { registerRollbackTool } from './tools/rollback.js';
|
|
34
34
|
import { registerStatusTool } from './tools/status.js';
|
|
35
35
|
import { registerDomainTools } from './tools/domains.js';
|
|
36
|
+
import { PACKAGE_VERSION } from './lib/version.js';
|
|
36
37
|
async function main() {
|
|
37
38
|
const apiKey = process.env.SOTA_API_KEY;
|
|
38
39
|
if (!apiKey) {
|
|
@@ -44,7 +45,7 @@ async function main() {
|
|
|
44
45
|
const client = new SotaClient({ apiKey, baseUrl: apiURL });
|
|
45
46
|
const server = new McpServer({
|
|
46
47
|
name: 'sota',
|
|
47
|
-
version:
|
|
48
|
+
version: PACKAGE_VERSION,
|
|
48
49
|
});
|
|
49
50
|
// Register all tools
|
|
50
51
|
registerProjectTools(server, client);
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AACnD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAEnD,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;IACxC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,CAAC,KAAK,CAAC,sDAAsD,CAAC,CAAC;QACtE,OAAO,CAAC,KAAK,CAAC,kEAAkE,CAAC,CAAC;QAClF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAClB,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,IAAI,qBAAqB,CAAC;IAEjE,MAAM,MAAM,GAAG,IAAI,UAAU,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAE3D,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC;QAC3B,IAAI,EAAE,MAAM;QACZ,OAAO,EAAE,eAAe;KACzB,CAAC,CAAC;IAEH,qBAAqB;IACrB,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,gBAAgB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,oBAAoB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACrC,kBAAkB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACnC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAEpC,wBAAwB;IACxB,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;IAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;AAClC,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,EAAE,EAAE;IACrB,OAAO,CAAC,KAAK,CAAC,cAAc,EAAE,KAAK,CAAC,CAAC;IACrC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,79 @@
|
|
|
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
|
+
export declare function isExcludedName(name: string): boolean;
|
|
32
|
+
/** Upper bound on inline file count (per single `deploy` call). */
|
|
33
|
+
export declare const MAX_INLINE_FILES = 200;
|
|
34
|
+
/** Upper bound on combined inline content length, in bytes. */
|
|
35
|
+
export declare const MAX_INLINE_TOTAL_BYTES: number;
|
|
36
|
+
/** 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. */
|
|
37
|
+
export declare const MAX_CLONE_BYTES: number;
|
|
38
|
+
export declare class ArchiveBuilderError extends Error {
|
|
39
|
+
readonly code: string;
|
|
40
|
+
constructor(code: string, message: string);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Pack a record of file paths → text content into a tar.gz Buffer.
|
|
44
|
+
*
|
|
45
|
+
* Each value is treated as UTF-8 text. Binary assets are not supported in
|
|
46
|
+
* this mode — use `archiveFromGitUrl` for that. The caller is responsible
|
|
47
|
+
* for including framework manifests (package.json, requirements.txt, or a
|
|
48
|
+
* Dockerfile) so the backend's auto-detection picks the right builder.
|
|
49
|
+
*/
|
|
50
|
+
export declare function archiveFromFiles(files: Record<string, string>): Buffer;
|
|
51
|
+
/**
|
|
52
|
+
* `git clone --depth=1` the given URL (optionally on a specified branch),
|
|
53
|
+
* then pack the resulting workdir into a tar.gz Buffer. Only public repos
|
|
54
|
+
* are supported in v1 — there is no credential plumbing.
|
|
55
|
+
*
|
|
56
|
+
* Rejects URLs that don't begin with https://, http://, git://, ssh://, or
|
|
57
|
+
* the scp-like git@host:path form, to keep the surface predictable.
|
|
58
|
+
*/
|
|
59
|
+
export declare function archiveFromGitUrl(gitUrl: string, gitBranch?: string): Buffer;
|
|
60
|
+
/**
|
|
61
|
+
* Pack an existing local directory into a tar.gz Buffer using the same
|
|
62
|
+
* ignore rules as every other mode (see isExcludedName: .git, node_modules,
|
|
63
|
+
* .DS_Store and the local/secret .env files). Exported so the deploy tool can re-use a
|
|
64
|
+
* single code path for archive construction.
|
|
65
|
+
*/
|
|
66
|
+
export declare function archiveFromDirectory(dir: string): Buffer;
|
|
67
|
+
/**
|
|
68
|
+
* Walk `root` and return the archive entries ("./rel/path", parents before
|
|
69
|
+
* children) plus the byte size of the regular files. Excluded names are
|
|
70
|
+
* skipped at every depth, and excluded directories are not descended into.
|
|
71
|
+
* Symlinks are archived as links and never followed.
|
|
72
|
+
*/
|
|
73
|
+
export declare function collectEntries(root: string): {
|
|
74
|
+
entries: string[];
|
|
75
|
+
totalBytes: number;
|
|
76
|
+
};
|
|
77
|
+
/** True when tar refused to start because it does not know `--null`. */
|
|
78
|
+
export declare function isUnknownNullOption(err: unknown): boolean;
|
|
79
|
+
//# sourceMappingURL=archive-builder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"archive-builder.d.ts","sourceRoot":"","sources":["../../src/lib/archive-builder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AA0BH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAGpD;AAED,mEAAmE;AACnE,eAAO,MAAM,gBAAgB,MAAM,CAAC;AACpC,+DAA+D;AAC/D,eAAO,MAAM,sBAAsB,QAAmB,CAAC;AACvD,0KAA0K;AAC1K,eAAO,MAAM,eAAe,QAAoB,CAAC;AAIjD,qBAAa,mBAAoB,SAAQ,KAAK;IAC5C,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;gBACV,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM;CAK1C;AAED;;;;;;;GAOG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAsCtE;AAED;;;;;;;GAOG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,CAsD5E;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAYxD;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG;IAAE,OAAO,EAAE,MAAM,EAAE,CAAC;IAAC,UAAU,EAAE,MAAM,CAAA;CAAE,CAqBtF;AAoDD,wEAAwE;AACxE,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,OAAO,GAAG,OAAO,CAGzD"}
|