@spec0/cli 0.4.0 → 0.5.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 +3 -1
- package/dist/commands/api/delete.d.ts +10 -0
- package/dist/commands/api/delete.d.ts.map +1 -0
- package/dist/commands/api/delete.js +70 -0
- package/dist/commands/api/delete.js.map +1 -0
- package/dist/commands/api/index.d.ts.map +1 -1
- package/dist/commands/api/index.js +2 -0
- package/dist/commands/api/index.js.map +1 -1
- package/dist/commands/api/show.d.ts +5 -2
- package/dist/commands/api/show.d.ts.map +1 -1
- package/dist/commands/api/show.js +75 -20
- package/dist/commands/api/show.js.map +1 -1
- package/dist/commands/auth.d.ts.map +1 -1
- package/dist/commands/auth.js +13 -11
- package/dist/commands/auth.js.map +1 -1
- package/dist/commands/mcp.d.ts +7 -1
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +135 -29
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/mock/delete.d.ts +11 -0
- package/dist/commands/mock/delete.d.ts.map +1 -0
- package/dist/commands/mock/delete.js +64 -0
- package/dist/commands/mock/delete.js.map +1 -0
- package/dist/commands/mock/index.d.ts.map +1 -1
- package/dist/commands/mock/index.js +2 -0
- package/dist/commands/mock/index.js.map +1 -1
- package/dist/commands/publish.js +2 -2
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/push.d.ts.map +1 -1
- package/dist/commands/push.js +13 -23
- package/dist/commands/push.js.map +1 -1
- package/dist/lib/api-client.d.ts +2 -2
- package/dist/lib/api-client.d.ts.map +1 -1
- package/dist/lib/api-client.js +7 -4
- package/dist/lib/api-client.js.map +1 -1
- package/dist/lib/git-provenance.d.ts +33 -0
- package/dist/lib/git-provenance.d.ts.map +1 -0
- package/dist/lib/git-provenance.js +50 -0
- package/dist/lib/git-provenance.js.map +1 -0
- package/dist/lib/platform-defaults.d.ts +29 -4
- package/dist/lib/platform-defaults.d.ts.map +1 -1
- package/dist/lib/platform-defaults.js +34 -4
- package/dist/lib/platform-defaults.js.map +1 -1
- package/package.json +6 -6
package/README.md
CHANGED
|
@@ -156,7 +156,8 @@ Every command supports `--output=text|json|yaml`. Progress / logs go to stderr,
|
|
|
156
156
|
| -------------------------- | ------------------------------------------------------------------------ |
|
|
157
157
|
| `spec0 commands` | List every command with its flags, args, and exit codes (JSON-friendly). |
|
|
158
158
|
| `spec0 commands <pattern>` | Filter the manifest by substring. |
|
|
159
|
-
| `spec0 mcp url` | Print the MCP server
|
|
159
|
+
| `spec0 mcp url` | Print the MCP (Streamable HTTP) server config for Cursor / Claude. |
|
|
160
|
+
| `spec0 mcp install` | Install the MCP server into Cursor and/or Claude (`--client`). |
|
|
160
161
|
|
|
161
162
|
### Other
|
|
162
163
|
|
|
@@ -177,6 +178,7 @@ Two paths:
|
|
|
177
178
|
| `SPEC0_ORG_ID` | UUID of the org the CLI acts against. | _required_ |
|
|
178
179
|
| `SPEC0_API_URL` | Platform backend base URL. | `https://api.spec0.io` |
|
|
179
180
|
| `SPEC0_APP_URL` | Platform web app (used for auth callback + dashboard links). | `https://spec0.io` |
|
|
181
|
+
| `SPEC0_MCP_URL` | MCP server endpoint (single Streamable HTTP URL) emitted by `spec0 mcp url` / `mcp install`. | `https://api.spec0.io/mcp` |
|
|
180
182
|
| `SPEC0_MODE` | Set to `agent` to flip every default for machine callers: JSON output, no colour, no spinners, no update banner. See the [agent guide](docs/guides/ai-agents.md). | _unset_ (human mode) |
|
|
181
183
|
|
|
182
184
|
`PLATFORM_*` variants are accepted for backwards compatibility; they'll be removed in the next major. Use `spec0 doctor` to see which source each value is resolving from.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* spec0 api delete <ref> — delete a team-scoped API.
|
|
3
|
+
*
|
|
4
|
+
* Uses PublicApisService.deleteTeamApi (`DELETE /api/v1/public/apis/team/{apiId}`).
|
|
5
|
+
* Resolves <ref> (name or UUID) via the shared ref-resolver. Requires `--yes`.
|
|
6
|
+
* Mirrors `spec0 team delete`'s destructive-op contract.
|
|
7
|
+
*/
|
|
8
|
+
import { Command } from "commander";
|
|
9
|
+
export declare function registerApiDeleteCommand(api: Command): void;
|
|
10
|
+
//# sourceMappingURL=delete.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.d.ts","sourceRoot":"","sources":["../../../src/commands/api/delete.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmBpC,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,OAAO,QAiEpD"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* spec0 api delete <ref> — delete a team-scoped API.
|
|
3
|
+
*
|
|
4
|
+
* Uses PublicApisService.deleteTeamApi (`DELETE /api/v1/public/apis/team/{apiId}`).
|
|
5
|
+
* Resolves <ref> (name or UUID) via the shared ref-resolver. Requires `--yes`.
|
|
6
|
+
* Mirrors `spec0 team delete`'s destructive-op contract.
|
|
7
|
+
*/
|
|
8
|
+
import chalk from "chalk";
|
|
9
|
+
import { PublicApisService } from "@spec0/sdk-public-platform";
|
|
10
|
+
import { configureSdkAuth, errorStatusCode, is401, extractErrorMessage, } from "../../lib/api-client.js";
|
|
11
|
+
import { requireOrgContext } from "../../lib/auth-context.js";
|
|
12
|
+
import { ExitCode, exitCodeForHttpStatus } from "../../lib/exit-codes.js";
|
|
13
|
+
import { fail, progress, resolveOutputContext, } from "../../lib/output/index.js";
|
|
14
|
+
import { resolveRef, resolveApiId } from "../../lib/ref-resolver.js";
|
|
15
|
+
export function registerApiDeleteCommand(api) {
|
|
16
|
+
api
|
|
17
|
+
.command("delete <ref>")
|
|
18
|
+
.description("Delete a team-scoped API (name or UUID). Requires --yes.")
|
|
19
|
+
.option("--yes", "Skip the confirmation prompt (required for non-interactive use)")
|
|
20
|
+
.option("--org <uuid>", "Org id override")
|
|
21
|
+
.option("--output <format>", "Output format: text, json, or yaml (default: text)")
|
|
22
|
+
.action(async (ref, opts) => {
|
|
23
|
+
const outCtx = resolveOutputContext(opts);
|
|
24
|
+
if (!ref.trim()) {
|
|
25
|
+
fail(outCtx, ExitCode.USAGE, "API ref is required.");
|
|
26
|
+
}
|
|
27
|
+
if (!opts.yes) {
|
|
28
|
+
fail(outCtx, ExitCode.USAGE, "Refusing to delete without confirmation. Pass --yes to proceed.", { hint: "spec0 api delete <ref> --yes" });
|
|
29
|
+
}
|
|
30
|
+
let authCtx;
|
|
31
|
+
try {
|
|
32
|
+
authCtx = requireOrgContext(opts.org);
|
|
33
|
+
}
|
|
34
|
+
catch (e) {
|
|
35
|
+
fail(outCtx, ExitCode.AUTH_MISSING, e.message, {
|
|
36
|
+
hint: "Set SPEC0_TOKEN + SPEC0_ORG_ID, or run 'spec0 auth login'.",
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
configureSdkAuth(authCtx);
|
|
40
|
+
let apiId;
|
|
41
|
+
try {
|
|
42
|
+
apiId = await resolveApiId(resolveRef(ref, { defaultOrg: authCtx.orgName }));
|
|
43
|
+
}
|
|
44
|
+
catch (e) {
|
|
45
|
+
fail(outCtx, ExitCode.NOT_FOUND, e.message, {
|
|
46
|
+
hint: "Run 'spec0 api list' to see what exists in this org.",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
await PublicApisService.deleteTeamApi({ apiId });
|
|
51
|
+
progress(outCtx, chalk.green(`✓ Deleted API ${ref} (${apiId})`));
|
|
52
|
+
}
|
|
53
|
+
catch (err) {
|
|
54
|
+
if (is401(err)) {
|
|
55
|
+
fail(outCtx, ExitCode.AUTH_MISSING, "Token invalid or expired.", {
|
|
56
|
+
hint: "Run 'spec0 auth login' or refresh SPEC0_TOKEN.",
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
const status = errorStatusCode(err);
|
|
60
|
+
const msg = extractErrorMessage(err) ?? err.message;
|
|
61
|
+
if (status === 404) {
|
|
62
|
+
fail(outCtx, ExitCode.NOT_FOUND, `API ${ref} not found.`, {
|
|
63
|
+
hint: "Run 'spec0 api list' to see what exists in this org.",
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
fail(outCtx, status ? exitCodeForHttpStatus(status) : ExitCode.GENERIC, `api delete failed: ${msg}`);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
//# sourceMappingURL=delete.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"delete.js","sourceRoot":"","sources":["../../../src/commands/api/delete.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,KAAK,EACL,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAC1E,OAAO,EACL,IAAI,EACJ,QAAQ,EACR,oBAAoB,GAErB,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAErE,MAAM,UAAU,wBAAwB,CAAC,GAAY;IACnD,GAAG;SACA,OAAO,CAAC,cAAc,CAAC;SACvB,WAAW,CAAC,0DAA0D,CAAC;SACvE,MAAM,CAAC,OAAO,EAAE,iEAAiE,CAAC;SAClF,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC;SACzC,MAAM,CAAC,mBAAmB,EAAE,oDAAoD,CAAC;SACjF,MAAM,CAAC,KAAK,EAAE,GAAW,EAAE,IAAqD,EAAE,EAAE;QACnF,MAAM,MAAM,GAAG,oBAAoB,CAAC,IAAI,CAAC,CAAC;QAE1C,IAAI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AAC;gBACf,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,YAAY,EAAE,2BAA2B,EAAE;oBAC/D,IAAI,EAAE,gDAAgD;iBACvD,CAAC,CAAC;YACL,CAAC;YACD,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;YACpC,MAAM,GAAG,GAAG,mBAAmB,CAAC,GAAG,CAAC,IAAK,GAAa,CAAC,OAAO,CAAC;YAC/D,IAAI,MAAM,KAAK,GAAG,EAAE,CAAC;gBACnB,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,SAAS,EAAE,OAAO,GAAG,aAAa,EAAE;oBACxD,IAAI,EAAE,sDAAsD;iBAC7D,CAAC,CAAC;YACL,CAAC;YACD,IAAI,CACF,MAAM,EACN,MAAM,CAAC,CAAC,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,EACzD,sBAAsB,GAAG,EAAE,CAC5B,CAAC;QACJ,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/commands/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAMpC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,QAMnD"}
|
|
@@ -4,10 +4,12 @@
|
|
|
4
4
|
import { registerApiListCommand } from "./list.js";
|
|
5
5
|
import { registerApiShowCommand } from "./show.js";
|
|
6
6
|
import { registerApiChangelogCommand } from "./changelog.js";
|
|
7
|
+
import { registerApiDeleteCommand } from "./delete.js";
|
|
7
8
|
export function registerApiCommands(program) {
|
|
8
9
|
const api = program.command("api").description("Manage APIs in your organisation");
|
|
9
10
|
registerApiListCommand(api);
|
|
10
11
|
registerApiShowCommand(api);
|
|
11
12
|
registerApiChangelogCommand(api);
|
|
13
|
+
registerApiDeleteCommand(api);
|
|
12
14
|
}
|
|
13
15
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/commands/api/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AAEvD,MAAM,UAAU,mBAAmB,CAAC,OAAgB;IAClD,MAAM,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,WAAW,CAAC,kCAAkC,CAAC,CAAC;IACnF,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC5B,sBAAsB,CAAC,GAAG,CAAC,CAAC;IAC5B,2BAA2B,CAAC,GAAG,CAAC,CAAC;IACjC,wBAAwB,CAAC,GAAG,CAAC,CAAC;AAChC,CAAC"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* spec0 api show <ref> — single-API metadata.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Prefers the rich internal GET /apis/{apiId}/summary (operations, env configs,
|
|
5
|
+
* subscriber count). A team/public principal (e.g. a SAT) isn't entitled to
|
|
6
|
+
* that endpoint (403) and some ids aren't present there (404), so it falls back
|
|
7
|
+
* to the leaner V1 team-API row, which the same principal can read.
|
|
8
|
+
* Resolves <ref> via ref-resolver: accepts <org>/<api>, bare <api>, or a UUID.
|
|
6
9
|
*/
|
|
7
10
|
import { Command } from "commander";
|
|
8
11
|
export declare function registerApiShowCommand(api: Command): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"show.d.ts","sourceRoot":"","sources":["../../../src/commands/api/show.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"show.d.ts","sourceRoot":"","sources":["../../../src/commands/api/show.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA6CpC,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,OAAO,QA0FlD"}
|
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* spec0 api show <ref> — single-API metadata.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Prefers the rich internal GET /apis/{apiId}/summary (operations, env configs,
|
|
5
|
+
* subscriber count). A team/public principal (e.g. a SAT) isn't entitled to
|
|
6
|
+
* that endpoint (403) and some ids aren't present there (404), so it falls back
|
|
7
|
+
* to the leaner V1 team-API row, which the same principal can read.
|
|
8
|
+
* Resolves <ref> via ref-resolver: accepts <org>/<api>, bare <api>, or a UUID.
|
|
6
9
|
*/
|
|
7
10
|
import chalk from "chalk";
|
|
8
|
-
import {
|
|
11
|
+
import { PublicApisService } from "@spec0/sdk-public-platform";
|
|
12
|
+
import { configureSdkAuth, createOrgApiClient, is401, errorStatusCode, extractErrorMessage, } from "../../lib/api-client.js";
|
|
9
13
|
import { requireOrgContext } from "../../lib/auth-context.js";
|
|
10
|
-
import { ExitCode } from "../../lib/exit-codes.js";
|
|
11
|
-
import { emit, fail, resolveOutputContext } from "../../lib/output/index.js";
|
|
14
|
+
import { ExitCode, exitCodeForHttpStatus } from "../../lib/exit-codes.js";
|
|
15
|
+
import { emit, fail, progress, resolveOutputContext, } from "../../lib/output/index.js";
|
|
12
16
|
import { resolveRef, resolveApiId } from "../../lib/ref-resolver.js";
|
|
13
17
|
import { getDefaultOrgId, getOrgConfig } from "../../lib/config.js";
|
|
14
18
|
export function registerApiShowCommand(api) {
|
|
@@ -41,19 +45,26 @@ export function registerApiShowCommand(api) {
|
|
|
41
45
|
}
|
|
42
46
|
configureSdkAuth(authCtx);
|
|
43
47
|
const client = createOrgApiClient(authCtx);
|
|
48
|
+
// resolveApiId hits PublicApisService.listTeamApis (V1) for names; UUIDs
|
|
49
|
+
// pass through. A name miss throws "No API named …" → NOT_FOUND.
|
|
50
|
+
let apiId;
|
|
44
51
|
try {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
if (!res.api) {
|
|
52
|
-
fail(outCtx, ExitCode.NOT_FOUND, `No API found for ref '${ref}'.`, {
|
|
53
|
-
hint: "Run 'spec0 api list' to see what exists in this org.",
|
|
52
|
+
apiId = await resolveApiId(parsed);
|
|
53
|
+
}
|
|
54
|
+
catch (err) {
|
|
55
|
+
if (is401(err)) {
|
|
56
|
+
fail(outCtx, ExitCode.AUTH_MISSING, "Token invalid or expired.", {
|
|
57
|
+
hint: "Run 'spec0 auth login' or refresh SPEC0_TOKEN.",
|
|
54
58
|
});
|
|
55
59
|
}
|
|
56
|
-
|
|
60
|
+
fail(outCtx, ExitCode.NOT_FOUND, err.message, {
|
|
61
|
+
hint: "Run 'spec0 api list' to see what exists in this org.",
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
let summary;
|
|
65
|
+
try {
|
|
66
|
+
const res = (await client.getJson(`/apis/${apiId}/summary`));
|
|
67
|
+
summary = res.api;
|
|
57
68
|
}
|
|
58
69
|
catch (err) {
|
|
59
70
|
if (is401(err)) {
|
|
@@ -61,15 +72,59 @@ export function registerApiShowCommand(api) {
|
|
|
61
72
|
hint: "Run 'spec0 auth login' or refresh SPEC0_TOKEN.",
|
|
62
73
|
});
|
|
63
74
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
75
|
+
// 403 (principal not entitled to the internal summary) or 404 (id not
|
|
76
|
+
// on that surface) → fall back to the leaner V1 team-API row. Other
|
|
77
|
+
// statuses map to the stable exit code (5xx → SERVER_ERROR, …).
|
|
78
|
+
const status = errorStatusCode(err);
|
|
79
|
+
if (status === 403 || status === 404) {
|
|
80
|
+
summary = await leanSummaryFromList(apiId, parsed);
|
|
81
|
+
if (summary) {
|
|
82
|
+
progress(outCtx, chalk.gray("note: limited metadata — operations, environments and subscribers need internal API access."));
|
|
83
|
+
}
|
|
68
84
|
}
|
|
69
|
-
|
|
85
|
+
else {
|
|
86
|
+
const msg = extractErrorMessage(err) ?? err.message;
|
|
87
|
+
fail(outCtx, status ? exitCodeForHttpStatus(status) : ExitCode.GENERIC, `api show failed: ${msg}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (!summary) {
|
|
91
|
+
fail(outCtx, ExitCode.NOT_FOUND, `No API found for ref '${ref}'.`, {
|
|
92
|
+
hint: "Run 'spec0 api list' to see what exists in this org.",
|
|
93
|
+
});
|
|
70
94
|
}
|
|
95
|
+
emit(outCtx, summary, renderApiShowText);
|
|
71
96
|
});
|
|
72
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Build a lean ApiSummary from the V1 team-API list, used when the rich
|
|
100
|
+
* internal summary is unavailable to the caller (e.g. a team SAT → 403).
|
|
101
|
+
* Matches on the resolved id first, then the name for a `<org>/<api>` ref.
|
|
102
|
+
*/
|
|
103
|
+
async function leanSummaryFromList(apiId, ref) {
|
|
104
|
+
let rows;
|
|
105
|
+
try {
|
|
106
|
+
rows = await PublicApisService.listTeamApis();
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
// The fallback list is itself unavailable (e.g. an org-key principal has no
|
|
110
|
+
// team → 404). Degrade to "not found" rather than crashing.
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
const wantedName = ref.kind === "name" ? ref.api.toLowerCase() : undefined;
|
|
114
|
+
const row = rows.find((r) => r.apiId === apiId) ??
|
|
115
|
+
(wantedName ? rows.find((r) => (r.apiName ?? "").toLowerCase() === wantedName) : undefined);
|
|
116
|
+
if (!row)
|
|
117
|
+
return undefined;
|
|
118
|
+
return {
|
|
119
|
+
apiId: row.apiId,
|
|
120
|
+
apiName: row.apiName,
|
|
121
|
+
version: row.version ?? undefined,
|
|
122
|
+
description: row.description ?? undefined,
|
|
123
|
+
teamId: row.teamId ?? undefined,
|
|
124
|
+
teamName: row.teamName ?? undefined,
|
|
125
|
+
updatedAt: row.updatedAt ?? undefined,
|
|
126
|
+
};
|
|
127
|
+
}
|
|
73
128
|
function renderApiShowText(api) {
|
|
74
129
|
const lines = [];
|
|
75
130
|
lines.push(chalk.bold(`${api.apiName ?? "?"} ${chalk.gray(`v${api.version ?? "?"}`)}`));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"show.js","sourceRoot":"","sources":["../../../src/commands/api/show.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"show.js","sourceRoot":"","sources":["../../../src/commands/api/show.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAC/D,OAAO,EACL,gBAAgB,EAChB,kBAAkB,EAClB,KAAK,EACL,eAAe,EACf,mBAAmB,GACpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,iBAAiB,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,C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,CAAC,mBAAmB,GAAG,CAAC,KAAK,IAAI,GAAG,EAAE,CAAC,CAAC;IAClD,KAAK,CAAC,IAAI,CAAC,mBAAmB,GAAG,CAAC,UAAU,EAAE,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC;IAC7D,KAAK,CAAC,IAAI,CAAC,mBAAmB,GAAG,CAAC,aAAa,EAAE,MAAM,IAAI,CAAC,EAAE,CAAC,CAAC;IAChE,KAAK,CAAC,IAAI,CAAC,mBAAmB,GAAG,CAAC,eAAe,IAAI,CAAC,EAAE,CAAC,CAAC;IAC1D,IAAI,GAAG,CAAC,cAAc;QAAE,KAAK,CAAC,IAAI,CAAC,mBAAmB,GAAG,CAAC,cAAc,EAAE,CAAC,CAAC;IAC5E,IAAI,GAAG,CAAC,aAAa;QAAE,KAAK,CAAC,IAAI,CAAC,mBAAmB,GAAG,CAAC,aAAa,EAAE,CAAC,CAAC;IAC1E,IAAI,GAAG,CAAC,SAAS;QAAE,KAAK,CAAC,IAAI,CAAC,mBAAmB,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;IAClE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;AAC1B,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA8CpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,QAoJpD"}
|
package/dist/commands/auth.js
CHANGED
|
@@ -6,6 +6,7 @@ import { createServer } from "http";
|
|
|
6
6
|
import { randomBytes } from "crypto";
|
|
7
7
|
import open from "open";
|
|
8
8
|
import { getConfig, getDefaultOrgId, getOrgConfig, setOrgConfig, setDefaultOrg, clearConfig, } from "../lib/config.js";
|
|
9
|
+
import { resolveOrgContext } from "../lib/auth-context.js";
|
|
9
10
|
import { resolvedPlatformAppUrl, resolvedPlatformApiUrl } from "../lib/platform-defaults.js";
|
|
10
11
|
import { ExitCode, exit } from "../lib/exit-codes.js";
|
|
11
12
|
function getAppUrl() {
|
|
@@ -15,21 +16,22 @@ function getApiUrl() {
|
|
|
15
16
|
return resolvedPlatformApiUrl();
|
|
16
17
|
}
|
|
17
18
|
function printAuthStatus() {
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
// Reflect the context commands will actually use: SPEC0_* env vars override the stored login
|
|
20
|
+
// (resolveOrgContext applies that precedence). Reading only the stored config here misreported
|
|
21
|
+
// the active target whenever the env vars were set.
|
|
22
|
+
const ctx = resolveOrgContext();
|
|
23
|
+
if (!ctx) {
|
|
20
24
|
console.log(chalk.yellow("Not logged in. Run 'spec0 auth login'."));
|
|
21
25
|
console.log(chalk.gray("For CI/CD, set SPEC0_TOKEN and SPEC0_ORG_ID environment variables."));
|
|
22
26
|
return;
|
|
23
27
|
}
|
|
24
|
-
const
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
}
|
|
29
|
-
console.log(
|
|
30
|
-
console.log(`
|
|
31
|
-
console.log(` API URL: ${org.apiUrl}`);
|
|
32
|
-
console.log(` Key: ${org.keyName ?? "(unnamed)"}`);
|
|
28
|
+
const fromEnv = Boolean((process.env.SPEC0_TOKEN ?? process.env.PLATFORM_API_TOKEN) &&
|
|
29
|
+
(process.env.SPEC0_ORG_ID ?? process.env.PLATFORM_ORG_ID));
|
|
30
|
+
const stored = getOrgConfig(ctx.orgId);
|
|
31
|
+
console.log(chalk.green("✓ Logged in") + (fromEnv ? chalk.gray(" (via environment)") : ""));
|
|
32
|
+
console.log(` Org: ${ctx.orgName ?? ctx.orgId}`);
|
|
33
|
+
console.log(` API URL: ${ctx.apiUrl}`);
|
|
34
|
+
console.log(` Key: ${fromEnv ? "SPEC0_TOKEN (env)" : (stored?.keyName ?? "(unnamed)")}`);
|
|
33
35
|
}
|
|
34
36
|
export function registerAuthCommands(program) {
|
|
35
37
|
// Top-level whoami shorthand
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EACL,SAAS,EACT,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC7F,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,sBAAsB,CAAC;AAEtD,SAAS,SAAS;IAChB,OAAO,sBAAsB,EAAE,CAAC;AAClC,CAAC;AAED,SAAS,SAAS;IAChB,OAAO,sBAAsB,EAAE,CAAC;AAClC,CAAC;AAED,SAAS,eAAe;IACtB,MAAM,
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,YAAY,EAAE,MAAM,MAAM,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAC;AACrC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EACL,SAAS,EACT,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,WAAW,GACZ,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,iBAAiB,EAAE,MAAM,wB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,KAAK,CAAC,KAAK,CAAC,oBAAoB,OAAO,EAAE,CAAC,CAAC,CAAC;IAC1D,CAAC,CAAC,CAAC;AACP,CAAC"}
|
package/dist/commands/mcp.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* spec0 mcp url | test
|
|
2
|
+
* spec0 mcp url | test | install
|
|
3
|
+
*
|
|
4
|
+
* Helpers for pointing MCP clients (Cursor, Claude) at the Spec0 MCP server.
|
|
5
|
+
* The server is a single Streamable HTTP endpoint; a bearer token is optional
|
|
6
|
+
* (anonymous gets the public docs tools, a token unlocks org-scoped tools). The
|
|
7
|
+
* canonical config references `${SPEC0_TOKEN}` so the secret stays in the
|
|
8
|
+
* environment rather than being written into client config files.
|
|
3
9
|
*/
|
|
4
10
|
import { Command } from "commander";
|
|
5
11
|
export declare function registerMcpCommands(program: Command): void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/commands/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAwCpC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,QA6DnD"}
|
package/dist/commands/mcp.js
CHANGED
|
@@ -1,52 +1,70 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* spec0 mcp url | test
|
|
2
|
+
* spec0 mcp url | test | install
|
|
3
|
+
*
|
|
4
|
+
* Helpers for pointing MCP clients (Cursor, Claude) at the Spec0 MCP server.
|
|
5
|
+
* The server is a single Streamable HTTP endpoint; a bearer token is optional
|
|
6
|
+
* (anonymous gets the public docs tools, a token unlocks org-scoped tools). The
|
|
7
|
+
* canonical config references `${SPEC0_TOKEN}` so the secret stays in the
|
|
8
|
+
* environment rather than being written into client config files.
|
|
3
9
|
*/
|
|
4
10
|
import chalk from "chalk";
|
|
5
11
|
import got from "got";
|
|
12
|
+
import { spawnSync } from "node:child_process";
|
|
13
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
14
|
+
import { homedir } from "node:os";
|
|
15
|
+
import { dirname, join } from "node:path";
|
|
6
16
|
import { getDefaultOrgId, getOrgConfig } from "../lib/config.js";
|
|
17
|
+
import { resolvedPlatformMcpBaseUrl, resolvedPlatformMcpUrl } from "../lib/platform-defaults.js";
|
|
7
18
|
import { ExitCode, exit, exitCodeForHttpStatus } from "../lib/exit-codes.js";
|
|
19
|
+
/** Server key used under `mcpServers` in every client config we write. */
|
|
20
|
+
const SERVER_KEY = "spec0";
|
|
21
|
+
/** Bearer header value — references the env var so the token never lands on disk. */
|
|
22
|
+
const AUTH_HEADER = "Bearer ${SPEC0_TOKEN}";
|
|
23
|
+
/** Canonical client config block for the Spec0 MCP server. */
|
|
24
|
+
function canonicalServerConfig(mcpUrl) {
|
|
25
|
+
return {
|
|
26
|
+
url: mcpUrl,
|
|
27
|
+
headers: { Authorization: AUTH_HEADER },
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Exit early (code 3) unless the user is logged in or has env credentials.
|
|
32
|
+
* Mirrors the sibling MCP commands: a default org from config, or SPEC0_TOKEN
|
|
33
|
+
* with an org id, is enough.
|
|
34
|
+
*/
|
|
35
|
+
function requireAuthOrExit() {
|
|
36
|
+
const orgId = process.env.SPEC0_ORG_ID ?? process.env.PLATFORM_ORG_ID ?? getDefaultOrgId();
|
|
37
|
+
const hasEnvToken = Boolean(process.env.SPEC0_TOKEN ?? process.env.PLATFORM_API_TOKEN);
|
|
38
|
+
const hasStoredOrg = Boolean(orgId && getOrgConfig(orgId));
|
|
39
|
+
if (!hasEnvToken && !hasStoredOrg) {
|
|
40
|
+
console.error(chalk.red("Not authenticated. Run 'spec0 auth login'."));
|
|
41
|
+
exit(ExitCode.AUTH_MISSING);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
8
44
|
export function registerMcpCommands(program) {
|
|
9
45
|
const mcp = program.command("mcp").description("MCP server URL and config");
|
|
10
46
|
mcp
|
|
11
47
|
.command("url")
|
|
12
|
-
.description("Print MCP server
|
|
48
|
+
.description("Print MCP server config for Cursor/Claude")
|
|
13
49
|
.action(async () => {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
console.error(chalk.red("Not authenticated. Run 'spec0 auth login'."));
|
|
17
|
-
exit(ExitCode.AUTH_MISSING);
|
|
18
|
-
}
|
|
19
|
-
const org = getOrgConfig(orgId);
|
|
20
|
-
const mcpUrl = `https://mcp.spec0.io/org/${orgId}/mcp`;
|
|
50
|
+
requireAuthOrExit();
|
|
51
|
+
const mcpUrl = resolvedPlatformMcpUrl();
|
|
21
52
|
console.log("Your MCP server URL:");
|
|
22
53
|
console.log(` ${mcpUrl}`);
|
|
23
54
|
console.log("");
|
|
24
|
-
console.log("Add to Cursor
|
|
25
|
-
console.log(JSON.stringify({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
url: mcpUrl,
|
|
29
|
-
apiKey: org.apiKey,
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
}, null, 2));
|
|
55
|
+
console.log("Add to your MCP client config (e.g. Cursor):");
|
|
56
|
+
console.log(JSON.stringify({ mcpServers: { [SERVER_KEY]: canonicalServerConfig(mcpUrl) } }, null, 2));
|
|
57
|
+
console.log("");
|
|
58
|
+
console.log(chalk.dim("SPEC0_TOKEN must be set in the client's environment for auth to succeed."));
|
|
33
59
|
});
|
|
34
60
|
mcp
|
|
35
61
|
.command("test")
|
|
36
62
|
.description("Verify MCP server is responding")
|
|
37
63
|
.action(async () => {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
console.error(chalk.red("Not authenticated. Run 'spec0 auth login'."));
|
|
41
|
-
exit(ExitCode.AUTH_MISSING);
|
|
42
|
-
}
|
|
43
|
-
const org = getOrgConfig(orgId);
|
|
44
|
-
const base = org.apiUrl.replace(/\/$/, "");
|
|
45
|
-
const url = `${base}/mcp/org/${orgId}/health`;
|
|
64
|
+
requireAuthOrExit();
|
|
65
|
+
const url = `${resolvedPlatformMcpBaseUrl()}/health`;
|
|
46
66
|
try {
|
|
47
|
-
const res = await got.get(url
|
|
48
|
-
headers: { Authorization: `Bearer ${org.apiKey}`, "X-Org-Id": orgId },
|
|
49
|
-
});
|
|
67
|
+
const res = await got.get(url);
|
|
50
68
|
console.log(chalk.green("MCP gateway OK:"), res.body);
|
|
51
69
|
}
|
|
52
70
|
catch (e) {
|
|
@@ -55,5 +73,93 @@ export function registerMcpCommands(program) {
|
|
|
55
73
|
exit(status ? exitCodeForHttpStatus(status) : ExitCode.NETWORK_ERROR);
|
|
56
74
|
}
|
|
57
75
|
});
|
|
76
|
+
mcp
|
|
77
|
+
.command("install")
|
|
78
|
+
.description("Install the Spec0 MCP server into Cursor and/or Claude")
|
|
79
|
+
.option("--client <client>", "Target client: cursor, claude, or all", "all")
|
|
80
|
+
.action(async (opts) => {
|
|
81
|
+
requireAuthOrExit();
|
|
82
|
+
const client = opts.client.toLowerCase();
|
|
83
|
+
if (!["cursor", "claude", "all"].includes(client)) {
|
|
84
|
+
console.error(chalk.red(`Unknown client '${opts.client}'. Expected: cursor, claude, or all.`));
|
|
85
|
+
exit(ExitCode.USAGE);
|
|
86
|
+
}
|
|
87
|
+
const mcpUrl = resolvedPlatformMcpUrl();
|
|
88
|
+
if (client === "cursor" || client === "all") {
|
|
89
|
+
installCursor(mcpUrl);
|
|
90
|
+
}
|
|
91
|
+
if (client === "claude" || client === "all") {
|
|
92
|
+
installClaude(mcpUrl);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Read-merge-write `~/.cursor/mcp.json`, setting `mcpServers.spec0` while
|
|
98
|
+
* preserving any other servers already configured there. Creates the file/dir
|
|
99
|
+
* when absent. Pretty-prints with a trailing newline.
|
|
100
|
+
*/
|
|
101
|
+
function installCursor(mcpUrl) {
|
|
102
|
+
const cursorConfigPath = join(homedir(), ".cursor", "mcp.json");
|
|
103
|
+
let config = {};
|
|
104
|
+
if (existsSync(cursorConfigPath)) {
|
|
105
|
+
try {
|
|
106
|
+
const raw = readFileSync(cursorConfigPath, "utf-8").trim();
|
|
107
|
+
if (raw)
|
|
108
|
+
config = JSON.parse(raw);
|
|
109
|
+
}
|
|
110
|
+
catch {
|
|
111
|
+
console.error(chalk.red(`Could not parse existing ${cursorConfigPath}; refusing to overwrite it.`));
|
|
112
|
+
console.error(chalk.dim("Fix or remove the file, then re-run 'spec0 mcp install'."));
|
|
113
|
+
exit(ExitCode.GENERIC);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
const mcpServers = { ...(config.mcpServers ?? {}) };
|
|
117
|
+
mcpServers[SERVER_KEY] = canonicalServerConfig(mcpUrl);
|
|
118
|
+
const merged = { ...config, mcpServers };
|
|
119
|
+
mkdirSync(dirname(cursorConfigPath), { recursive: true });
|
|
120
|
+
writeFileSync(cursorConfigPath, `${JSON.stringify(merged, null, 2)}\n`, "utf-8");
|
|
121
|
+
console.log(chalk.green("Cursor:"), `wrote ${cursorConfigPath}`);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Register the server with Claude via `claude mcp add`. The flag form follows the
|
|
125
|
+
* current Claude CLI: all options precede the server name, the Streamable HTTP
|
|
126
|
+
* transport is selected explicitly (`--transport http`), and the bearer header is
|
|
127
|
+
* passed verbatim so the `${SPEC0_TOKEN}` placeholder is expanded by the client at
|
|
128
|
+
* connect time.
|
|
129
|
+
*
|
|
130
|
+
* If the `claude` binary isn't on PATH (or the invocation fails for any reason)
|
|
131
|
+
* we don't hard-fail: we print the exact command plus the manual JSON so the user
|
|
132
|
+
* can finish by hand.
|
|
133
|
+
*/
|
|
134
|
+
function installClaude(mcpUrl) {
|
|
135
|
+
const args = [
|
|
136
|
+
"mcp",
|
|
137
|
+
"add",
|
|
138
|
+
"--transport",
|
|
139
|
+
"http",
|
|
140
|
+
SERVER_KEY,
|
|
141
|
+
mcpUrl,
|
|
142
|
+
"--header",
|
|
143
|
+
`Authorization: ${AUTH_HEADER}`,
|
|
144
|
+
];
|
|
145
|
+
const printableCommand = `claude mcp add --transport http ${SERVER_KEY} ${mcpUrl} --header "Authorization: ${AUTH_HEADER}"`;
|
|
146
|
+
let result;
|
|
147
|
+
try {
|
|
148
|
+
result = spawnSync("claude", args, { stdio: "inherit" });
|
|
149
|
+
}
|
|
150
|
+
catch {
|
|
151
|
+
// Swallow — handled by the fallback below (e.g. spawn error on some platforms).
|
|
152
|
+
}
|
|
153
|
+
if (result && result.error === undefined && result.status === 0) {
|
|
154
|
+
console.log(chalk.green("Claude:"), "registered MCP server 'spec0'.");
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
// Binary missing or command failed — guide the user instead of failing hard.
|
|
158
|
+
console.log(chalk.yellow("Claude:"), "could not run 'claude mcp add' automatically.");
|
|
159
|
+
console.log("Run this command yourself:");
|
|
160
|
+
console.log(` ${printableCommand}`);
|
|
161
|
+
console.log("");
|
|
162
|
+
console.log("Or add this to your Claude MCP config manually:");
|
|
163
|
+
console.log(JSON.stringify({ mcpServers: { [SERVER_KEY]: { type: "http", ...canonicalServerConfig(mcpUrl) } } }, null, 2));
|
|
58
164
|
}
|
|
59
165
|
//# sourceMappingURL=mcp.js.map
|