@layervai/qurl-mcp 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -19,6 +19,117 @@ It currently supports:
19
19
  - optionally serving LayerV public legal pages
20
20
  - serving a configurable MP4 video playback page
21
21
 
22
+ ## Quick start: no account needed
23
+
24
+ Share an app running on your machine, or a URL, privately from Claude
25
+ Desktop, Claude Code, Cursor, Codex, or any local MCP client. You need no
26
+ account and no API key: with no `QURL_API_KEY` set, the server drives the
27
+ [qURL CLI](https://github.com/layervai/qurl-integrations/tree/main/apps/cli)
28
+ installed on your machine, and the first publish creates this machine's
29
+ identity by itself.
30
+
31
+ **1. Install the qURL CLI** (macOS and Linux; Node.js 22.12 or later is
32
+ needed for the MCP server):
33
+
34
+ ```bash
35
+ (umask 022 && mkdir -p "$HOME/.local/bin" "$HOME/.local/state") && chmod go-w "$HOME/.local" "$HOME/.local/bin" "$HOME/.local/state" && curl -fsSL --proto '=https' https://raw.githubusercontent.com/layervai/qurl-integrations/main/scripts/install.sh | INSTALL_DIR="$HOME/.local/bin" sh
36
+ ```
37
+
38
+ On Windows, download `qurl.exe` from the
39
+ [latest release](https://github.com/layervai/qurl-integrations/releases/latest)
40
+ and put its folder on `PATH`. The server finds `qurl` on `PATH`, and also in
41
+ `~/.local/bin`, `/opt/homebrew/bin`, and `/usr/local/bin`, which many MCP
42
+ clients leave off the `PATH` they give servers. If the CLI is missing, every
43
+ tool answers with this install command instead of failing.
44
+
45
+ **2. Add the server to your MCP client**, with no `env` block.
46
+
47
+ Claude Desktop (`claude_desktop_config.json`) and Cursor (`~/.cursor/mcp.json`):
48
+
49
+ ```json
50
+ {
51
+ "mcpServers": {
52
+ "qurl": {
53
+ "command": "npx",
54
+ "args": ["-y", "@layervai/qurl-mcp"]
55
+ }
56
+ }
57
+ }
58
+ ```
59
+
60
+ Codex (`~/.codex/config.toml`):
61
+
62
+ ```toml
63
+ [mcp_servers.qurl]
64
+ command = "npx"
65
+ args = ["-y", "@layervai/qurl-mcp"]
66
+ ```
67
+
68
+ Claude Code:
69
+
70
+ ```bash
71
+ claude mcp add qurl -- npx -y @layervai/qurl-mcp
72
+ ```
73
+
74
+ **3. Ask for what you want**, for example "share the app on localhost:3000
75
+ with my client". The agent publishes the app (it stays on your machine; the
76
+ CLI's background service keeps the share running), and gives you a
77
+ short-lived link for one person, or turns on access requests so people can
78
+ ask for access.
79
+
80
+ ### Tools without an account
81
+
82
+ | Tool | What it does | CLI command |
83
+ | ---------------------- | ---------------------------------------------------------------------------- | -------------------------------------------------------- |
84
+ | `publish_crid` | Publish a local app or URL privately and return its CRID | `qurl publish <url> [--allow-requests] [--access <mode>]` |
85
+ | `share_by_crid` | Make a short-lived access link for a CRID this machine published | `qurl share <CRID> [--ttl] [--session-duration]` |
86
+ | `list_crids` | List this machine's published resources (read-only) | `qurl list --status active` |
87
+ | `manage_crid_requests` | List, approve by code, or deny access requests; list or remove approved people; turn requests on or off | `qurl requests`, `qurl approve`, `qurl deny`, `qurl grants` |
88
+ | `manage_crid_access` | Private access policy, invitations, and consumer grants | `qurl access <action> <CRID>` |
89
+ | `set_crid_sharing` | Stop, start, or restart sharing a local app | `qurl stop`, `qurl start`, `qurl restart` |
90
+ | `delete_crid` | Delete a resource permanently | `qurl delete <CRID> --yes` |
91
+
92
+ The tools follow the same rules as the qURL agent skill
93
+ (<https://layerv.ai/skills/qurl/SKILL.md>):
94
+
95
+ - Everything is published private. These tools have no option to publish
96
+ publicly.
97
+ - A pending access request is approved only with the six-digit code the
98
+ person gives you. No listing shows a code, and no tool approves by name:
99
+ anyone can type any name, and names come back as unverified data.
100
+ - An access link is a bearer secret for one recipient. A CRID grants nothing
101
+ by itself and is safe to share.
102
+
103
+ The server runs the CLI with an argument array (never a shell), with
104
+ JSON output, closed stdin, a timeout, and bounded output, and it does not
105
+ log what the CLI prints. The tools that need an account key (the qURL link,
106
+ token, session, and upload tools, and the `qurl://` resources and prompts)
107
+ are not listed in this mode.
108
+
109
+ ### With an account key
110
+
111
+ Set `QURL_API_KEY` to a LayerV API key and the server uses the qURL API
112
+ directly, with the full tool set described in the [feature map](#feature-map):
113
+
114
+ ```json
115
+ {
116
+ "mcpServers": {
117
+ "qurl": {
118
+ "command": "npx",
119
+ "args": ["-y", "@layervai/qurl-mcp"],
120
+ "env": { "QURL_API_KEY": "lv_live_xxx" }
121
+ }
122
+ }
123
+ }
124
+ ```
125
+
126
+ ### Remote HTTP server
127
+
128
+ The HTTP transport (`qurl-mcp-http`) serves remote agent runtimes. It is
129
+ account-based: every request carries the caller's qURL API key as a bearer
130
+ token, and it never runs a local CLI. See [HTTP Authentication](#http-authentication)
131
+ and the [LayerV MCP guide](https://layerv.ai/mcp/).
132
+
22
133
  ## Private consumer access
23
134
 
24
135
  Node.js 22.12 or later is required by the shared qURL SDK.
@@ -197,19 +308,11 @@ npm run start:http
197
308
 
198
309
  ## MCP Client Example
199
310
 
200
- If you want to use this server in `stdio` mode with a local MCP client:
201
-
202
- ```json
203
- {
204
- "mcpServers": {
205
- "qurl": {
206
- "command": "npx",
207
- "args": ["@layervai/qurl-mcp"],
208
- "env": { "QURL_API_KEY": "lv_live_xxx" }
209
- }
210
- }
211
- }
212
- ```
311
+ If you want to use this server in `stdio` mode with a local MCP client, use
312
+ the configuration from [Quick start](#quick-start-no-account-needed). Leave
313
+ out `env` to work without an account through the local qURL CLI, or add
314
+ `"env": { "QURL_API_KEY": "lv_live_xxx" }` to use the qURL API with an
315
+ account key.
213
316
 
214
317
  ## Configuration Files
215
318
 
@@ -285,7 +388,9 @@ setting; clients configured for a larger first upload must validate the session
285
388
  with a small qURL API call or a smaller upload first.
286
389
  Size the configured maximum and reverse-proxy concurrency limit together.
287
390
 
288
- Set `QURL_API_KEY` in the environment for `stdio` mode. In HTTP mode, every
391
+ Set `QURL_API_KEY` in the environment for `stdio` mode to use the qURL API.
392
+ Without it, `stdio` mode runs through the local qURL CLI and needs no account
393
+ (see [Quick start](#quick-start-no-account-needed)). In HTTP mode, every
289
394
  client request supplies its own qURL API key as a bearer token.
290
395
 
291
396
  `defaultQurlApiUrl` and `QURL_API_URL` require HTTPS for non-loopback hosts
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAgBA,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAkC1C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAiBA,wBAAsB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CA0C1C"}
package/dist/index.js CHANGED
@@ -4,9 +4,10 @@ import { createRequire } from "node:module";
4
4
  import { fileURLToPath } from "node:url";
5
5
  import { formatErrorForLog, installTimestampedConsole, logInfo } from "./logging.js";
6
6
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
7
- import { MISSING_API_KEY_MESSAGE, QURLClient } from "./client.js";
7
+ import { QURLClient } from "./client.js";
8
8
  import { getDefaultConfigPath, inspectSmtpConfig, loadRuntimeConfig } from "./config.js";
9
- import { createServer } from "./server.js";
9
+ import { QurlCli } from "./qurl-cli.js";
10
+ import { createLocalCliServer, createServer } from "./server.js";
10
11
  installTimestampedConsole();
11
12
  const require = createRequire(import.meta.url);
12
13
  const { version } = require("../package.json");
@@ -16,7 +17,13 @@ export async function main() {
16
17
  const runtimeConfig = loadRuntimeConfig(runtimeConfigPath);
17
18
  const apiKey = runtimeConfig.qurlApiKey ?? "";
18
19
  if (!apiKey) {
19
- console.error(`Warning: ${MISSING_API_KEY_MESSAGE}`);
20
+ // No account key: drive the locally installed qURL CLI, which publishes
21
+ // without an account. The CLI is looked up per tool call, so a missing
22
+ // CLI becomes an install instruction in the tool result, not a startup
23
+ // failure.
24
+ logInfo("QURL_API_KEY is not set: tools run through the local qURL CLI (qurl), which needs no account.");
25
+ await createLocalCliServer(new QurlCli(), version).connect(new StdioServerTransport());
26
+ return;
20
27
  }
21
28
  const smtpInspection = inspectSmtpConfig(runtimeConfigPath);
22
29
  logInfo("Runtime config loaded.");
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,iBAAiB,EAAE,yBAAyB,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,uBAAuB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACzF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,yBAAyB,EAAE,CAAC;AAE5B,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC,iBAAiB,CAAwB,CAAC;AAEtE,MAAM,CAAC,KAAK,UAAU,IAAI;IACxB,IAAI,CAAC;QACH,MAAM,iBAAiB,GAAG,oBAAoB,EAAE,CAAC;QACjD,MAAM,aAAa,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;QAC3D,MAAM,MAAM,GAAG,aAAa,CAAC,UAAU,IAAI,EAAE,CAAC;QAC9C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,CAAC,KAAK,CAAC,YAAY,uBAAuB,EAAE,CAAC,CAAC;QACvD,CAAC;QACD,MAAM,cAAc,GAAG,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;QAC5D,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CAAC,QAAQ,GAAG,CAAC,CAAC;IACvB,CAAC;AACH,CAAC;AAED,MAAM,YAAY,GAChB,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ;IACnC,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IAC3B,YAAY,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACnE,IAAI,YAAY;IAAE,MAAM,IAAI,EAAE,CAAC"}
@@ -0,0 +1,96 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ type CliEnv = Record<string, string | undefined>;
3
+ type CliPlatform = typeof process.platform;
4
+ /**
5
+ * Runs the locally installed qURL CLI (`qurl`) for the no-account stdio mode.
6
+ *
7
+ * Safety rules, all enforced here rather than by callers:
8
+ * - The binary is started directly with an argument array (`shell: false`),
9
+ * so no argument is ever interpreted by a shell.
10
+ * - stdin is closed, so a command that would prompt cannot wait for input.
11
+ * - Every run has a timeout (SIGTERM, then SIGKILL) and bounded stdout and
12
+ * stderr. Output beyond the bound stops the process.
13
+ * - Only machine-readable output (`--output=json`) is parsed. Nothing the CLI
14
+ * prints is logged by this module.
15
+ */
16
+ /** One-line install command for macOS and Linux, from the qURL agent skill. */
17
+ export declare const QURL_CLI_INSTALL_COMMAND = "(umask 022 && mkdir -p \"$HOME/.local/bin\" \"$HOME/.local/state\") && chmod go-w \"$HOME/.local\" \"$HOME/.local/bin\" \"$HOME/.local/state\" && curl -fsSL --proto '=https' https://raw.githubusercontent.com/layervai/qurl-integrations/main/scripts/install.sh | INSTALL_DIR=\"$HOME/.local/bin\" sh";
18
+ export declare const QURL_CLI_MISSING_MESSAGE: string;
19
+ export type QurlCliErrorCode = "cli_missing" | "cli_failed" | "cli_timeout" | "cli_cancelled" | "cli_output_too_large" | "cli_bad_output";
20
+ /**
21
+ * The tool call a CLI run belongs to. The server runs every tool handler in
22
+ * this context with the MCP request's abort signal, so a call that the client
23
+ * cancels (or gives up on at its own timeout) stops the qurl process instead
24
+ * of leaving it running behind a failed call.
25
+ */
26
+ export declare const cliCallContext: AsyncLocalStorage<{
27
+ signal?: CancelSignal;
28
+ }>;
29
+ /** The part of an abort signal a run uses (the MCP request's signal fits it). */
30
+ export type CancelSignal = {
31
+ readonly aborted: boolean;
32
+ addEventListener(type: "abort", listener: () => void, options?: {
33
+ once?: boolean;
34
+ }): void;
35
+ removeEventListener(type: "abort", listener: () => void): void;
36
+ };
37
+ export declare class QurlCliError extends Error {
38
+ readonly code: QurlCliErrorCode;
39
+ readonly exitCode?: number | undefined;
40
+ constructor(code: QurlCliErrorCode, message: string, exitCode?: number | undefined);
41
+ }
42
+ export type QurlCliOptions = {
43
+ /** Environment for the lookup and the child process (default: process.env). */
44
+ env?: CliEnv;
45
+ platform?: CliPlatform;
46
+ homeDir?: string;
47
+ /**
48
+ * Directories searched after PATH. MCP clients often start servers with a
49
+ * minimal PATH that lacks the installer's directories, so the default list
50
+ * holds the places the official installer and Homebrew use.
51
+ */
52
+ fallbackDirs?: string[];
53
+ timeoutMs?: number;
54
+ maxStdoutBytes?: number;
55
+ maxStderrBytes?: number;
56
+ killGraceMs?: number;
57
+ };
58
+ export type QurlCliRunOptions = {
59
+ timeoutMs?: number;
60
+ signal?: CancelSignal;
61
+ };
62
+ /** The surface the CLI-backed tools use; tests may substitute it. */
63
+ export interface IQurlCli {
64
+ runJson(args: string[], options?: QurlCliRunOptions): Promise<unknown>;
65
+ }
66
+ export declare function sanitizeCliText(text: string): string;
67
+ export declare class QurlCli implements IQurlCli {
68
+ private readonly env;
69
+ private readonly platform;
70
+ private readonly fallbackDirs;
71
+ private readonly timeoutMs;
72
+ private readonly maxStdoutBytes;
73
+ private readonly maxStderrBytes;
74
+ private readonly killGraceMs;
75
+ constructor(options?: QurlCliOptions);
76
+ /**
77
+ * Find `qurl` on PATH, then in the fallback directories. Relative PATH
78
+ * entries are skipped: they would resolve against whatever directory the
79
+ * MCP client started this server in. The lookup runs on every call, so a
80
+ * CLI installed while the server runs is found without a restart.
81
+ */
82
+ findBinary(): string | undefined;
83
+ /**
84
+ * Run `qurl <args> --output=json` and return the parsed JSON document.
85
+ * Throws QurlCliError for every failure; its message is safe to show.
86
+ */
87
+ runJson(args: string[], options?: QurlCliRunOptions): Promise<unknown>;
88
+ private running;
89
+ private readonly waiting;
90
+ private acquire;
91
+ private release;
92
+ private childEnv;
93
+ private run;
94
+ }
95
+ export {};
96
+ //# sourceMappingURL=qurl-cli.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qurl-cli.d.ts","sourceRoot":"","sources":["../src/qurl-cli.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AAOrD,KAAK,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC,CAAC;AACjD,KAAK,WAAW,GAAG,OAAO,OAAO,CAAC,QAAQ,CAAC;AAE3C;;;;;;;;;;;GAWG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,wBAAwB,6SAC6P,CAAC;AAEnS,eAAO,MAAM,wBAAwB,QAK+C,CAAC;AAYrF,MAAM,MAAM,gBAAgB,GACxB,aAAa,GACb,YAAY,GACZ,aAAa,GACb,eAAe,GACf,sBAAsB,GACtB,gBAAgB,CAAC;AAErB;;;;;GAKG;AACH,eAAO,MAAM,cAAc;aAAoC,YAAY;EAAK,CAAC;AAEjF,iFAAiF;AACjF,MAAM,MAAM,YAAY,GAAG;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,EAAE,OAAO,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE,OAAO,CAAA;KAAE,GAAG,IAAI,CAAC;IAC1F,mBAAmB,CAAC,IAAI,EAAE,OAAO,EAAE,QAA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Ac,CAAS;IACxC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;gBAEzB,OAAO,GAAE,cAAmB;IAoBxC;;;;;OAKG;IACH,UAAU,IAAI,MAAM,GAAG,SAAS;IAYhC;;;OAGG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,OAAO,GAAE,iBAAsB,GAAG,OAAO,CAAC,OAAO,CAAC;IAyBhF,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAyB;IAEjD,OAAO,CAAC,OAAO;IAsBf,OAAO,CAAC,OAAO;IAKf,OAAO,CAAC,QAAQ;IAQhB,OAAO,CAAC,GAAG;CA2IZ"}
@@ -0,0 +1,331 @@
1
+ import { Buffer } from "node:buffer";
2
+ import { AsyncLocalStorage } from "node:async_hooks";
3
+ import { spawn } from "node:child_process";
4
+ import { accessSync, constants, statSync } from "node:fs";
5
+ import { homedir } from "node:os";
6
+ import { delimiter, isAbsolute, join } from "node:path";
7
+ import { clearTimeout, setTimeout } from "node:timers";
8
+ /**
9
+ * Runs the locally installed qURL CLI (`qurl`) for the no-account stdio mode.
10
+ *
11
+ * Safety rules, all enforced here rather than by callers:
12
+ * - The binary is started directly with an argument array (`shell: false`),
13
+ * so no argument is ever interpreted by a shell.
14
+ * - stdin is closed, so a command that would prompt cannot wait for input.
15
+ * - Every run has a timeout (SIGTERM, then SIGKILL) and bounded stdout and
16
+ * stderr. Output beyond the bound stops the process.
17
+ * - Only machine-readable output (`--output=json`) is parsed. Nothing the CLI
18
+ * prints is logged by this module.
19
+ */
20
+ /** One-line install command for macOS and Linux, from the qURL agent skill. */
21
+ export const QURL_CLI_INSTALL_COMMAND = '(umask 022 && mkdir -p "$HOME/.local/bin" "$HOME/.local/state") && chmod go-w "$HOME/.local" "$HOME/.local/bin" "$HOME/.local/state" && curl -fsSL --proto \'=https\' https://raw.githubusercontent.com/layervai/qurl-integrations/main/scripts/install.sh | INSTALL_DIR="$HOME/.local/bin" sh';
22
+ export const QURL_CLI_MISSING_MESSAGE = "The qURL CLI (qurl) is not installed or could not be found. Show the user this install command and let them run it; do not run it without their approval. On macOS or Linux: " +
23
+ QURL_CLI_INSTALL_COMMAND +
24
+ " On Windows, download qurl.exe from https://github.com/layervai/qurl-integrations/releases/latest and put its folder on PATH. " +
25
+ "No account is needed. This server also looks in ~/.local/bin, so no restart of the MCP client is needed after installing. " +
26
+ "To use a LayerV account instead, set QURL_API_KEY in the MCP server environment.";
27
+ const DEFAULT_TIMEOUT_MS = 60_000;
28
+ const DEFAULT_MAX_STDOUT_BYTES = 1024 * 1024;
29
+ const DEFAULT_MAX_STDERR_BYTES = 64 * 1024;
30
+ const DEFAULT_KILL_GRACE_MS = 5_000;
31
+ // After the process exits, its pipes normally close at once. A grandchild
32
+ // that inherited them (it should not: the CLI's background service is
33
+ // started by the OS service manager) must not hold a tool call open.
34
+ const PIPE_CLOSE_GRACE_MS = 2_000;
35
+ const MAX_ERROR_DETAIL_CHARS = 1_500;
36
+ /**
37
+ * The tool call a CLI run belongs to. The server runs every tool handler in
38
+ * this context with the MCP request's abort signal, so a call that the client
39
+ * cancels (or gives up on at its own timeout) stops the qurl process instead
40
+ * of leaving it running behind a failed call.
41
+ */
42
+ export const cliCallContext = new AsyncLocalStorage();
43
+ /** At most this many qurl processes run at once; later calls wait their turn. */
44
+ const MAX_CONCURRENT_RUNS = 3;
45
+ export class QurlCliError extends Error {
46
+ code;
47
+ exitCode;
48
+ constructor(code, message, exitCode) {
49
+ super(message);
50
+ this.code = code;
51
+ this.exitCode = exitCode;
52
+ this.name = "QurlCliError";
53
+ }
54
+ }
55
+ // Exit codes are the CLI's stable scripting contract.
56
+ const EXIT_MEANINGS = {
57
+ 1: "general failure",
58
+ 2: "usage error: the command was not accepted; do not retry it unchanged",
59
+ 3: "configuration error: upgrade the qURL CLI or fix its configuration",
60
+ 4: "authentication failed: this machine's qURL identity was rejected; tell the user and do not edit qURL's state directory",
61
+ 5: "not found: a wrong CRID, a deleted resource, or a resource this machine does not own",
62
+ 6: "permission denied for this machine's identity",
63
+ 7: "conflict with the resource's current state",
64
+ 8: "invalid input",
65
+ 9: "rate limited: back off for minutes, not seconds",
66
+ 10: "server error: retry once later, then report it",
67
+ 11: "service unavailable: retry with backoff",
68
+ 12: "verification failed: the link did not match the CRID; treat it as tampering, do not retry around it, and tell the user",
69
+ 130: "interrupted",
70
+ };
71
+ // ANSI CSI/OSC escapes and every other control character except newline.
72
+ // eslint-disable-next-line no-control-regex
73
+ const ANSI_PATTERN = /\u001b\[[0-?]*[ -/]*[@-~]|\u001b\][^\u0007\u001b]*(?:\u0007|\u001b\\)/g;
74
+ // eslint-disable-next-line no-control-regex
75
+ const CONTROL_PATTERN = /[\u0000-\u0009\u000b-\u001f\u007f-\u009f\u2028\u2029]/g;
76
+ function formatSeconds(ms) {
77
+ const seconds = Math.max(1, Math.ceil(ms / 1000));
78
+ return `${seconds} second${seconds === 1 ? "" : "s"}`;
79
+ }
80
+ export function sanitizeCliText(text) {
81
+ return text
82
+ .replace(ANSI_PATTERN, "")
83
+ .replace(CONTROL_PATTERN, " ")
84
+ .split("\n")
85
+ .map((line) => line.trim())
86
+ .filter(Boolean)
87
+ .join(" ")
88
+ .slice(0, MAX_ERROR_DETAIL_CHARS);
89
+ }
90
+ function isExecutableFile(file, platform) {
91
+ try {
92
+ if (!statSync(file).isFile())
93
+ return false;
94
+ if (platform !== "win32")
95
+ accessSync(file, constants.X_OK);
96
+ return true;
97
+ }
98
+ catch {
99
+ return false;
100
+ }
101
+ }
102
+ export class QurlCli {
103
+ env;
104
+ platform;
105
+ fallbackDirs;
106
+ timeoutMs;
107
+ maxStdoutBytes;
108
+ maxStderrBytes;
109
+ killGraceMs;
110
+ constructor(options = {}) {
111
+ this.env = options.env ?? process.env;
112
+ this.platform = options.platform ?? process.platform;
113
+ const home = options.homeDir ?? this.env.HOME ?? homedir();
114
+ this.fallbackDirs =
115
+ options.fallbackDirs ??
116
+ (this.platform === "win32"
117
+ ? []
118
+ : [
119
+ join(home, ".local", "bin"),
120
+ "/opt/homebrew/bin",
121
+ "/usr/local/bin",
122
+ "/home/linuxbrew/.linuxbrew/bin",
123
+ ]);
124
+ this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
125
+ this.maxStdoutBytes = options.maxStdoutBytes ?? DEFAULT_MAX_STDOUT_BYTES;
126
+ this.maxStderrBytes = options.maxStderrBytes ?? DEFAULT_MAX_STDERR_BYTES;
127
+ this.killGraceMs = options.killGraceMs ?? DEFAULT_KILL_GRACE_MS;
128
+ }
129
+ /**
130
+ * Find `qurl` on PATH, then in the fallback directories. Relative PATH
131
+ * entries are skipped: they would resolve against whatever directory the
132
+ * MCP client started this server in. The lookup runs on every call, so a
133
+ * CLI installed while the server runs is found without a restart.
134
+ */
135
+ findBinary() {
136
+ const name = this.platform === "win32" ? "qurl.exe" : "qurl";
137
+ const pathDirs = (this.env.PATH ?? this.env.Path ?? "")
138
+ .split(this.platform === "win32" ? ";" : delimiter)
139
+ .filter((dir) => dir && isAbsolute(dir));
140
+ for (const dir of [...pathDirs, ...this.fallbackDirs]) {
141
+ const candidate = join(dir, name);
142
+ if (isExecutableFile(candidate, this.platform))
143
+ return candidate;
144
+ }
145
+ return undefined;
146
+ }
147
+ /**
148
+ * Run `qurl <args> --output=json` and return the parsed JSON document.
149
+ * Throws QurlCliError for every failure; its message is safe to show.
150
+ */
151
+ async runJson(args, options = {}) {
152
+ const binary = this.findBinary();
153
+ if (!binary)
154
+ throw new QurlCliError("cli_missing", QURL_CLI_MISSING_MESSAGE);
155
+ const command = args[0] ?? "";
156
+ const signal = options.signal ?? cliCallContext.getStore()?.signal;
157
+ await this.acquire(signal, command);
158
+ let stdout;
159
+ try {
160
+ stdout = await this.run(binary, [...args, "--output=json"], command, { ...options, signal });
161
+ }
162
+ finally {
163
+ this.release();
164
+ }
165
+ const text = stdout.trim();
166
+ try {
167
+ const parsed = JSON.parse(text);
168
+ if (parsed !== null && typeof parsed === "object" && !Array.isArray(parsed))
169
+ return parsed;
170
+ }
171
+ catch {
172
+ // Reported below.
173
+ }
174
+ throw new QurlCliError("cli_bad_output", `qurl ${command} did not return a JSON document. The command may have taken effect; check with list_crids before retrying, and upgrade the qURL CLI if this repeats.`);
175
+ }
176
+ running = 0;
177
+ waiting = [];
178
+ acquire(signal, command) {
179
+ if (signal?.aborted)
180
+ return Promise.reject(cancelled(command));
181
+ if (this.running < MAX_CONCURRENT_RUNS) {
182
+ this.running += 1;
183
+ return Promise.resolve();
184
+ }
185
+ return new Promise((resolve, reject) => {
186
+ const start = () => {
187
+ signal?.removeEventListener("abort", onAbort);
188
+ this.running += 1;
189
+ resolve();
190
+ };
191
+ const onAbort = () => {
192
+ const index = this.waiting.indexOf(start);
193
+ if (index >= 0)
194
+ this.waiting.splice(index, 1);
195
+ reject(cancelled(command));
196
+ };
197
+ signal?.addEventListener("abort", onAbort, { once: true });
198
+ this.waiting.push(start);
199
+ });
200
+ }
201
+ release() {
202
+ this.running -= 1;
203
+ this.waiting.shift()?.();
204
+ }
205
+ childEnv() {
206
+ // This mode runs only without an account key. An empty key in the
207
+ // environment must not reach the CLI, where it reads as a bad credential.
208
+ const env = { ...this.env };
209
+ delete env.QURL_API_KEY;
210
+ return env;
211
+ }
212
+ run(binary, argv, command, options) {
213
+ const timeoutMs = options.timeoutMs ?? this.timeoutMs;
214
+ return new Promise((resolve, reject) => {
215
+ let child;
216
+ try {
217
+ child = spawn(binary, argv, {
218
+ env: this.childEnv(),
219
+ stdio: ["ignore", "pipe", "pipe"],
220
+ shell: false,
221
+ windowsHide: true,
222
+ });
223
+ }
224
+ catch {
225
+ reject(new QurlCliError("cli_missing", QURL_CLI_MISSING_MESSAGE));
226
+ return;
227
+ }
228
+ const stdoutChunks = [];
229
+ const stderrChunks = [];
230
+ let stdoutBytes = 0;
231
+ let stderrBytes = 0;
232
+ let failure;
233
+ let settled = false;
234
+ let exitCode = null;
235
+ let exitSignal = null;
236
+ let killTimer;
237
+ let closeTimer;
238
+ const exited = () => child.exitCode !== null || child.signalCode !== null;
239
+ const stop = (reason) => {
240
+ failure ??= reason;
241
+ if (exited())
242
+ return;
243
+ child.kill("SIGTERM");
244
+ killTimer ??= setTimeout(() => child.kill("SIGKILL"), this.killGraceMs);
245
+ killTimer.unref?.();
246
+ };
247
+ // A timeout or a cancel that comes after the process exited (while its
248
+ // pipes drain) does not undo a run that finished: only a run that is
249
+ // still going is stopped and reported as such.
250
+ const timer = setTimeout(() => !exited() &&
251
+ stop(new QurlCliError("cli_timeout", `qurl ${command} did not finish within ${formatSeconds(timeoutMs)} and was stopped. It may have taken effect; check with list_crids before retrying.`)), timeoutMs);
252
+ const signal = options.signal;
253
+ const onAbort = () => {
254
+ if (!exited())
255
+ stop(cancelled(command));
256
+ };
257
+ if (signal?.aborted)
258
+ onAbort();
259
+ else
260
+ signal?.addEventListener("abort", onAbort, { once: true });
261
+ const finish = () => {
262
+ if (settled)
263
+ return;
264
+ signal?.removeEventListener("abort", onAbort);
265
+ settled = true;
266
+ clearTimeout(timer);
267
+ if (killTimer)
268
+ clearTimeout(killTimer);
269
+ if (closeTimer)
270
+ clearTimeout(closeTimer);
271
+ child.stdout?.destroy();
272
+ child.stderr?.destroy();
273
+ if (failure) {
274
+ reject(failure);
275
+ return;
276
+ }
277
+ if (exitCode === 0) {
278
+ resolve(Buffer.concat(stdoutChunks).toString("utf8"));
279
+ return;
280
+ }
281
+ const code = exitCode ?? -1;
282
+ const meaning = EXIT_MEANINGS[code] ?? (exitSignal ? `stopped by ${exitSignal}` : "unknown failure");
283
+ const detail = sanitizeCliText(Buffer.concat(stderrChunks).toString("utf8"));
284
+ const upgrade = /unknown (command|flag|shorthand flag)/i.test(detail)
285
+ ? " This qURL CLI may be too old for this tool; upgrade it by running the install command again: " +
286
+ QURL_CLI_INSTALL_COMMAND
287
+ : "";
288
+ reject(new QurlCliError("cli_failed", `qurl ${command} failed (exit ${code}: ${meaning}).${detail ? ` qurl said: ${detail}` : ""}${upgrade}`, code));
289
+ };
290
+ child.stdout?.on("data", (chunk) => {
291
+ stdoutBytes += chunk.length;
292
+ if (stdoutBytes > this.maxStdoutBytes) {
293
+ stop(new QurlCliError("cli_output_too_large", `qurl ${command} returned more output than this server accepts (${this.maxStdoutBytes} bytes) and was stopped.`));
294
+ return;
295
+ }
296
+ stdoutChunks.push(chunk);
297
+ });
298
+ child.stderr?.on("data", (chunk) => {
299
+ if (stderrBytes >= this.maxStderrBytes)
300
+ return;
301
+ const room = this.maxStderrBytes - stderrBytes;
302
+ stderrChunks.push(chunk.subarray(0, room));
303
+ stderrBytes += Math.min(room, chunk.length);
304
+ });
305
+ child.on("error", (error) => {
306
+ if (error.code === "ENOENT" || error.code === "EACCES") {
307
+ failure ??= new QurlCliError("cli_missing", QURL_CLI_MISSING_MESSAGE);
308
+ }
309
+ else {
310
+ failure ??= new QurlCliError("cli_failed", `qurl ${command} could not be started (${error.code ?? "error"}).`);
311
+ }
312
+ finish();
313
+ });
314
+ child.on("exit", (code, signal) => {
315
+ exitCode = code;
316
+ exitSignal = signal;
317
+ closeTimer = setTimeout(finish, PIPE_CLOSE_GRACE_MS);
318
+ closeTimer.unref?.();
319
+ });
320
+ child.on("close", (code, signal) => {
321
+ exitCode ??= code;
322
+ exitSignal ??= signal;
323
+ finish();
324
+ });
325
+ });
326
+ }
327
+ }
328
+ function cancelled(command) {
329
+ return new QurlCliError("cli_cancelled", `qurl ${command} was stopped because the tool call was cancelled. It may have taken effect; check with list_crids before retrying.`);
330
+ }
331
+ //# sourceMappingURL=qurl-cli.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"qurl-cli.js","sourceRoot":"","sources":["../src/qurl-cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,UAA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