slatebox-mcp 0.3.5 → 0.4.1
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 +13 -9
- package/generated/client.json +574 -681
- package/generated/exec-tool.json +90 -73
- package/generated/guest-client.js +1 -1
- package/generated/slatebox.d.ts +189 -196
- package/package.json +9 -5
- package/src/cli.js +18 -60
- package/src/client/index.js +6 -1
- package/src/{slatebox.js → commands.js} +57 -41
- package/src/mcp.js +96 -0
- package/src/server.js +1 -1
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "slatebox-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"mcpName": "com.slatebox/slatebox",
|
|
5
|
-
"description": "Slatebox is
|
|
5
|
+
"description": "Slatebox is the free, open-source visual intelligence platform for your team and agents: diagrams, flowcharts, mind maps, whiteboards, Gantt plans and presentations you build together on one live canvas, with any agent connected over MCP.",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"mcp",
|
|
8
8
|
"mcp-server",
|
|
@@ -12,12 +12,15 @@
|
|
|
12
12
|
"diagram",
|
|
13
13
|
"flowchart",
|
|
14
14
|
"whiteboard",
|
|
15
|
+
"brainstorming",
|
|
16
|
+
"retrospective",
|
|
15
17
|
"project-planning",
|
|
16
18
|
"gantt",
|
|
17
19
|
"timeline",
|
|
18
20
|
"presentation",
|
|
19
21
|
"mermaid",
|
|
20
22
|
"collaboration",
|
|
23
|
+
"visual-intelligence",
|
|
21
24
|
"open-source",
|
|
22
25
|
"miro-alternative"
|
|
23
26
|
],
|
|
@@ -33,15 +36,16 @@
|
|
|
33
36
|
"license": "MIT",
|
|
34
37
|
"type": "module",
|
|
35
38
|
"bin": {
|
|
36
|
-
"slatebox-mcp": "src/cli.js"
|
|
37
|
-
"slatebox": "src/slatebox.js"
|
|
39
|
+
"slatebox-mcp": "src/cli.js"
|
|
38
40
|
},
|
|
39
41
|
"exports": {
|
|
40
42
|
"./client": {
|
|
41
43
|
"types": "./generated/slatebox.d.ts",
|
|
42
44
|
"default": "./src/client/index.js"
|
|
43
45
|
},
|
|
44
|
-
"./exec": "./src/exec/index.js"
|
|
46
|
+
"./exec": "./src/exec/index.js",
|
|
47
|
+
"./commands": "./src/commands.js",
|
|
48
|
+
"./mcp": "./src/mcp.js"
|
|
45
49
|
},
|
|
46
50
|
"files": [
|
|
47
51
|
"src",
|
package/src/cli.js
CHANGED
|
@@ -5,67 +5,25 @@
|
|
|
5
5
|
// --http [--port N] loopback Streamable HTTP at http://127.0.0.1:N/mcp
|
|
6
6
|
// --typed-tools on|off list the typed tools (default on; or SLATEBOX_MCP_TYPED_TOOLS).
|
|
7
7
|
// exec and describe are always listed.
|
|
8
|
+
// exec | describe ... the terminal commands (the same as `slatebox exec|describe`)
|
|
8
9
|
// SLATEBOX_API_TOKEN is your personal access token; SLATEBOX_BASE_URL (or --base-url) your
|
|
9
10
|
// Slatebox origin. A script runs in this process with your rights: there is no sandbox.
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
import {
|
|
14
|
-
import {
|
|
15
|
-
import {
|
|
16
|
-
import { startHttp } from "./http-server.js";
|
|
17
|
-
import { typedToolsEnabled } from "./typed-tools.js";
|
|
11
|
+
//
|
|
12
|
+
// This package names only the `slatebox-mcp` command. The `slatebox` command belongs to the npm
|
|
13
|
+
// package slatebox, which runs these same commands in its own process.
|
|
14
|
+
import { UsageError } from "./client/index.js";
|
|
15
|
+
import { run } from "./commands.js";
|
|
16
|
+
import { mcpHelp, startMcp } from "./mcp.js";
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
http: { type: "boolean" }, port: { type: "string" }, host: { type: "string" }, "base-url": { type: "string" },
|
|
31
|
-
"typed-tools": { type: "string" },
|
|
32
|
-
} }));
|
|
33
|
-
} catch {
|
|
34
|
-
throw new UsageError("Usage: slatebox-mcp [--base-url ORIGIN] [--typed-tools on|off] [--http [--port N]]");
|
|
35
|
-
}
|
|
36
|
-
const typedOption = values["typed-tools"] ?? process.env.SLATEBOX_MCP_TYPED_TOOLS;
|
|
37
|
-
if (typedOption !== undefined && typedOption !== "" && !/^(on|off|true|false|1|0|yes|no)$/i.test(String(typedOption).trim()))
|
|
38
|
-
throw new UsageError("--typed-tools (or SLATEBOX_MCP_TYPED_TOOLS) is on or off.");
|
|
39
|
-
const typedTools = typedToolsEnabled(typedOption);
|
|
40
|
-
const token = process.env.SLATEBOX_API_TOKEN;
|
|
41
|
-
const baseUrl = apiOrigin(values["base-url"] || process.env.SLATEBOX_BASE_URL || DEFAULT_ORIGIN);
|
|
42
|
-
const generated = defaultGenerated();
|
|
43
|
-
if (!token) {
|
|
44
|
-
// No Slatebox yet: the prompts and the client docs still work;
|
|
45
|
-
// every tool answers that it needs a token. The HTTP server always needs one: it is the bearer.
|
|
46
|
-
if (values.http) throw new UsageError("Set SLATEBOX_API_TOKEN to a personal access token.");
|
|
47
|
-
if (values.port !== undefined || values.host !== undefined) throw new UsageError("--port and --host go with --http.");
|
|
48
|
-
process.stderr.write("SLATEBOX_API_TOKEN is not set: the prompts and the client docs work; the tools need a personal access token.\n");
|
|
49
|
-
const exec = async () => { throw tokenRequired(); };
|
|
50
|
-
await createSlateboxMcpServer({ exec, generated, typedTools }).connect(new StdioServerTransport());
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const client = createClient({ baseUrl, token, generated });
|
|
54
|
-
const exec = createExec({ baseUrl, token, generated });
|
|
55
|
-
const instance = client.instance?.describe ? () => client.instance.describe({}) : undefined;
|
|
56
|
-
const createServerForRequest = () => createSlateboxMcpServer({ exec, generated, instance, typedTools });
|
|
57
|
-
if (!values.http) {
|
|
58
|
-
if (values.port !== undefined || values.host !== undefined) throw new UsageError("--port and --host go with --http.");
|
|
59
|
-
await createServerForRequest().connect(new StdioServerTransport());
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
const port = values.port === undefined ? DEFAULT_HTTP_PORT : Number(values.port);
|
|
63
|
-
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new UsageError("--port is a port number.");
|
|
64
|
-
const listening = await startHttp({ host: values.host ?? "127.0.0.1", port, token, createServerForRequest });
|
|
65
|
-
process.stderr.write(`Slatebox MCP listening at ${listening.url} (loopback only; send your Slatebox token as the bearer token)\n`);
|
|
18
|
+
const argv = process.argv.slice(2);
|
|
19
|
+
if (argv[0] === "--help" || argv[0] === "-h" || argv[0] === "help" || (!["exec", "describe"].includes(argv[0]) && (argv.includes("--help") || argv.includes("-h")))) {
|
|
20
|
+
process.stdout.write(mcpHelp());
|
|
21
|
+
process.exitCode = 0;
|
|
22
|
+
} else if (["exec", "describe"].includes(argv[0])) {
|
|
23
|
+
process.exitCode = await run(argv, { name: "slatebox-mcp" });
|
|
24
|
+
} else {
|
|
25
|
+
startMcp(argv).catch((error) => {
|
|
26
|
+
process.stderr.write(`Slatebox MCP could not start: ${error.message}\n`);
|
|
27
|
+
process.exitCode = error instanceof UsageError ? 2 : 1;
|
|
28
|
+
});
|
|
66
29
|
}
|
|
67
|
-
|
|
68
|
-
main().catch((error) => {
|
|
69
|
-
process.stderr.write(`Slatebox MCP could not start: ${error.message}\n`);
|
|
70
|
-
process.exitCode = error instanceof UsageError ? 2 : 1;
|
|
71
|
-
});
|
package/src/client/index.js
CHANGED
|
@@ -2,8 +2,13 @@
|
|
|
2
2
|
// action, named by its action id (slatebox.slates.get(input)). Types: generated/slatebox.d.ts.
|
|
3
3
|
// Use it in your own code (an AI SDK tool, a script). Outside an exec run it sends no
|
|
4
4
|
// Slatebox-Exec-* headers, so each call is an ordinary API call.
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
5
6
|
import { defaultGenerated } from "../generated.js";
|
|
6
7
|
|
|
8
|
+
// Every call names this package (the server counts calls per client, never their content).
|
|
9
|
+
const { version } = JSON.parse(readFileSync(new URL("../../package.json", import.meta.url), "utf8"));
|
|
10
|
+
export const USER_AGENT = `slatebox-mcp/${version}`;
|
|
11
|
+
|
|
7
12
|
export class SlateboxError extends Error {
|
|
8
13
|
constructor({ code = "error", status = 0, message, details, retryAfter } = {}) {
|
|
9
14
|
super(message || `Slatebox returned HTTP ${status}.`);
|
|
@@ -85,7 +90,7 @@ function retryAfterSeconds(payload, response) {
|
|
|
85
90
|
*/
|
|
86
91
|
export async function sendCall({ baseUrl, token, fetchImpl = fetch, method, input, headers = {} }) {
|
|
87
92
|
const { url, init } = buildRequest(baseUrl, method, input);
|
|
88
|
-
init.headers = { ...init.headers, authorization: `Bearer ${token}`, ...headers };
|
|
93
|
+
init.headers = { ...init.headers, "user-agent": USER_AGENT, authorization: `Bearer ${token}`, ...headers };
|
|
89
94
|
let response;
|
|
90
95
|
try {
|
|
91
96
|
response = await fetchImpl(url, init);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
//
|
|
1
|
+
// The exec and describe commands: run a script against your Slatebox, or learn the client it
|
|
2
|
+
// uses. `run(argv, io)` returns the exit code, so the `slatebox` command (npm package slatebox)
|
|
3
|
+
// runs them in its own process, and `slatebox-mcp exec|describe` runs them here.
|
|
3
4
|
import { readFileSync } from "node:fs";
|
|
4
5
|
import { createInterface } from "node:readline/promises";
|
|
5
6
|
import { parseArgs } from "node:util";
|
|
@@ -13,7 +14,9 @@ const help = `Usage:
|
|
|
13
14
|
slatebox exec FILE | - | -e CODE [--intent TEXT] [--preview] [--confirm ID]
|
|
14
15
|
[--idempotency-key KEY] [--remote] [--json] [--base-url ORIGIN]
|
|
15
16
|
slatebox describe [QUERY] [--method NAME ...] [--json]
|
|
16
|
-
slatebox help
|
|
17
|
+
slatebox exec --help
|
|
18
|
+
|
|
19
|
+
(slatebox-mcp exec and slatebox-mcp describe are the same commands.)
|
|
17
20
|
|
|
18
21
|
exec runs a JavaScript or TypeScript script. The global \`slatebox\` is a typed client for
|
|
19
22
|
what your token may do: slatebox.slates.get({ shareId }), and so on. Top-level await and
|
|
@@ -97,7 +100,7 @@ function readCode(source) {
|
|
|
97
100
|
const shellQuote = (text) => (/^[A-Za-z0-9_./:=@%+-]+$/.test(text) ? text : `'${text.replaceAll("'", `'\\''`)}'`);
|
|
98
101
|
|
|
99
102
|
/** The same command with --confirm and --idempotency-key set: what a person runs to confirm. */
|
|
100
|
-
function confirmCommand(argv, id, key) {
|
|
103
|
+
function confirmCommand(name, argv, id, key) {
|
|
101
104
|
const kept = [];
|
|
102
105
|
for (let i = 0; i < argv.length; i += 1) {
|
|
103
106
|
const arg = argv[i];
|
|
@@ -105,29 +108,28 @@ function confirmCommand(argv, id, key) {
|
|
|
105
108
|
if (arg.startsWith("--confirm=") || arg.startsWith("--idempotency-key=")) continue;
|
|
106
109
|
kept.push(arg);
|
|
107
110
|
}
|
|
108
|
-
return [
|
|
111
|
+
return [name, ...kept, "--confirm", id, "--idempotency-key", key].map(shellQuote).join(" ");
|
|
109
112
|
}
|
|
110
113
|
|
|
111
|
-
async function ask(question) {
|
|
112
|
-
const rl = createInterface({ input:
|
|
114
|
+
async function ask(io, question) {
|
|
115
|
+
const rl = createInterface({ input: io.stdin, output: io.stderr });
|
|
113
116
|
try { return (await rl.question(question)).trim().toLowerCase(); } finally { rl.close(); }
|
|
114
117
|
}
|
|
115
118
|
|
|
116
|
-
async function main() {
|
|
117
|
-
const argv = process.argv.slice(2);
|
|
119
|
+
async function main(argv, io) {
|
|
118
120
|
const args = parse(argv);
|
|
119
|
-
if (args.command === "help") {
|
|
121
|
+
if (args.command === "help") { io.stdout.write(help); return 0; }
|
|
120
122
|
const generated = defaultGenerated();
|
|
121
123
|
if (args.command === "describe") {
|
|
122
124
|
const out = await describe({ query: args.query, methods: args.methods }, { generated });
|
|
123
|
-
if (args.json)
|
|
124
|
-
else if (out.methods.some((m) => m.dts))
|
|
125
|
-
else
|
|
125
|
+
if (args.json) io.stdout.write(JSON.stringify(out, null, 2) + "\n");
|
|
126
|
+
else if (out.methods.some((m) => m.dts)) io.stdout.write(out.methods.map((m) => m.dts).join("\n\n") + "\n\n" + out.types + "\n");
|
|
127
|
+
else io.stdout.write(out.methods.map((m) => `${m.name.padEnd(28)} ${m.title}`).join("\n") + "\n");
|
|
126
128
|
return 0;
|
|
127
129
|
}
|
|
128
|
-
const token =
|
|
130
|
+
const token = io.env.SLATEBOX_API_TOKEN;
|
|
129
131
|
if (!token) throw new UsageError("Set SLATEBOX_API_TOKEN to a personal access token.");
|
|
130
|
-
const baseUrl = apiOrigin(args.baseUrl ??
|
|
132
|
+
const baseUrl = apiOrigin(args.baseUrl ?? io.env.SLATEBOX_BASE_URL ?? DEFAULT_ORIGIN);
|
|
131
133
|
const code = readCode(args.source);
|
|
132
134
|
const intent = args.intent ?? `slatebox exec ${args.source.inline !== undefined ? "-e" : args.source.file}`.slice(0, 200);
|
|
133
135
|
const run = (extra = {}) => {
|
|
@@ -137,42 +139,56 @@ async function main() {
|
|
|
137
139
|
let result = await run();
|
|
138
140
|
if (result.status === "confirmation_required") {
|
|
139
141
|
const { id, reasons } = result.confirmation;
|
|
140
|
-
|
|
142
|
+
io.stderr.write(summaryLine(result) + "\n");
|
|
141
143
|
for (const reason of reasons)
|
|
142
|
-
|
|
143
|
-
if (
|
|
144
|
-
if ((await ask("Save anyway? [y/N] ")) === "y") result = await run({ confirm: id, idempotencyKey: result.idempotencyKey });
|
|
144
|
+
io.stderr.write(` call ${reason.n}: ${reason.rule}${reason.shareId ? " on " + reason.shareId : ""}${reason.count !== undefined ? ` (${reason.count})` : ""}\n`);
|
|
145
|
+
if (io.stdin?.isTTY && io.stderr?.isTTY && args.source.file !== "-") {
|
|
146
|
+
if ((await ask(io, "Save anyway? [y/N] ")) === "y") result = await run({ confirm: id, idempotencyKey: result.idempotencyKey });
|
|
145
147
|
} else {
|
|
146
|
-
|
|
147
|
-
if (args.source.file === "-")
|
|
148
|
-
if (args.json)
|
|
148
|
+
io.stderr.write("To save, run:\n " + confirmCommand(io.name, argv, id, result.idempotencyKey) + "\n");
|
|
149
|
+
if (args.source.file === "-") io.stderr.write(" with the same script on standard input.\n");
|
|
150
|
+
if (args.json) io.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
149
151
|
return 6;
|
|
150
152
|
}
|
|
151
153
|
}
|
|
152
154
|
if (args.json) {
|
|
153
|
-
|
|
155
|
+
io.stdout.write(JSON.stringify(result, null, 2) + "\n");
|
|
154
156
|
} else {
|
|
155
|
-
|
|
156
|
-
if (result.status === "completed")
|
|
157
|
-
else if (result.logs?.length)
|
|
157
|
+
io.stderr.write(summaryLine(result) + "\n");
|
|
158
|
+
if (result.status === "completed") io.stdout.write(JSON.stringify(result.result ?? null, null, 2) + "\n");
|
|
159
|
+
else if (result.logs?.length) io.stderr.write(result.logs.join("\n") + "\n");
|
|
158
160
|
}
|
|
159
161
|
return { completed: 0, failed: 7, confirmation_required: 6 }[result.status] ?? 1;
|
|
160
162
|
}
|
|
161
163
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
164
|
+
/**
|
|
165
|
+
* Run `exec`, `describe` or `help`.
|
|
166
|
+
* @param {string[]} argv the words after the command name, e.g. ["exec", "-e", "return 1"]
|
|
167
|
+
* @param {{env?: object, stdin?: any, stdout?: any, stderr?: any, name?: string}} [io]
|
|
168
|
+
* @returns {Promise<number>} the exit code
|
|
169
|
+
*/
|
|
170
|
+
export async function run(argv, io = {}) {
|
|
171
|
+
const env = io.env ?? process.env;
|
|
172
|
+
const token = env.SLATEBOX_API_TOKEN;
|
|
173
|
+
const redact = (text) => (token ? text.replaceAll(token, "[redacted]") : text);
|
|
174
|
+
// A script or an untrusted endpoint could echo the token; it never reaches the terminal.
|
|
175
|
+
const guard = (stream) => ({
|
|
176
|
+
isTTY: stream.isTTY,
|
|
177
|
+
write: (chunk, ...rest) => stream.write(typeof chunk === "string" ? redact(chunk) : chunk, ...rest),
|
|
178
|
+
});
|
|
179
|
+
const name = io.name ?? "slatebox";
|
|
180
|
+
const streams = { name, env, stdin: io.stdin ?? process.stdin, stdout: guard(io.stdout ?? process.stdout), stderr: guard(io.stderr ?? process.stderr) };
|
|
181
|
+
try {
|
|
182
|
+
return await main(argv, streams);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
const api = error instanceof SlateboxError;
|
|
185
|
+
const status = api ? `HTTP ${error.status} ${error.code}: ` : "";
|
|
186
|
+
streams.stderr.write(`${name}: ${status}${error.message}\n`);
|
|
187
|
+
if (api && error.details !== undefined) streams.stderr.write(JSON.stringify(error.details, null, 2) + "\n");
|
|
188
|
+
const usage = error instanceof UsageError || error instanceof ExecInputError;
|
|
189
|
+
if (usage) streams.stderr.write(`Run ${name} exec --help for usage.\n`);
|
|
190
|
+
return usage ? 2 : api ? exitFor(error.status) : 1;
|
|
191
|
+
}
|
|
168
192
|
}
|
|
169
193
|
|
|
170
|
-
|
|
171
|
-
const api = error instanceof SlateboxError;
|
|
172
|
-
const status = api ? `HTTP ${error.status} ${error.code}: ` : "";
|
|
173
|
-
process.stderr.write(`slatebox: ${status}${error.message}\n`);
|
|
174
|
-
if (api && error.details !== undefined) process.stderr.write(JSON.stringify(error.details, null, 2) + "\n");
|
|
175
|
-
const usage = error instanceof UsageError || error instanceof ExecInputError;
|
|
176
|
-
if (usage) process.stderr.write("Run slatebox help for usage.\n");
|
|
177
|
-
process.exitCode = usage ? 2 : api ? exitFor(error.status) : 1;
|
|
178
|
-
});
|
|
194
|
+
export { help };
|
package/src/mcp.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
// The MCP server: exec and describe, one typed tool per client method, prompts
|
|
2
|
+
// and resources.
|
|
3
|
+
// stdio (default) for agent hosts that start a command
|
|
4
|
+
// --http [--port N] loopback Streamable HTTP at http://127.0.0.1:N/mcp
|
|
5
|
+
// --typed-tools on|off list the typed tools (default on; or SLATEBOX_MCP_TYPED_TOOLS).
|
|
6
|
+
// exec and describe are always listed.
|
|
7
|
+
// SLATEBOX_API_TOKEN is your personal access token; SLATEBOX_BASE_URL (or --base-url) your
|
|
8
|
+
// Slatebox origin. A script runs in this process with your rights: there is no sandbox.
|
|
9
|
+
import { parseArgs } from "node:util";
|
|
10
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
11
|
+
import { apiOrigin, createClient, DEFAULT_ORIGIN, UsageError } from "./client/index.js";
|
|
12
|
+
import { createExec } from "./exec/index.js";
|
|
13
|
+
import { defaultGenerated } from "./generated.js";
|
|
14
|
+
import { createSlateboxMcpServer } from "./server.js";
|
|
15
|
+
import { startHttp } from "./http-server.js";
|
|
16
|
+
import { typedToolsEnabled } from "./typed-tools.js";
|
|
17
|
+
|
|
18
|
+
export const DEFAULT_HTTP_PORT = 3917;
|
|
19
|
+
|
|
20
|
+
/** `slatebox-mcp --help` (and `slatebox mcp --help`, with that name). */
|
|
21
|
+
export function mcpHelp(name = "slatebox-mcp") {
|
|
22
|
+
return `Usage: ${name} [--base-url ORIGIN] [--typed-tools on|off] [--http [--port N]]
|
|
23
|
+
${name === "slatebox-mcp" ? "slatebox-mcp exec | describe ... (the same as slatebox exec | describe; see slatebox-mcp exec --help)" : "slatebox exec | describe ... (see slatebox exec --help)"}
|
|
24
|
+
|
|
25
|
+
The Slatebox MCP server: exec and describe, one typed tool per client method, prompts and resources.
|
|
26
|
+
|
|
27
|
+
(no option) stdio, for agent hosts that start a command
|
|
28
|
+
--http [--port N] loopback Streamable HTTP at http://127.0.0.1:N/mcp (default port ${DEFAULT_HTTP_PORT});
|
|
29
|
+
needs SLATEBOX_API_TOKEN, sent as the bearer token
|
|
30
|
+
--typed-tools on|off list the typed tools (default on; or SLATEBOX_MCP_TYPED_TOOLS);
|
|
31
|
+
exec and describe are always listed
|
|
32
|
+
--base-url ORIGIN your Slatebox (or SLATEBOX_BASE_URL; default ${DEFAULT_ORIGIN})
|
|
33
|
+
--help this text
|
|
34
|
+
|
|
35
|
+
SLATEBOX_API_TOKEN is your personal access token (Profile > Developer in your Slatebox). Without
|
|
36
|
+
one the prompts and the client docs work and every tool says it needs a token. A script runs in
|
|
37
|
+
this process with your rights: there is no sandbox.
|
|
38
|
+
`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** What every tool answers when the server started without a token. */
|
|
42
|
+
function tokenRequired() {
|
|
43
|
+
return Object.assign(new Error("No Slatebox token: set SLATEBOX_API_TOKEN to a personal access token from your Slatebox and restart this server. The prompts work without one."), { code: "sign_in_required", status: 401 });
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Start the MCP server (stdio, or loopback HTTP with --http). `slatebox-mcp` and `slatebox mcp`
|
|
48
|
+
* both call this. It resolves once the server is connected; the process then lives as long as the
|
|
49
|
+
* transport does.
|
|
50
|
+
* @param {string[]} argv options after the command name
|
|
51
|
+
* @param {{env?: object, stderr?: any}} [io]
|
|
52
|
+
*/
|
|
53
|
+
export async function startMcp(argv = [], io = {}) {
|
|
54
|
+
const env = io.env ?? process.env;
|
|
55
|
+
const stderr = io.stderr ?? process.stderr;
|
|
56
|
+
let values;
|
|
57
|
+
try {
|
|
58
|
+
({ values } = parseArgs({ args: argv, options: {
|
|
59
|
+
http: { type: "boolean" }, port: { type: "string" }, host: { type: "string" }, "base-url": { type: "string" },
|
|
60
|
+
"typed-tools": { type: "string" },
|
|
61
|
+
} }));
|
|
62
|
+
} catch {
|
|
63
|
+
throw new UsageError("Usage: slatebox-mcp [--base-url ORIGIN] [--typed-tools on|off] [--http [--port N]]");
|
|
64
|
+
}
|
|
65
|
+
const typedOption = values["typed-tools"] ?? env.SLATEBOX_MCP_TYPED_TOOLS;
|
|
66
|
+
if (typedOption !== undefined && typedOption !== "" && !/^(on|off|true|false|1|0|yes|no)$/i.test(String(typedOption).trim()))
|
|
67
|
+
throw new UsageError("--typed-tools (or SLATEBOX_MCP_TYPED_TOOLS) is on or off.");
|
|
68
|
+
const typedTools = typedToolsEnabled(typedOption);
|
|
69
|
+
const token = env.SLATEBOX_API_TOKEN;
|
|
70
|
+
const baseUrl = apiOrigin(values["base-url"] || env.SLATEBOX_BASE_URL || DEFAULT_ORIGIN);
|
|
71
|
+
const generated = defaultGenerated();
|
|
72
|
+
if (!token) {
|
|
73
|
+
// No Slatebox yet: the prompts and the client docs still work;
|
|
74
|
+
// every tool answers that it needs a token. The HTTP server always needs one: it is the bearer.
|
|
75
|
+
if (values.http) throw new UsageError("Set SLATEBOX_API_TOKEN to a personal access token.");
|
|
76
|
+
if (values.port !== undefined || values.host !== undefined) throw new UsageError("--port and --host go with --http.");
|
|
77
|
+
stderr.write("SLATEBOX_API_TOKEN is not set: the prompts and the client docs work; the tools need a personal access token.\n");
|
|
78
|
+
const exec = async () => { throw tokenRequired(); };
|
|
79
|
+
await createSlateboxMcpServer({ exec, generated, typedTools }).connect(new StdioServerTransport());
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const client = createClient({ baseUrl, token, generated });
|
|
83
|
+
const exec = createExec({ baseUrl, token, generated });
|
|
84
|
+
const instance = client.instance?.describe ? () => client.instance.describe({}) : undefined;
|
|
85
|
+
const createServerForRequest = () => createSlateboxMcpServer({ exec, generated, instance, typedTools });
|
|
86
|
+
if (!values.http) {
|
|
87
|
+
if (values.port !== undefined || values.host !== undefined) throw new UsageError("--port and --host go with --http.");
|
|
88
|
+
await createServerForRequest().connect(new StdioServerTransport());
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const port = values.port === undefined ? DEFAULT_HTTP_PORT : Number(values.port);
|
|
92
|
+
if (!Number.isInteger(port) || port < 0 || port > 65535) throw new UsageError("--port is a port number.");
|
|
93
|
+
const listening = await startHttp({ host: values.host ?? "127.0.0.1", port, token, createServerForRequest });
|
|
94
|
+
stderr.write(`Slatebox MCP listening at ${listening.url} (loopback only; send your Slatebox token as the bearer token)\n`);
|
|
95
|
+
}
|
|
96
|
+
|
package/src/server.js
CHANGED
|
@@ -58,7 +58,7 @@ export function createSlateboxMcpServer({ exec, generated = defaultGenerated(),
|
|
|
58
58
|
const spec = generated.tools;
|
|
59
59
|
const instructions = typedTools ? spec.instructions : spec.instructionsExecOnly ?? spec.instructions;
|
|
60
60
|
const server = new Server(
|
|
61
|
-
{ name: "slatebox", version },
|
|
61
|
+
{ name: "slatebox", ...(spec.server ?? {}), version },
|
|
62
62
|
{ capabilities: { tools: {}, prompts: {}, resources: {} }, ...(instructions ? { instructions } : {}) },
|
|
63
63
|
);
|
|
64
64
|
const tools = toolDefinitions(generated, { typed: typedTools });
|