codeport 0.3.0 → 0.4.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 +4 -2
- package/index.js +277 -135
- package/package.json +4 -1
package/README.md
CHANGED
|
@@ -17,6 +17,8 @@ into it, and your session token is kept in the OS keychain and never shown to th
|
|
|
17
17
|
| `analyze_project` | Detect the stack, save the project in your organization's catalog, first estimate |
|
|
18
18
|
| `estimate_cost` | Monthly cost on every platform for a load (Team / Department / Company or your numbers); `platform` gives an itemized bill with sources |
|
|
19
19
|
| `recommend_target` | Ranking by simplicity, cost and fit, with reasons; names the best platform Codeport can deploy to |
|
|
20
|
+
| `connect_github` | Link that installs the Codeport GitHub App (read-only, repositories you pick); lists connected repositories |
|
|
21
|
+
| `analyze_repository` | Analyze a connected repository in Codeport's cloud, without the code on this machine: stack, costs, recommendation |
|
|
20
22
|
|
|
21
23
|
## Set up
|
|
22
24
|
|
|
@@ -57,8 +59,8 @@ claude mcp add codeport -- node /path/to/codeport/apps/mcp/dist/index.js
|
|
|
57
59
|
`pnpm --filter @codeport/mcp pack:npm` bundles the server into `apps/mcp/npm/` (the
|
|
58
60
|
`@codeport/*` workspace packages are inlined; only the MCP SDK, zod and the OS keychain binding
|
|
59
61
|
stay as dependencies). Bump `version` in `package.json` and `src/version.ts`, merge, then push a
|
|
60
|
-
tag `mcp-v<version
|
|
61
|
-
with npm trusted publishing.
|
|
62
|
+
tag `mcp-v<version>`, or press "Run workflow" on "Release codeport to npm" for `main`: the workflow
|
|
63
|
+
tests, packs and publishes it with npm trusted publishing, and refuses a version already on npm.
|
|
62
64
|
|
|
63
65
|
Then, in a project folder, ask: _"Sign in to Codeport with me@company.com"_, paste the code, and
|
|
64
66
|
_"Analyze this project with Codeport and tell me where to host it."_
|
package/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { createRequire as __cpRequire } from "node:module"; const require = __cpRequire(import.meta.url);
|
|
3
3
|
|
|
4
|
-
//
|
|
4
|
+
// src/index.ts
|
|
5
5
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
6
|
|
|
7
|
-
//
|
|
7
|
+
// src/api.ts
|
|
8
8
|
var ApiError = class extends Error {
|
|
9
9
|
constructor(status, message) {
|
|
10
10
|
super(message);
|
|
@@ -84,7 +84,7 @@ async function errorText(res, fallback) {
|
|
|
84
84
|
}
|
|
85
85
|
}
|
|
86
86
|
|
|
87
|
-
//
|
|
87
|
+
// src/auth-flow.ts
|
|
88
88
|
import { z } from "zod";
|
|
89
89
|
var Email = z.string().trim().toLowerCase().email();
|
|
90
90
|
var Code = z.string().trim().regex(/^\d{6}$/, "the code has 6 digits");
|
|
@@ -145,7 +145,7 @@ var AuthFlow = class {
|
|
|
145
145
|
}
|
|
146
146
|
};
|
|
147
147
|
|
|
148
|
-
//
|
|
148
|
+
// src/credentials.ts
|
|
149
149
|
import { mkdir, readFile, rm, writeFile, chmod } from "node:fs/promises";
|
|
150
150
|
import { homedir } from "node:os";
|
|
151
151
|
import path from "node:path";
|
|
@@ -209,11 +209,11 @@ async function defaultStore() {
|
|
|
209
209
|
return await KeyringStore.tryCreate() ?? new FileStore();
|
|
210
210
|
}
|
|
211
211
|
|
|
212
|
-
//
|
|
212
|
+
// src/server.ts
|
|
213
213
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
214
214
|
import { z as z2 } from "zod";
|
|
215
215
|
var text = (t) => ({ content: [{ type: "text", text: t }] });
|
|
216
|
-
function createServer(flow2, tools, version) {
|
|
216
|
+
function createServer(flow2, tools, version, github) {
|
|
217
217
|
const server2 = new McpServer({ name: "codeport", version });
|
|
218
218
|
server2.registerTool(
|
|
219
219
|
"auth_start",
|
|
@@ -296,14 +296,258 @@ function createServer(flow2, tools, version) {
|
|
|
296
296
|
},
|
|
297
297
|
async (a) => text(await tools.recommend(a))
|
|
298
298
|
);
|
|
299
|
+
if (github) {
|
|
300
|
+
server2.registerTool(
|
|
301
|
+
"connect_github",
|
|
302
|
+
{
|
|
303
|
+
title: "Connect GitHub repositories to Codeport",
|
|
304
|
+
description: "Give the link that installs the Codeport GitHub App, so Codeport can analyze repositories in its cloud without the code on this machine (read-only access to code and metadata, for the repositories the user picks). Also lists the repositories already connected."
|
|
305
|
+
},
|
|
306
|
+
async () => text(await github.connect())
|
|
307
|
+
);
|
|
308
|
+
server2.registerTool(
|
|
309
|
+
"analyze_repository",
|
|
310
|
+
{
|
|
311
|
+
title: "Analyze a connected GitHub repository",
|
|
312
|
+
description: "Analyze a GitHub repository connected through connect_github, in Codeport's cloud: stack, monthly cost on every platform and where to host it. Works without a local copy of the code. Without `repo`, lists the connected repositories.",
|
|
313
|
+
inputSchema: {
|
|
314
|
+
repo: z2.string().optional().describe("owner/name or just the name, e.g. acme/portal"),
|
|
315
|
+
reanalyze: z2.boolean().optional().describe("Analyze the latest commit again instead of the last result"),
|
|
316
|
+
scenario: load.scenario,
|
|
317
|
+
geo: load.geo
|
|
318
|
+
}
|
|
319
|
+
},
|
|
320
|
+
async (a) => text(await github.analyze(a))
|
|
321
|
+
);
|
|
322
|
+
}
|
|
299
323
|
return server2;
|
|
300
324
|
}
|
|
301
325
|
|
|
302
|
-
//
|
|
326
|
+
// src/format.ts
|
|
327
|
+
var runtimeName = (lang) => lang === "typescript" || lang === "javascript" ? "Node.js" : lang === "python" ? "Python" : lang === "csharp" || lang === "fsharp" ? ".NET" : lang;
|
|
328
|
+
var money = (v) => v >= 100 ? `$${Math.round(v).toLocaleString("en-US")}` : `$${v.toFixed(2)}`;
|
|
329
|
+
var range = (r) => Math.abs(r.high - r.low) < 5e-3 ? money(r.low) : `${money(r.low)}\u2013${money(r.high)}`;
|
|
330
|
+
var SCENARIO = {
|
|
331
|
+
team: "Team (up to 50 users, ~1,000 requests a day, 1 GB of data)",
|
|
332
|
+
department: "Department (up to 500 users, ~20,000 requests a day, 10 GB)",
|
|
333
|
+
company: "Company (up to 5,000 users, ~200,000 requests a day, 50 GB)"
|
|
334
|
+
};
|
|
335
|
+
function formatStack(apps, warnings) {
|
|
336
|
+
const out = [];
|
|
337
|
+
for (const a of apps) {
|
|
338
|
+
const p = a.profile;
|
|
339
|
+
const rt = p.runtimes[0];
|
|
340
|
+
out.push(`### ${p.app.name}${a.path ? ` (\`${a.path}\`)` : ""}`);
|
|
341
|
+
out.push(
|
|
342
|
+
`- Kind: ${p.app.kind}; ${rt?.language ?? "unknown"}${rt?.framework ? `, ${rt.framework}` : ""}${rt?.version ? ` (${runtimeName(rt.language)} ${rt.version})` : ""}${p.build.packageManager ? `; ${p.build.packageManager}` : ""}${p.build.port ? `; port ${p.build.port}` : ""}`
|
|
343
|
+
);
|
|
344
|
+
if (p.services.length)
|
|
345
|
+
out.push(
|
|
346
|
+
`- Services: ${p.services.map((s) => `${s.type}${s.engine ? ` (${s.engine})` : ""}`).join(", ")}`
|
|
347
|
+
);
|
|
348
|
+
const secrets = p.env.filter((e) => e.secret).map((e) => e.name);
|
|
349
|
+
const plain = p.env.filter((e) => !e.secret).map((e) => e.name);
|
|
350
|
+
if (secrets.length) out.push(`- Secrets it needs: ${secrets.join(", ")}`);
|
|
351
|
+
if (plain.length) out.push(`- Other settings: ${plain.join(", ")}`);
|
|
352
|
+
for (const w of a.warnings) out.push(`- Note: ${w}`);
|
|
353
|
+
}
|
|
354
|
+
for (const w of warnings) out.push(`- Note: ${w}`);
|
|
355
|
+
return out.join("\n");
|
|
356
|
+
}
|
|
357
|
+
function scenarioLine(r) {
|
|
358
|
+
return `Load: ${SCENARIO[r.scenario] ?? "custom numbers"}. Region: ${r.geo === "us" ? "US East" : "Europe (Frankfurt)"}. Monthly USD.`;
|
|
359
|
+
}
|
|
360
|
+
function asOf(r) {
|
|
361
|
+
const d = Object.entries(r.pricesAsOf).map(([p, day]) => `${p} ${day}`);
|
|
362
|
+
return d.length ? `Prices as of: ${d.join(", ")}.` : "";
|
|
363
|
+
}
|
|
364
|
+
function formatCosts(r) {
|
|
365
|
+
const ok = r.ranking.filter((p) => !p.excluded).sort((a, b) => a.monthlyUsd.low + a.monthlyUsd.high - (b.monthlyUsd.low + b.monthlyUsd.high));
|
|
366
|
+
const out = [scenarioLine(r), "", "| Platform | Per month | Codeport deploys here |", "|---|---|---|"];
|
|
367
|
+
for (const p of ok)
|
|
368
|
+
out.push(`| ${p.name} | ${range(p.monthlyUsd)} | ${p.deployable ? "yes" : "not yet"} |`);
|
|
369
|
+
const ex = r.ranking.filter((p) => p.excluded);
|
|
370
|
+
if (ex.length) out.push("", "Not suitable or not priced:", ...ex.map((p) => `- ${p.name}: ${p.excluded}`));
|
|
371
|
+
const missing = [...new Set(ok.flatMap((p) => p.notIncluded.map((n) => n.item)))];
|
|
372
|
+
if (missing.length)
|
|
373
|
+
out.push("", `Not in these totals (billed by their own providers): ${missing.join(", ")}.`);
|
|
374
|
+
out.push("", asOf(r), "Ask for one platform's breakdown to see every line, its unit price and source.");
|
|
375
|
+
return out.filter((l, i, a) => !(l === "" && a[i - 1] === "")).join("\n");
|
|
376
|
+
}
|
|
377
|
+
function formatBreakdown(p, r) {
|
|
378
|
+
if (p.excluded) return `${p.name}: ${p.excluded}`;
|
|
379
|
+
const out = [
|
|
380
|
+
`## ${p.name}: ${range(p.monthlyUsd)} per month${p.region === "global" ? "" : ` (prices for ${p.region})`}`,
|
|
381
|
+
scenarioLine(r),
|
|
382
|
+
"",
|
|
383
|
+
"| Item | Quantity | Unit price | Cost | Source |",
|
|
384
|
+
"|---|---|---|---|---|"
|
|
385
|
+
];
|
|
386
|
+
for (const l of p.lines) {
|
|
387
|
+
const q = Math.abs(l.quantity.high - l.quantity.low) < 1e-9 ? fmtQty(l.quantity.low) : `${fmtQty(l.quantity.low)}\u2013${fmtQty(l.quantity.high)}`;
|
|
388
|
+
const unit = l.unitPrice ? `$${l.unitPrice.usd} / ${l.unitPrice.per === 1 ? "" : `${l.unitPrice.per.toLocaleString("en-US")} `}${l.unitPrice.unit}` : "";
|
|
389
|
+
const src = !l.source ? "" : l.source.kind === "aws-price-list" ? `AWS Price List, SKU ${l.source.sku}, ${l.source.publishedAt.slice(0, 10)}` : l.source.kind === "manual" ? `[${new URL(l.source.url).hostname}](${l.source.url}), checked ${l.source.verifiedAt}` : l.source.kind === "azure-retail-prices" ? `Azure Retail Prices, meter ${l.source.meterId}` : `Google Cloud Billing, SKU ${l.source.skuId}`;
|
|
390
|
+
const note = [l.vendor ? `billed by ${l.vendor}` : "", l.note ?? ""].filter(Boolean).join("; ");
|
|
391
|
+
out.push(
|
|
392
|
+
`| ${l.label}${note ? ` (${note})` : ""} | ${l.unitPrice ? q : `${q} ${l.unit}`} | ${unit} | ${range(l.usd)} | ${src} |`
|
|
393
|
+
);
|
|
394
|
+
}
|
|
395
|
+
if (p.notIncluded.length)
|
|
396
|
+
out.push("", "Not included:", ...p.notIncluded.map((n) => `- ${n.item}: ${n.reason}`));
|
|
397
|
+
return out.join("\n");
|
|
398
|
+
}
|
|
399
|
+
var fmtQty = (v) => v >= 1e3 ? Math.round(v).toLocaleString("en-US") : Number(v.toFixed(3)).toString();
|
|
400
|
+
function formatRecommendation(r) {
|
|
401
|
+
const ok = r.ranking.filter((p) => !p.excluded);
|
|
402
|
+
const best = ok[0];
|
|
403
|
+
if (!best)
|
|
404
|
+
return "No platform can run this project as it is: " + r.ranking.map((p) => `${p.name}: ${p.excluded}`).join("; ");
|
|
405
|
+
const out = [scenarioLine(r), ""];
|
|
406
|
+
const dep = ok.find((p) => p.deployable);
|
|
407
|
+
out.push(`**Best fit: ${best.name}** (${range(best.monthlyUsd)} per month, score ${best.score}).`);
|
|
408
|
+
if (!best.deployable && dep)
|
|
409
|
+
out.push(
|
|
410
|
+
`Codeport cannot deploy to ${best.name} yet. The best option it deploys to today is **${dep.name}** (${range(dep.monthlyUsd)} per month).`
|
|
411
|
+
);
|
|
412
|
+
if (!best.deployable && !dep) {
|
|
413
|
+
const why = r.ranking.filter((p) => p.deployable).map((p) => `${p.name}: ${p.excluded ?? "not suitable"}`);
|
|
414
|
+
out.push(`Codeport cannot deploy this project anywhere yet (${why.join("; ")}).`);
|
|
415
|
+
}
|
|
416
|
+
out.push("", "| # | Platform | Per month | Score | For | Against |", "|---|---|---|---|---|---|");
|
|
417
|
+
ok.forEach(
|
|
418
|
+
(p, i) => out.push(
|
|
419
|
+
`| ${i + 1} | ${p.name}${p.deployable ? "" : " (estimate only)"} | ${range(p.monthlyUsd)} | ${p.score} | ${p.pros.join("; ")} | ${p.cons.join("; ")} |`
|
|
420
|
+
)
|
|
421
|
+
);
|
|
422
|
+
const ex = r.ranking.filter((p) => p.excluded);
|
|
423
|
+
if (ex.length) out.push("", "Ruled out:", ...ex.map((p) => `- ${p.name}: ${p.excluded}`));
|
|
424
|
+
out.push("", "Score = 0.45 simplicity + 0.35 cost + 0.2 fit with the stack.", asOf(r));
|
|
425
|
+
return out.join("\n");
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// src/github-tools.ts
|
|
429
|
+
var NOT_SIGNED_IN = "Not signed in to Codeport. Ask the user for their work email and call auth_start.";
|
|
430
|
+
var GitHubTools = class {
|
|
431
|
+
constructor(api2, store2, opts = {}) {
|
|
432
|
+
this.api = api2;
|
|
433
|
+
this.store = store2;
|
|
434
|
+
this.waitMs = opts.waitMs ?? 1e5;
|
|
435
|
+
this.pollMs = opts.pollMs ?? 4e3;
|
|
436
|
+
this.sleep = opts.sleep ?? ((ms) => new Promise((r) => setTimeout(r, ms)));
|
|
437
|
+
}
|
|
438
|
+
waitMs;
|
|
439
|
+
pollMs;
|
|
440
|
+
sleep;
|
|
441
|
+
async run(fn) {
|
|
442
|
+
const c = await this.store.load();
|
|
443
|
+
const token = c && c.apiUrl === this.api.baseUrl ? c.token : null;
|
|
444
|
+
if (!token) return NOT_SIGNED_IN;
|
|
445
|
+
try {
|
|
446
|
+
return await fn(token);
|
|
447
|
+
} catch (e) {
|
|
448
|
+
if (e instanceof ApiError && e.status === 401) {
|
|
449
|
+
await this.store.clear();
|
|
450
|
+
return "The Codeport session has expired. Call auth_start to sign in again.";
|
|
451
|
+
}
|
|
452
|
+
if (e instanceof ApiError && e.status === 503)
|
|
453
|
+
return "Connecting GitHub is not available on this Codeport server yet.";
|
|
454
|
+
if (e instanceof ApiError) return `Codeport could not do that (${e.status}: ${e.message}).`;
|
|
455
|
+
throw e;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
/** The install link and what is already connected. */
|
|
459
|
+
async connect() {
|
|
460
|
+
return this.run(async (token) => {
|
|
461
|
+
const g = await this.api.call(token, "GET", "/v1/github");
|
|
462
|
+
const lines = [];
|
|
463
|
+
if (g.installations.length)
|
|
464
|
+
lines.push(
|
|
465
|
+
`Connected GitHub accounts: ${g.installations.map((i) => i.account).join(", ")}.`,
|
|
466
|
+
...repoLines(g),
|
|
467
|
+
"",
|
|
468
|
+
"To give Codeport access to more repositories or another GitHub account, open:"
|
|
469
|
+
);
|
|
470
|
+
else
|
|
471
|
+
lines.push(
|
|
472
|
+
"GitHub is not connected yet. Ask the user to open this link, choose the repositories Codeport may read (read-only access to code and metadata), and confirm. The link is valid for one hour:"
|
|
473
|
+
);
|
|
474
|
+
lines.push(
|
|
475
|
+
g.installUrl,
|
|
476
|
+
"",
|
|
477
|
+
"After that, use analyze_repository. Codeport analyzes new repositories automatically."
|
|
478
|
+
);
|
|
479
|
+
return lines.join("\n");
|
|
480
|
+
});
|
|
481
|
+
}
|
|
482
|
+
/** Analyzes a connected repository in the cloud and reports its stack and costs. */
|
|
483
|
+
async analyze(args) {
|
|
484
|
+
return this.run(async (token) => {
|
|
485
|
+
const g = await this.api.call(token, "GET", "/v1/github");
|
|
486
|
+
if (!g.repos.length)
|
|
487
|
+
return "No GitHub repositories are connected. Call connect_github to get the link that connects them.";
|
|
488
|
+
if (!args.repo) return ["Which repository? Connected ones:", ...repoLines(g)].join("\n");
|
|
489
|
+
const want = args.repo.toLowerCase().replace(/^https?:\/\/github\.com\//, "").replace(/\.git$/, "");
|
|
490
|
+
const matches = g.repos.filter((r) => {
|
|
491
|
+
const full2 = (r.repo ?? "").replace(/^github:/, "").toLowerCase();
|
|
492
|
+
return full2 === want || full2.split("/")[1] === want || r.name.toLowerCase() === want;
|
|
493
|
+
});
|
|
494
|
+
if (matches.length !== 1)
|
|
495
|
+
return [
|
|
496
|
+
matches.length ? `"${args.repo}" matches several repositories:` : `"${args.repo}" is not connected. Connected:`,
|
|
497
|
+
...repoLines({ repos: matches.length ? matches : g.repos }),
|
|
498
|
+
"Give the full owner/name, or call connect_github to add a repository."
|
|
499
|
+
].join("\n");
|
|
500
|
+
const app = matches[0];
|
|
501
|
+
const full = (app.repo ?? app.name).replace(/^github:/, "");
|
|
502
|
+
if (app.status !== "analyzed" || args.reanalyze) {
|
|
503
|
+
const { run } = await this.api.call(token, "POST", `/v1/apps/${app.appId}/runs`, {
|
|
504
|
+
trigger: "mcp"
|
|
505
|
+
});
|
|
506
|
+
const done = await this.wait(token, run.id);
|
|
507
|
+
if (!done)
|
|
508
|
+
return `Codeport is analyzing ${full} in the cloud; it usually takes a minute or two. Call analyze_repository again shortly.`;
|
|
509
|
+
if (done.status === "failed")
|
|
510
|
+
return `The analysis of ${full} failed: ${done.error ?? "unknown error"}`;
|
|
511
|
+
}
|
|
512
|
+
const geo = args.geo ?? "eu";
|
|
513
|
+
const report = await this.api.call(token, "GET", `/v1/apps/${app.appId}/report?geo=${geo}`);
|
|
514
|
+
if (!report.estimates || !report.profiles.length)
|
|
515
|
+
return `${full} has no finished analysis yet. Call analyze_repository with reanalyze: true.`;
|
|
516
|
+
const commit = report.analysis?.commitSha ? ` at commit ${report.analysis.commitSha.slice(0, 7)}` : "";
|
|
517
|
+
return [
|
|
518
|
+
`Analysis of ${full}${commit} (in Codeport's cloud; the code was read, nothing from it was run).`,
|
|
519
|
+
"",
|
|
520
|
+
"## Stack",
|
|
521
|
+
formatStack(
|
|
522
|
+
report.profiles.map((p) => ({ path: p.path, profile: p.profile, warnings: [] })),
|
|
523
|
+
[]
|
|
524
|
+
),
|
|
525
|
+
"",
|
|
526
|
+
formatRecommendation(report.estimates[args.scenario ?? "team"])
|
|
527
|
+
].join("\n");
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
async wait(token, runId) {
|
|
531
|
+
const deadline = Date.now() + this.waitMs;
|
|
532
|
+
for (; ; ) {
|
|
533
|
+
const { run } = await this.api.call(token, "GET", `/v1/runs/${runId}`);
|
|
534
|
+
if (run.status === "succeeded" || run.status === "failed") return run;
|
|
535
|
+
if (Date.now() + this.pollMs > deadline) return null;
|
|
536
|
+
await this.sleep(this.pollMs);
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
function repoLines(g) {
|
|
541
|
+
return g.repos.map(
|
|
542
|
+
(r) => `- ${(r.repo ?? r.name).replace(/^github:/, "")}${r.status === "analyzed" ? "" : " (not analyzed yet)"}`
|
|
543
|
+
);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
// src/project-tools.ts
|
|
303
547
|
import path6 from "node:path";
|
|
304
548
|
import { stat as stat2 } from "node:fs/promises";
|
|
305
549
|
|
|
306
|
-
// packages/detectors/dist/files.js
|
|
550
|
+
// ../../packages/detectors/dist/files.js
|
|
307
551
|
import { readdir, readFile as readFile2, stat } from "node:fs/promises";
|
|
308
552
|
import path2 from "node:path";
|
|
309
553
|
var IGNORED_DIRS = /* @__PURE__ */ new Set([
|
|
@@ -386,10 +630,10 @@ function subdir(files, dir) {
|
|
|
386
630
|
return { list: () => keys, read: (rel) => files.read(prefix + rel) };
|
|
387
631
|
}
|
|
388
632
|
|
|
389
|
-
// packages/detectors/dist/analyze.js
|
|
633
|
+
// ../../packages/detectors/dist/analyze.js
|
|
390
634
|
import path4 from "node:path";
|
|
391
635
|
|
|
392
|
-
// packages/app-profile/dist/schema.js
|
|
636
|
+
// ../../packages/app-profile/dist/schema.js
|
|
393
637
|
import { z as z3 } from "zod";
|
|
394
638
|
var Source = z3.enum(["detector", "llm", "user"]);
|
|
395
639
|
var AppKind = z3.enum(["web", "api", "worker", "static", "fullstack"]);
|
|
@@ -445,7 +689,7 @@ var AppProfile = z3.object({
|
|
|
445
689
|
load: Load.default({ source: "detector" })
|
|
446
690
|
});
|
|
447
691
|
|
|
448
|
-
// packages/detectors/dist/common.js
|
|
692
|
+
// ../../packages/detectors/dist/common.js
|
|
449
693
|
var ServiceSet = class {
|
|
450
694
|
map = /* @__PURE__ */ new Map();
|
|
451
695
|
add(hit, evidence) {
|
|
@@ -477,7 +721,7 @@ function firstExisting(files, candidates) {
|
|
|
477
721
|
return candidates.find((c) => set.has(c));
|
|
478
722
|
}
|
|
479
723
|
|
|
480
|
-
// packages/detectors/dist/catalog.js
|
|
724
|
+
// ../../packages/detectors/dist/catalog.js
|
|
481
725
|
var NPM_SERVICES = {
|
|
482
726
|
pg: [{ type: "database", engine: "postgres" }],
|
|
483
727
|
postgres: [{ type: "database", engine: "postgres" }],
|
|
@@ -723,7 +967,7 @@ var IGNORED_ENV = /* @__PURE__ */ new Set([
|
|
|
723
967
|
]);
|
|
724
968
|
var TEST_ENV = /^(PLAYWRIGHT|CYPRESS|VITEST|JEST|CI_|GITHUB_)/;
|
|
725
969
|
|
|
726
|
-
// packages/detectors/dist/env.js
|
|
970
|
+
// ../../packages/detectors/dist/env.js
|
|
727
971
|
var ENV_FILES = /(^|\/)\.env\.(example|sample|template|local\.example)$/;
|
|
728
972
|
var SOURCE = /\.(js|cjs|mjs|jsx|ts|tsx|mts|cts|py|vue|svelte|astro)$/;
|
|
729
973
|
var TEST_PATH = /(^|\/)(tests?|__tests__|e2e|cypress|playwright|spec)\/|\.(test|spec)\.[a-z]+$|(^|\/)(playwright|vitest|jest|cypress)\.config\./i;
|
|
@@ -767,7 +1011,7 @@ function detectEnv(files) {
|
|
|
767
1011
|
return { env, evidence: found };
|
|
768
1012
|
}
|
|
769
1013
|
|
|
770
|
-
// packages/detectors/dist/node.js
|
|
1014
|
+
// ../../packages/detectors/dist/node.js
|
|
771
1015
|
function readPackageJson(files, rel = "package.json") {
|
|
772
1016
|
const raw = files.read(rel);
|
|
773
1017
|
if (!raw)
|
|
@@ -921,7 +1165,7 @@ function detectNode(files, fallbackName, inheritedPm) {
|
|
|
921
1165
|
};
|
|
922
1166
|
}
|
|
923
1167
|
|
|
924
|
-
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/error.js
|
|
1168
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/error.js
|
|
925
1169
|
function getLineColFromPtr(string, ptr) {
|
|
926
1170
|
let lines = string.slice(0, ptr).split(/\r?\n/);
|
|
927
1171
|
return [lines.length, lines.pop().length + 1];
|
|
@@ -965,7 +1209,7 @@ ${codeblock}`, options);
|
|
|
965
1209
|
}
|
|
966
1210
|
};
|
|
967
1211
|
|
|
968
|
-
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/primitive.js
|
|
1212
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/primitive.js
|
|
969
1213
|
function parseString(ctx) {
|
|
970
1214
|
let startPtr = ctx.p;
|
|
971
1215
|
let c = ctx.s.charCodeAt(ctx.p++);
|
|
@@ -1066,7 +1310,7 @@ function parseString(ctx) {
|
|
|
1066
1310
|
TomlError.x("unfinished string", ctx, startPtr);
|
|
1067
1311
|
}
|
|
1068
1312
|
|
|
1069
|
-
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/date.js
|
|
1313
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/date.js
|
|
1070
1314
|
var DATE_TIME_RE = /^(\d{4}-\d{2}-\d{2})?[Tt ]?(?:(\d{2}):\d{2}(?::\d{2}(?:\.\d+)?)?)?(Z|z|[-+]\d{2}:\d{2})?$/i;
|
|
1071
1315
|
var TomlDate = class _TomlDate extends Date {
|
|
1072
1316
|
#hasDate = false;
|
|
@@ -1181,7 +1425,7 @@ var TomlDate = class _TomlDate extends Date {
|
|
|
1181
1425
|
}
|
|
1182
1426
|
};
|
|
1183
1427
|
|
|
1184
|
-
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/extract.js
|
|
1428
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/extract.js
|
|
1185
1429
|
function isDigit(char, base = 10) {
|
|
1186
1430
|
return base === 16 ? char > 47 && char < 58 || char > 64 && char < 71 || char > 96 && char < 103 : char > 47 && char < 48 + base;
|
|
1187
1431
|
}
|
|
@@ -1390,7 +1634,7 @@ function readDate(ctx, str, type, unsafeDelim, errPtr, temporalSuffix) {
|
|
|
1390
1634
|
}
|
|
1391
1635
|
}
|
|
1392
1636
|
|
|
1393
|
-
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/util.js
|
|
1637
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/util.js
|
|
1394
1638
|
function skipComment(ctx) {
|
|
1395
1639
|
for (; ctx.p < ctx.s.length; ctx.p++) {
|
|
1396
1640
|
let c = ctx.s.charCodeAt(ctx.p);
|
|
@@ -1416,7 +1660,7 @@ function skipVoid(ctx, banNewLines, banComments) {
|
|
|
1416
1660
|
}
|
|
1417
1661
|
}
|
|
1418
1662
|
|
|
1419
|
-
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/struct.js
|
|
1663
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/struct.js
|
|
1420
1664
|
function parseKey(ctx, end = 61) {
|
|
1421
1665
|
let startPtr;
|
|
1422
1666
|
let state = 0;
|
|
@@ -1533,7 +1777,7 @@ function parseArray(ctx) {
|
|
|
1533
1777
|
TomlError.x("unfinished array", ctx, startPtr);
|
|
1534
1778
|
}
|
|
1535
1779
|
|
|
1536
|
-
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/parse.js
|
|
1780
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/parse.js
|
|
1537
1781
|
function peekTable(ctx, key, table, meta, type) {
|
|
1538
1782
|
let t = table;
|
|
1539
1783
|
let m = meta;
|
|
@@ -1676,10 +1920,10 @@ function parse(toml, options = {}) {
|
|
|
1676
1920
|
return res;
|
|
1677
1921
|
}
|
|
1678
1922
|
|
|
1679
|
-
// node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/stringify.js
|
|
1923
|
+
// ../../node_modules/.pnpm/smol-toml@1.9.1/node_modules/smol-toml/dist/stringify.js
|
|
1680
1924
|
var HAS_WELLFORMED = !!"".isWellFormed;
|
|
1681
1925
|
|
|
1682
|
-
// packages/detectors/dist/python.js
|
|
1926
|
+
// ../../packages/detectors/dist/python.js
|
|
1683
1927
|
var DOC_TOOLS = /^(sphinx|mkdocs|alabaster|furo|myst-parser|pydata-sphinx-theme|docutils|recommonmark)/;
|
|
1684
1928
|
function normalizePyName(spec) {
|
|
1685
1929
|
const m = spec.trim().match(/^([A-Za-z0-9][A-Za-z0-9._-]*)/);
|
|
@@ -1795,7 +2039,7 @@ function detectPython(files, fallbackName, inheritedLock) {
|
|
|
1795
2039
|
};
|
|
1796
2040
|
}
|
|
1797
2041
|
|
|
1798
|
-
// packages/detectors/dist/dotnet.js
|
|
2042
|
+
// ../../packages/detectors/dist/dotnet.js
|
|
1799
2043
|
import path3 from "node:path";
|
|
1800
2044
|
var PROJECT_FILE = /\.(cs|fs)proj$/;
|
|
1801
2045
|
function properties(xml) {
|
|
@@ -2114,7 +2358,7 @@ function detectDotnet(files) {
|
|
|
2114
2358
|
return { apps, warnings };
|
|
2115
2359
|
}
|
|
2116
2360
|
|
|
2117
|
-
// packages/detectors/dist/analyze.js
|
|
2361
|
+
// ../../packages/detectors/dist/analyze.js
|
|
2118
2362
|
function hasManifest(files, dir) {
|
|
2119
2363
|
const view = subdir(files, dir);
|
|
2120
2364
|
return view.list().includes("package.json") || pythonManifests(view).length > 0;
|
|
@@ -2248,109 +2492,7 @@ async function analyzeDirectory(dir) {
|
|
|
2248
2492
|
return analyzeFiles(await fromDirectory(dir), path4.basename(path4.resolve(dir)));
|
|
2249
2493
|
}
|
|
2250
2494
|
|
|
2251
|
-
//
|
|
2252
|
-
var runtimeName = (lang) => lang === "typescript" || lang === "javascript" ? "Node.js" : lang === "python" ? "Python" : lang === "csharp" || lang === "fsharp" ? ".NET" : lang;
|
|
2253
|
-
var money = (v) => v >= 100 ? `$${Math.round(v).toLocaleString("en-US")}` : `$${v.toFixed(2)}`;
|
|
2254
|
-
var range = (r) => Math.abs(r.high - r.low) < 5e-3 ? money(r.low) : `${money(r.low)}\u2013${money(r.high)}`;
|
|
2255
|
-
var SCENARIO = {
|
|
2256
|
-
team: "Team (up to 50 users, ~1,000 requests a day, 1 GB of data)",
|
|
2257
|
-
department: "Department (up to 500 users, ~20,000 requests a day, 10 GB)",
|
|
2258
|
-
company: "Company (up to 5,000 users, ~200,000 requests a day, 50 GB)"
|
|
2259
|
-
};
|
|
2260
|
-
function formatStack(apps, warnings) {
|
|
2261
|
-
const out = [];
|
|
2262
|
-
for (const a of apps) {
|
|
2263
|
-
const p = a.profile;
|
|
2264
|
-
const rt = p.runtimes[0];
|
|
2265
|
-
out.push(`### ${p.app.name}${a.path ? ` (\`${a.path}\`)` : ""}`);
|
|
2266
|
-
out.push(
|
|
2267
|
-
`- Kind: ${p.app.kind}; ${rt?.language ?? "unknown"}${rt?.framework ? `, ${rt.framework}` : ""}${rt?.version ? ` (${runtimeName(rt.language)} ${rt.version})` : ""}${p.build.packageManager ? `; ${p.build.packageManager}` : ""}${p.build.port ? `; port ${p.build.port}` : ""}`
|
|
2268
|
-
);
|
|
2269
|
-
if (p.services.length)
|
|
2270
|
-
out.push(
|
|
2271
|
-
`- Services: ${p.services.map((s) => `${s.type}${s.engine ? ` (${s.engine})` : ""}`).join(", ")}`
|
|
2272
|
-
);
|
|
2273
|
-
const secrets = p.env.filter((e) => e.secret).map((e) => e.name);
|
|
2274
|
-
const plain = p.env.filter((e) => !e.secret).map((e) => e.name);
|
|
2275
|
-
if (secrets.length) out.push(`- Secrets it needs: ${secrets.join(", ")}`);
|
|
2276
|
-
if (plain.length) out.push(`- Other settings: ${plain.join(", ")}`);
|
|
2277
|
-
for (const w of a.warnings) out.push(`- Note: ${w}`);
|
|
2278
|
-
}
|
|
2279
|
-
for (const w of warnings) out.push(`- Note: ${w}`);
|
|
2280
|
-
return out.join("\n");
|
|
2281
|
-
}
|
|
2282
|
-
function scenarioLine(r) {
|
|
2283
|
-
return `Load: ${SCENARIO[r.scenario] ?? "custom numbers"}. Region: ${r.geo === "us" ? "US East" : "Europe (Frankfurt)"}. Monthly USD.`;
|
|
2284
|
-
}
|
|
2285
|
-
function asOf(r) {
|
|
2286
|
-
const d = Object.entries(r.pricesAsOf).map(([p, day]) => `${p} ${day}`);
|
|
2287
|
-
return d.length ? `Prices as of: ${d.join(", ")}.` : "";
|
|
2288
|
-
}
|
|
2289
|
-
function formatCosts(r) {
|
|
2290
|
-
const ok = r.ranking.filter((p) => !p.excluded).sort((a, b) => a.monthlyUsd.low + a.monthlyUsd.high - (b.monthlyUsd.low + b.monthlyUsd.high));
|
|
2291
|
-
const out = [scenarioLine(r), "", "| Platform | Per month | Codeport deploys here |", "|---|---|---|"];
|
|
2292
|
-
for (const p of ok)
|
|
2293
|
-
out.push(`| ${p.name} | ${range(p.monthlyUsd)} | ${p.deployable ? "yes" : "not yet"} |`);
|
|
2294
|
-
const ex = r.ranking.filter((p) => p.excluded);
|
|
2295
|
-
if (ex.length) out.push("", "Not suitable or not priced:", ...ex.map((p) => `- ${p.name}: ${p.excluded}`));
|
|
2296
|
-
const missing = [...new Set(ok.flatMap((p) => p.notIncluded.map((n) => n.item)))];
|
|
2297
|
-
if (missing.length)
|
|
2298
|
-
out.push("", `Not in these totals (billed by their own providers): ${missing.join(", ")}.`);
|
|
2299
|
-
out.push("", asOf(r), "Ask for one platform's breakdown to see every line, its unit price and source.");
|
|
2300
|
-
return out.filter((l, i, a) => !(l === "" && a[i - 1] === "")).join("\n");
|
|
2301
|
-
}
|
|
2302
|
-
function formatBreakdown(p, r) {
|
|
2303
|
-
if (p.excluded) return `${p.name}: ${p.excluded}`;
|
|
2304
|
-
const out = [
|
|
2305
|
-
`## ${p.name}: ${range(p.monthlyUsd)} per month${p.region === "global" ? "" : ` (prices for ${p.region})`}`,
|
|
2306
|
-
scenarioLine(r),
|
|
2307
|
-
"",
|
|
2308
|
-
"| Item | Quantity | Unit price | Cost | Source |",
|
|
2309
|
-
"|---|---|---|---|---|"
|
|
2310
|
-
];
|
|
2311
|
-
for (const l of p.lines) {
|
|
2312
|
-
const q = Math.abs(l.quantity.high - l.quantity.low) < 1e-9 ? fmtQty(l.quantity.low) : `${fmtQty(l.quantity.low)}\u2013${fmtQty(l.quantity.high)}`;
|
|
2313
|
-
const unit = l.unitPrice ? `$${l.unitPrice.usd} / ${l.unitPrice.per === 1 ? "" : `${l.unitPrice.per.toLocaleString("en-US")} `}${l.unitPrice.unit}` : "";
|
|
2314
|
-
const src = !l.source ? "" : l.source.kind === "aws-price-list" ? `AWS Price List, SKU ${l.source.sku}, ${l.source.publishedAt.slice(0, 10)}` : l.source.kind === "manual" ? `[${new URL(l.source.url).hostname}](${l.source.url}), checked ${l.source.verifiedAt}` : l.source.kind === "azure-retail-prices" ? `Azure Retail Prices, meter ${l.source.meterId}` : `Google Cloud Billing, SKU ${l.source.skuId}`;
|
|
2315
|
-
const note = [l.vendor ? `billed by ${l.vendor}` : "", l.note ?? ""].filter(Boolean).join("; ");
|
|
2316
|
-
out.push(
|
|
2317
|
-
`| ${l.label}${note ? ` (${note})` : ""} | ${l.unitPrice ? q : `${q} ${l.unit}`} | ${unit} | ${range(l.usd)} | ${src} |`
|
|
2318
|
-
);
|
|
2319
|
-
}
|
|
2320
|
-
if (p.notIncluded.length)
|
|
2321
|
-
out.push("", "Not included:", ...p.notIncluded.map((n) => `- ${n.item}: ${n.reason}`));
|
|
2322
|
-
return out.join("\n");
|
|
2323
|
-
}
|
|
2324
|
-
var fmtQty = (v) => v >= 1e3 ? Math.round(v).toLocaleString("en-US") : Number(v.toFixed(3)).toString();
|
|
2325
|
-
function formatRecommendation(r) {
|
|
2326
|
-
const ok = r.ranking.filter((p) => !p.excluded);
|
|
2327
|
-
const best = ok[0];
|
|
2328
|
-
if (!best)
|
|
2329
|
-
return "No platform can run this project as it is: " + r.ranking.map((p) => `${p.name}: ${p.excluded}`).join("; ");
|
|
2330
|
-
const out = [scenarioLine(r), ""];
|
|
2331
|
-
const dep = ok.find((p) => p.deployable);
|
|
2332
|
-
out.push(`**Best fit: ${best.name}** (${range(best.monthlyUsd)} per month, score ${best.score}).`);
|
|
2333
|
-
if (!best.deployable && dep)
|
|
2334
|
-
out.push(
|
|
2335
|
-
`Codeport cannot deploy to ${best.name} yet. The best option it deploys to today is **${dep.name}** (${range(dep.monthlyUsd)} per month).`
|
|
2336
|
-
);
|
|
2337
|
-
if (!best.deployable && !dep) {
|
|
2338
|
-
const why = r.ranking.filter((p) => p.deployable).map((p) => `${p.name}: ${p.excluded ?? "not suitable"}`);
|
|
2339
|
-
out.push(`Codeport cannot deploy this project anywhere yet (${why.join("; ")}).`);
|
|
2340
|
-
}
|
|
2341
|
-
out.push("", "| # | Platform | Per month | Score | For | Against |", "|---|---|---|---|---|---|");
|
|
2342
|
-
ok.forEach(
|
|
2343
|
-
(p, i) => out.push(
|
|
2344
|
-
`| ${i + 1} | ${p.name}${p.deployable ? "" : " (estimate only)"} | ${range(p.monthlyUsd)} | ${p.score} | ${p.pros.join("; ")} | ${p.cons.join("; ")} |`
|
|
2345
|
-
)
|
|
2346
|
-
);
|
|
2347
|
-
const ex = r.ranking.filter((p) => p.excluded);
|
|
2348
|
-
if (ex.length) out.push("", "Ruled out:", ...ex.map((p) => `- ${p.name}: ${p.excluded}`));
|
|
2349
|
-
out.push("", "Score = 0.45 simplicity + 0.35 cost + 0.2 fit with the stack.", asOf(r));
|
|
2350
|
-
return out.join("\n");
|
|
2351
|
-
}
|
|
2352
|
-
|
|
2353
|
-
// apps/mcp/src/projects.ts
|
|
2495
|
+
// src/projects.ts
|
|
2354
2496
|
import { mkdir as mkdir2, readFile as readFile3, writeFile as writeFile2 } from "node:fs/promises";
|
|
2355
2497
|
import { homedir as homedir2 } from "node:os";
|
|
2356
2498
|
import path5 from "node:path";
|
|
@@ -2397,8 +2539,8 @@ async function repoOf(dir) {
|
|
|
2397
2539
|
}
|
|
2398
2540
|
}
|
|
2399
2541
|
|
|
2400
|
-
//
|
|
2401
|
-
var
|
|
2542
|
+
// src/project-tools.ts
|
|
2543
|
+
var NOT_SIGNED_IN2 = "Not signed in to Codeport. Ask the user for their work email and call auth_start.";
|
|
2402
2544
|
var ProjectTools = class {
|
|
2403
2545
|
constructor(api2, store2, projects = new ProjectMap(), cwd = () => process.cwd()) {
|
|
2404
2546
|
this.api = api2;
|
|
@@ -2433,7 +2575,7 @@ var ProjectTools = class {
|
|
|
2433
2575
|
}
|
|
2434
2576
|
async run(fn) {
|
|
2435
2577
|
const token = await this.token();
|
|
2436
|
-
if (!token) return
|
|
2578
|
+
if (!token) return NOT_SIGNED_IN2;
|
|
2437
2579
|
try {
|
|
2438
2580
|
return await fn(token);
|
|
2439
2581
|
} catch (e) {
|
|
@@ -2528,15 +2670,15 @@ var usd = (r) => {
|
|
|
2528
2670
|
return Math.abs(r.high - r.low) < 5e-3 ? f(r.low) : `${f(r.low)}\u2013${f(r.high)}`;
|
|
2529
2671
|
};
|
|
2530
2672
|
|
|
2531
|
-
//
|
|
2532
|
-
var VERSION = "0.
|
|
2673
|
+
// src/version.ts
|
|
2674
|
+
var VERSION = "0.4.0";
|
|
2533
2675
|
|
|
2534
|
-
//
|
|
2676
|
+
// src/index.ts
|
|
2535
2677
|
var apiUrl = process.env.CODEPORT_API_URL ?? "https://api.codeport.diy";
|
|
2536
2678
|
var api = new CodeportApi(apiUrl);
|
|
2537
2679
|
var store = await defaultStore();
|
|
2538
2680
|
var flow = new AuthFlow(api, store);
|
|
2539
|
-
var server = createServer(flow, new ProjectTools(api, store), VERSION);
|
|
2681
|
+
var server = createServer(flow, new ProjectTools(api, store), VERSION, new GitHubTools(api, store));
|
|
2540
2682
|
await server.connect(new StdioServerTransport());
|
|
2541
2683
|
/*! Bundled license information:
|
|
2542
2684
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "codeport",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Codeport MCP server: analyze your project's stack, estimate hosting cost and pick where to host it",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -28,5 +28,8 @@
|
|
|
28
28
|
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
29
29
|
"@napi-rs/keyring": "^2.1.2",
|
|
30
30
|
"zod": "^3.25.76"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"provenance": false
|
|
31
34
|
}
|
|
32
35
|
}
|