corkcrm-mcp 0.36.1 → 0.37.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 +55 -0
- package/dist/cli.d.ts +48 -0
- package/dist/cli.js +421 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.js +21 -8
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
# corkcrm-mcp
|
|
2
|
+
|
|
3
|
+
The MCP server for CorkTasks (corktasks.com), plus two commands that let a script call one CorkTasks tool without handling the API key. The hosted copy at `https://corktasks.com/api/mcp` runs the same tool code; `docs/MCP_HOSTED.md` in the repository says how the two relate.
|
|
4
|
+
|
|
5
|
+
## The MCP server
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
CORK_API_KEY=<key> CONVEX_URL=<convex site url> npx -y corkcrm-mcp@latest
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
With no command, the package starts the server over stdio. Make a key in CorkTasks under Workspace Settings > API Keys. `CONVEX_URL` is the production Convex site URL, ending `.convex.site`.
|
|
12
|
+
|
|
13
|
+
## Sign in once: `corkcrm-mcp login`
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
npm install -g corkcrm-mcp
|
|
17
|
+
corkcrm-mcp login
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
- It asks for the key with hidden input. Piped stdin works too: the first line is the key.
|
|
21
|
+
- It checks the key with one `whoami` call, then saves `{url, key}` to `~/.config/corktasks/credentials.json`. The file is `0600` and its folder `0700`, so only you can read it.
|
|
22
|
+
- It prints who you signed in as and where the file is. It never prints the key.
|
|
23
|
+
- `--url` defaults to `CONVEX_URL`, then to the URL already saved, then to the live app, `https://hip-dog-509.convex.site`. It must be `https`; `http` is accepted only for `localhost` and `127.0.0.1`.
|
|
24
|
+
- Run `login` again to replace the key; delete the file to sign out.
|
|
25
|
+
- The key is never accepted as an argument, because arguments land in shell history.
|
|
26
|
+
|
|
27
|
+
## Call one tool: `corkcrm-mcp call <tool>`
|
|
28
|
+
|
|
29
|
+
```sh
|
|
30
|
+
echo '{"text":"Hello","session":"<session id>","message_id":"<id>","app":"claude_code"}' \
|
|
31
|
+
| corkcrm-mcp call add_note --timeout 5000
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
- stdin is one JSON object: the tool's arguments, sent as they are.
|
|
35
|
+
- It posts them to `<url>/mcp/<tool>` with the saved key. `CORK_API_KEY` and `CONVEX_URL` in the environment win over the saved file only when both are set; otherwise the saved key and URL are used as a pair, so the saved key never goes to a URL only the environment named.
|
|
36
|
+
- On success it prints the server's answer as one line of JSON on stdout.
|
|
37
|
+
- On failure it prints one line on stderr, `corkcrm-mcp call: <reason>`, and nothing on stdout.
|
|
38
|
+
- `--timeout` is in milliseconds, default 8000. It bounds the whole command: reading stdin, then the request with the time left. The process exits as soon as it is reached.
|
|
39
|
+
|
|
40
|
+
### From a hook or script: use an installed copy
|
|
41
|
+
|
|
42
|
+
A Claude Code hook, or any script with a short time limit, should run an installed copy (`npm install -g corkcrm-mcp`, then `corkcrm-mcp call ...`), not `npx -y corkcrm-mcp@latest`. `npx` checks the npm registry on every run, before the command starts and outside `--timeout`, so a slow registry or a network outage makes the hook late. Update the installed copy with `npm install -g corkcrm-mcp@latest`.
|
|
43
|
+
|
|
44
|
+
## Exit codes (`login` and `call`)
|
|
45
|
+
|
|
46
|
+
| Code | Meaning |
|
|
47
|
+
| --- | --- |
|
|
48
|
+
| 0 | Done. |
|
|
49
|
+
| 1 | Bad command line, bad JSON on stdin, or stdin did not close within `--timeout`. Nothing was sent. |
|
|
50
|
+
| 2 | The server refused the call: its `error` code and message are on stderr. |
|
|
51
|
+
| 3 | Not signed in on this computer, or the server rejected the key (HTTP 401). |
|
|
52
|
+
| 4 | Network error, timeout, or server error (5xx). Safe to retry; `add_note` with the same `session` and `message_id` writes once. |
|
|
53
|
+
| 5 | This computer failed: `login` could not save the sign-in file, or the command hit an unexpected error. |
|
|
54
|
+
|
|
55
|
+
`corkcrm-mcp help` prints the same summary.
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
export declare const EXIT: {
|
|
2
|
+
readonly ok: 0;
|
|
3
|
+
/** Bad command line or bad JSON on stdin. */
|
|
4
|
+
readonly usage: 1;
|
|
5
|
+
/** The server answered and refused the call: HTTP 200 with `error`, or a 4xx other than 401. */
|
|
6
|
+
readonly refused: 2;
|
|
7
|
+
/** No sign-in on this computer, or the server rejected the key (401). */
|
|
8
|
+
readonly auth: 3;
|
|
9
|
+
/** The server could not be reached, timed out, answered 5xx, or answered something unreadable. */
|
|
10
|
+
readonly network: 4;
|
|
11
|
+
/** This computer failed: the sign-in could not be saved, or the command hit an unexpected error. */
|
|
12
|
+
readonly local: 5;
|
|
13
|
+
};
|
|
14
|
+
/** The live CorkTasks deployment's Convex site URL. Not a secret; --url and CONVEX_URL override it. */
|
|
15
|
+
export declare const DEFAULT_URL = "https://hip-dog-509.convex.site";
|
|
16
|
+
export declare const DEFAULT_CALL_TIMEOUT_MS = 8000;
|
|
17
|
+
export declare const USAGE = "Usage:\n corkcrm-mcp Start the MCP server over stdio (needs CORK_API_KEY and CONVEX_URL).\n corkcrm-mcp login [--url <url>] Sign this computer in to CorkTasks. Asks for an API key with hidden input\n (or reads it from piped stdin), checks it, and saves it to\n ~/.config/corktasks/credentials.json, readable only by you (0600).\n --url is the Convex site URL, ending .convex.site; it defaults to\n CONVEX_URL, then to the URL already saved, then to https://hip-dog-509.convex.site.\n corkcrm-mcp call <tool> [--timeout <ms>]\n Read one JSON object of arguments from stdin, call <tool> with the\n saved sign-in, and print the answer as one line of JSON.\n --timeout bounds the whole call, reading stdin included; it\n defaults to 8000 ms.\n corkcrm-mcp help Show this.\n\nCORK_API_KEY and CONVEX_URL in the environment win over the saved sign-in when both are set.\nMake a key in CorkTasks under Workspace Settings > API Keys. Never pass it as an argument.\nA hook should run an installed copy (npm install -g corkcrm-mcp), not npx, which checks the registry first.\n\nExit codes for login and call: 0 ok, 1 bad command line or input (or stdin open past --timeout), 2 the server refused the call,\n3 not signed in or the key was rejected, 4 network error, timeout, or server error,\n5 the sign-in could not be saved or the command failed unexpectedly.\n";
|
|
18
|
+
export type CliIO = {
|
|
19
|
+
env: NodeJS.ProcessEnv;
|
|
20
|
+
/** Home directory; the credentials file lives under it. */
|
|
21
|
+
home: string;
|
|
22
|
+
stdout: (text: string) => void;
|
|
23
|
+
stderr: (text: string) => void;
|
|
24
|
+
/** All of stdin as text (call's arguments). */
|
|
25
|
+
readStdin: () => Promise<string>;
|
|
26
|
+
/** Asks for the key without echoing it; with stdin not a terminal, reads its first line. */
|
|
27
|
+
readSecret: (prompt: string) => Promise<string>;
|
|
28
|
+
};
|
|
29
|
+
export type Credentials = {
|
|
30
|
+
url: string;
|
|
31
|
+
key: string;
|
|
32
|
+
};
|
|
33
|
+
export declare const credentialsPath: (home: string) => string;
|
|
34
|
+
/** "https://x.convex.site/" -> "https://x.convex.site"; null unless https, or http to this computer. */
|
|
35
|
+
export declare function normalizeUrl(raw: string): string | null;
|
|
36
|
+
/** The saved sign-in, or null when the file is missing or unreadable. Never throws, never logs the content. */
|
|
37
|
+
export declare function readCredentials(home: string): Promise<Partial<Credentials> | null>;
|
|
38
|
+
/** Writes the file at 0600 in a 0700 folder: a temporary file first, then a rename, so a reader never sees half. */
|
|
39
|
+
export declare function writeCredentials(home: string, creds: Credentials): Promise<string>;
|
|
40
|
+
/** Runs one command; returns the exit code. Never throws. */
|
|
41
|
+
export declare function runCli(argv: string[], io: CliIO): Promise<number>;
|
|
42
|
+
export declare const CLI_COMMANDS: string[];
|
|
43
|
+
/** Reads all of process.stdin as text. */
|
|
44
|
+
export declare function readProcessStdin(): Promise<string>;
|
|
45
|
+
/** Hidden prompt on a terminal: raw mode, nothing echoed. Piped stdin: its first line. */
|
|
46
|
+
export declare function readProcessSecret(prompt: string): Promise<string>;
|
|
47
|
+
/** The real process's IO for runCli. */
|
|
48
|
+
export declare const processIO: () => CliIO;
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
// The command-line mode of corkcrm-mcp: `login` stores a person's CorkTasks key once per computer, and
|
|
2
|
+
// `call <tool>` posts one tool call with it, so a script (a Claude Code hook) can call a tool without ever
|
|
3
|
+
// seeing the key, the way a script that runs `gh` never sees the GitHub token. index.ts sends argv here
|
|
4
|
+
// when its first word is a command; with no command it starts the stdio server as before.
|
|
5
|
+
//
|
|
6
|
+
// The key is read only from a hidden prompt (or piped stdin) or CORK_API_KEY, never from an argument, and
|
|
7
|
+
// is never printed, logged, or put in an error message.
|
|
8
|
+
import { randomBytes } from "node:crypto";
|
|
9
|
+
import { chmod, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
10
|
+
import { homedir } from "node:os";
|
|
11
|
+
import { dirname, join } from "node:path";
|
|
12
|
+
export const EXIT = {
|
|
13
|
+
ok: 0,
|
|
14
|
+
/** Bad command line or bad JSON on stdin. */
|
|
15
|
+
usage: 1,
|
|
16
|
+
/** The server answered and refused the call: HTTP 200 with `error`, or a 4xx other than 401. */
|
|
17
|
+
refused: 2,
|
|
18
|
+
/** No sign-in on this computer, or the server rejected the key (401). */
|
|
19
|
+
auth: 3,
|
|
20
|
+
/** The server could not be reached, timed out, answered 5xx, or answered something unreadable. */
|
|
21
|
+
network: 4,
|
|
22
|
+
/** This computer failed: the sign-in could not be saved, or the command hit an unexpected error. */
|
|
23
|
+
local: 5,
|
|
24
|
+
};
|
|
25
|
+
/** The live CorkTasks deployment's Convex site URL. Not a secret; --url and CONVEX_URL override it. */
|
|
26
|
+
export const DEFAULT_URL = "https://hip-dog-509.convex.site";
|
|
27
|
+
export const DEFAULT_CALL_TIMEOUT_MS = 8_000;
|
|
28
|
+
const LOGIN_TIMEOUT_MS = 15_000;
|
|
29
|
+
const MESSAGE_MAX = 300;
|
|
30
|
+
export const USAGE = `Usage:
|
|
31
|
+
corkcrm-mcp Start the MCP server over stdio (needs CORK_API_KEY and CONVEX_URL).
|
|
32
|
+
corkcrm-mcp login [--url <url>] Sign this computer in to CorkTasks. Asks for an API key with hidden input
|
|
33
|
+
(or reads it from piped stdin), checks it, and saves it to
|
|
34
|
+
~/.config/corktasks/credentials.json, readable only by you (0600).
|
|
35
|
+
--url is the Convex site URL, ending .convex.site; it defaults to
|
|
36
|
+
CONVEX_URL, then to the URL already saved, then to ${DEFAULT_URL}.
|
|
37
|
+
corkcrm-mcp call <tool> [--timeout <ms>]
|
|
38
|
+
Read one JSON object of arguments from stdin, call <tool> with the
|
|
39
|
+
saved sign-in, and print the answer as one line of JSON.
|
|
40
|
+
--timeout bounds the whole call, reading stdin included; it
|
|
41
|
+
defaults to ${DEFAULT_CALL_TIMEOUT_MS} ms.
|
|
42
|
+
corkcrm-mcp help Show this.
|
|
43
|
+
|
|
44
|
+
CORK_API_KEY and CONVEX_URL in the environment win over the saved sign-in when both are set.
|
|
45
|
+
Make a key in CorkTasks under Workspace Settings > API Keys. Never pass it as an argument.
|
|
46
|
+
A hook should run an installed copy (npm install -g corkcrm-mcp), not npx, which checks the registry first.
|
|
47
|
+
|
|
48
|
+
Exit codes for login and call: 0 ok, 1 bad command line or input (or stdin open past --timeout), 2 the server refused the call,
|
|
49
|
+
3 not signed in or the key was rejected, 4 network error, timeout, or server error,
|
|
50
|
+
5 the sign-in could not be saved or the command failed unexpectedly.
|
|
51
|
+
`;
|
|
52
|
+
export const credentialsPath = (home) => join(home, ".config", "corktasks", "credentials.json");
|
|
53
|
+
const LOCAL_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
54
|
+
/** "https://x.convex.site/" -> "https://x.convex.site"; null unless https, or http to this computer. */
|
|
55
|
+
export function normalizeUrl(raw) {
|
|
56
|
+
const trimmed = raw.trim();
|
|
57
|
+
try {
|
|
58
|
+
const u = new URL(trimmed);
|
|
59
|
+
if (u.protocol === "http:" ? !LOCAL_HOSTS.has(u.hostname) : u.protocol !== "https:")
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
catch {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
return trimmed.replace(/\/+$/, "");
|
|
66
|
+
}
|
|
67
|
+
/** The saved sign-in, or null when the file is missing or unreadable. Never throws, never logs the content. */
|
|
68
|
+
export async function readCredentials(home) {
|
|
69
|
+
let text;
|
|
70
|
+
try {
|
|
71
|
+
text = await readFile(credentialsPath(home), "utf8");
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
try {
|
|
77
|
+
const parsed = JSON.parse(text);
|
|
78
|
+
if (!parsed || typeof parsed !== "object")
|
|
79
|
+
return null;
|
|
80
|
+
const { url, key } = parsed;
|
|
81
|
+
return { url: typeof url === "string" ? url : undefined, key: typeof key === "string" ? key : undefined };
|
|
82
|
+
}
|
|
83
|
+
catch {
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
/** Writes the file at 0600 in a 0700 folder: a temporary file first, then a rename, so a reader never sees half. */
|
|
88
|
+
export async function writeCredentials(home, creds) {
|
|
89
|
+
const path = credentialsPath(home);
|
|
90
|
+
const dir = dirname(path);
|
|
91
|
+
await mkdir(dir, { recursive: true, mode: 0o700 });
|
|
92
|
+
await chmod(dir, 0o700);
|
|
93
|
+
const tmp = join(dir, `.credentials.${randomBytes(6).toString("hex")}.tmp`);
|
|
94
|
+
try {
|
|
95
|
+
await writeFile(tmp, `${JSON.stringify({ url: creds.url, key: creds.key }, null, 2)}\n`, { mode: 0o600, flag: "wx" });
|
|
96
|
+
await chmod(tmp, 0o600);
|
|
97
|
+
await rename(tmp, path);
|
|
98
|
+
}
|
|
99
|
+
catch (e) {
|
|
100
|
+
await rm(tmp, { force: true });
|
|
101
|
+
throw e;
|
|
102
|
+
}
|
|
103
|
+
await chmod(path, 0o600);
|
|
104
|
+
return path;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* CORK_API_KEY and CONVEX_URL when both are set, else the saved file, always as a pair: a saved key is never
|
|
108
|
+
* sent to a URL that only the environment named. A file with a key and no URL uses DEFAULT_URL.
|
|
109
|
+
*/
|
|
110
|
+
async function resolveCredentials(io) {
|
|
111
|
+
const envKey = io.env.CORK_API_KEY?.trim();
|
|
112
|
+
const envUrl = io.env.CONVEX_URL?.trim();
|
|
113
|
+
if (envKey && envUrl)
|
|
114
|
+
return { key: envKey, url: envUrl };
|
|
115
|
+
const saved = (await readCredentials(io.home)) ?? {};
|
|
116
|
+
return { key: saved.key, url: saved.key ? (saved.url ?? DEFAULT_URL) : saved.url };
|
|
117
|
+
}
|
|
118
|
+
/** Rejects with a TimeoutError-named error after ms. */
|
|
119
|
+
function withDeadline(promise, ms, message) {
|
|
120
|
+
let timer;
|
|
121
|
+
const deadline = new Promise((_, reject) => {
|
|
122
|
+
timer = setTimeout(() => {
|
|
123
|
+
const e = new Error(message);
|
|
124
|
+
e.name = "TimeoutError";
|
|
125
|
+
reject(e);
|
|
126
|
+
}, ms);
|
|
127
|
+
});
|
|
128
|
+
return Promise.race([promise, deadline]).finally(() => clearTimeout(timer));
|
|
129
|
+
}
|
|
130
|
+
/** One line, capped, with the key scrubbed out in case a server ever echoes it back. */
|
|
131
|
+
function oneLine(text, key) {
|
|
132
|
+
let s = text.replace(/\s+/g, " ").trim();
|
|
133
|
+
if (key && key.length >= 4)
|
|
134
|
+
s = s.split(key).join("[key]");
|
|
135
|
+
return s.length > MESSAGE_MAX ? `${s.slice(0, MESSAGE_MAX - 3)}...` : s;
|
|
136
|
+
}
|
|
137
|
+
function hostOf(url) {
|
|
138
|
+
try {
|
|
139
|
+
return new URL(url).host;
|
|
140
|
+
}
|
|
141
|
+
catch {
|
|
142
|
+
return "the server";
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
/** --name value and --name=value; flags listed in `known` only. */
|
|
146
|
+
function parseArgs(args, known) {
|
|
147
|
+
const positional = [];
|
|
148
|
+
const flags = {};
|
|
149
|
+
for (let i = 0; i < args.length; i++) {
|
|
150
|
+
const a = args[i];
|
|
151
|
+
if (!a.startsWith("--")) {
|
|
152
|
+
positional.push(a);
|
|
153
|
+
continue;
|
|
154
|
+
}
|
|
155
|
+
const eq = a.indexOf("=");
|
|
156
|
+
const name = eq === -1 ? a.slice(2) : a.slice(2, eq);
|
|
157
|
+
if (!known.includes(name))
|
|
158
|
+
return `Unknown option --${name}.`;
|
|
159
|
+
const value = eq === -1 ? args[++i] : a.slice(eq + 1);
|
|
160
|
+
if (value === undefined || value === "")
|
|
161
|
+
return `--${name} needs a value.`;
|
|
162
|
+
flags[name] = value;
|
|
163
|
+
}
|
|
164
|
+
return { positional, flags };
|
|
165
|
+
}
|
|
166
|
+
/** reportedMs is the budget named in a timeout message: call's whole --timeout, not the part left for the request. */
|
|
167
|
+
async function post(url, key, body, timeoutMs, reportedMs = timeoutMs) {
|
|
168
|
+
let response;
|
|
169
|
+
let text;
|
|
170
|
+
try {
|
|
171
|
+
response = await fetch(url, {
|
|
172
|
+
method: "POST",
|
|
173
|
+
headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
|
|
174
|
+
body,
|
|
175
|
+
signal: AbortSignal.timeout(timeoutMs),
|
|
176
|
+
});
|
|
177
|
+
text = await response.text();
|
|
178
|
+
}
|
|
179
|
+
catch (e) {
|
|
180
|
+
const name = e instanceof Error ? e.name : "";
|
|
181
|
+
if (name === "TimeoutError" || name === "AbortError") {
|
|
182
|
+
return { kind: "network", message: `${hostOf(url)} did not answer within ${reportedMs} ms.` };
|
|
183
|
+
}
|
|
184
|
+
const cause = e instanceof Error && e.cause instanceof Error ? `: ${e.cause.message}` : "";
|
|
185
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
186
|
+
return { kind: "network", message: `Could not reach ${hostOf(url)}: ${message}${cause}.` };
|
|
187
|
+
}
|
|
188
|
+
let parsed = undefined;
|
|
189
|
+
try {
|
|
190
|
+
parsed = JSON.parse(text);
|
|
191
|
+
}
|
|
192
|
+
catch {
|
|
193
|
+
parsed = undefined;
|
|
194
|
+
}
|
|
195
|
+
if (response.status === 200) {
|
|
196
|
+
if (parsed === undefined)
|
|
197
|
+
return { kind: "network", message: `${hostOf(url)} answered HTTP 200 with a body that is not JSON.` };
|
|
198
|
+
return { kind: "ok", status: 200, body: parsed };
|
|
199
|
+
}
|
|
200
|
+
return { kind: "http", status: response.status, body: parsed };
|
|
201
|
+
}
|
|
202
|
+
function errorOf(body) {
|
|
203
|
+
if (body && typeof body === "object" && "error" in body) {
|
|
204
|
+
const e = body.error;
|
|
205
|
+
if (e && typeof e === "object") {
|
|
206
|
+
const { code, message } = e;
|
|
207
|
+
return { code: typeof code === "string" ? code : "error", message: typeof message === "string" ? message : "" };
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
const NOT_SIGNED_IN = "Not signed in on this computer. Run `corkcrm-mcp login` once, or set CORK_API_KEY and CONVEX_URL.";
|
|
213
|
+
async function runCall(args, io) {
|
|
214
|
+
const fail = (code, message, key) => {
|
|
215
|
+
io.stderr(`corkcrm-mcp call: ${oneLine(message, key)}\n`);
|
|
216
|
+
return code;
|
|
217
|
+
};
|
|
218
|
+
const parsed = parseArgs(args, ["timeout"]);
|
|
219
|
+
if (typeof parsed === "string")
|
|
220
|
+
return fail(EXIT.usage, parsed);
|
|
221
|
+
const [tool, ...rest] = parsed.positional;
|
|
222
|
+
if (!tool)
|
|
223
|
+
return fail(EXIT.usage, "Name the tool: corkcrm-mcp call <tool> < args.json");
|
|
224
|
+
if (rest.length > 0)
|
|
225
|
+
return fail(EXIT.usage, "Arguments go on stdin as one JSON object, not on the command line.");
|
|
226
|
+
if (!/^[a-z][a-z0-9_]{0,63}$/.test(tool))
|
|
227
|
+
return fail(EXIT.usage, `"${tool}" is not a tool name.`);
|
|
228
|
+
let timeoutMs = DEFAULT_CALL_TIMEOUT_MS;
|
|
229
|
+
if (parsed.flags.timeout !== undefined) {
|
|
230
|
+
timeoutMs = Number(parsed.flags.timeout);
|
|
231
|
+
if (!Number.isInteger(timeoutMs) || timeoutMs < 1 || timeoutMs > 600_000) {
|
|
232
|
+
return fail(EXIT.usage, "--timeout is a whole number of milliseconds from 1 to 600000.");
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
// One deadline for the whole call: reading stdin, then the request with whatever time is left.
|
|
236
|
+
const deadline = Date.now() + timeoutMs;
|
|
237
|
+
let input;
|
|
238
|
+
try {
|
|
239
|
+
input = await withDeadline(io.readStdin(), timeoutMs, `stdin did not close within ${timeoutMs} ms.`);
|
|
240
|
+
}
|
|
241
|
+
catch (e) {
|
|
242
|
+
return fail(EXIT.usage, `Could not read stdin: ${e instanceof Error ? e.message : String(e)}`);
|
|
243
|
+
}
|
|
244
|
+
let argsObject;
|
|
245
|
+
try {
|
|
246
|
+
argsObject = input.trim() === "" ? {} : JSON.parse(input);
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
return fail(EXIT.usage, "stdin is not valid JSON. Send one JSON object of the tool's arguments.");
|
|
250
|
+
}
|
|
251
|
+
if (!argsObject || typeof argsObject !== "object" || Array.isArray(argsObject)) {
|
|
252
|
+
return fail(EXIT.usage, "stdin must be one JSON object of the tool's arguments.");
|
|
253
|
+
}
|
|
254
|
+
const creds = await resolveCredentials(io);
|
|
255
|
+
if (!creds.key)
|
|
256
|
+
return fail(EXIT.auth, NOT_SIGNED_IN);
|
|
257
|
+
const url = creds.url ? normalizeUrl(creds.url) : null;
|
|
258
|
+
if (!url) {
|
|
259
|
+
return fail(EXIT.auth, "The CorkTasks URL is not an https URL (http only to localhost). Run `corkcrm-mcp login` again.");
|
|
260
|
+
}
|
|
261
|
+
const left = deadline - Date.now();
|
|
262
|
+
if (left < 1)
|
|
263
|
+
return fail(EXIT.network, `No time left for the request within ${timeoutMs} ms.`);
|
|
264
|
+
const result = await post(`${url}/mcp/${tool}`, creds.key, JSON.stringify(argsObject), left, timeoutMs);
|
|
265
|
+
if (result.kind === "network")
|
|
266
|
+
return fail(EXIT.network, result.message, creds.key);
|
|
267
|
+
if (result.kind === "ok") {
|
|
268
|
+
const error = errorOf(result.body);
|
|
269
|
+
if (error)
|
|
270
|
+
return fail(EXIT.refused, `${error.code}: ${error.message}`, creds.key);
|
|
271
|
+
io.stdout(`${JSON.stringify(result.body)}\n`);
|
|
272
|
+
return EXIT.ok;
|
|
273
|
+
}
|
|
274
|
+
if (result.status === 401) {
|
|
275
|
+
return fail(EXIT.auth, "The server rejected the saved key (HTTP 401). Make a new key and run `corkcrm-mcp login` again.");
|
|
276
|
+
}
|
|
277
|
+
const error = errorOf(result.body);
|
|
278
|
+
if (result.status >= 500) {
|
|
279
|
+
return fail(EXIT.network, `${hostOf(url)} answered HTTP ${result.status}${error?.message ? `: ${error.message}` : "."}`, creds.key);
|
|
280
|
+
}
|
|
281
|
+
return fail(EXIT.refused, error ? `${error.code}: ${error.message} (HTTP ${result.status})` : `HTTP ${result.status} for ${tool}; is the tool name right?`, creds.key);
|
|
282
|
+
}
|
|
283
|
+
async function runLogin(args, io) {
|
|
284
|
+
const fail = (code, message, key) => {
|
|
285
|
+
io.stderr(`corkcrm-mcp login: ${oneLine(message, key)}\n`);
|
|
286
|
+
return code;
|
|
287
|
+
};
|
|
288
|
+
const parsed = parseArgs(args, ["url"]);
|
|
289
|
+
if (typeof parsed === "string")
|
|
290
|
+
return fail(EXIT.usage, parsed);
|
|
291
|
+
if (parsed.positional.length > 0) {
|
|
292
|
+
return fail(EXIT.usage, "login takes no arguments but --url. The key is asked for, never passed on the command line.");
|
|
293
|
+
}
|
|
294
|
+
const saved = await readCredentials(io.home);
|
|
295
|
+
const rawUrl = parsed.flags.url ?? (io.env.CONVEX_URL?.trim() || saved?.url || DEFAULT_URL);
|
|
296
|
+
const url = normalizeUrl(rawUrl);
|
|
297
|
+
if (!url) {
|
|
298
|
+
return fail(EXIT.usage, "The URL must be https, such as https://<deployment>.convex.site (http only to localhost).");
|
|
299
|
+
}
|
|
300
|
+
let key;
|
|
301
|
+
try {
|
|
302
|
+
key = (await io.readSecret("CorkTasks API key (Workspace Settings > API Keys; input hidden): ")).trim();
|
|
303
|
+
}
|
|
304
|
+
catch (e) {
|
|
305
|
+
return fail(EXIT.usage, e instanceof Error ? e.message : "Cancelled.");
|
|
306
|
+
}
|
|
307
|
+
if (!key)
|
|
308
|
+
return fail(EXIT.usage, "No key was entered. Nothing was saved.");
|
|
309
|
+
if (/\s/.test(key))
|
|
310
|
+
return fail(EXIT.usage, "That key has spaces in it. Nothing was saved.");
|
|
311
|
+
const result = await post(`${url}/mcp/whoami`, key, "{}", LOGIN_TIMEOUT_MS);
|
|
312
|
+
if (result.kind === "network")
|
|
313
|
+
return fail(EXIT.network, `${result.message} Nothing was saved.`, key);
|
|
314
|
+
if (result.kind === "http" && result.status === 401) {
|
|
315
|
+
return fail(EXIT.auth, "CorkTasks did not accept that key. Nothing was saved. Make one in Workspace Settings > API Keys.");
|
|
316
|
+
}
|
|
317
|
+
if (result.kind === "http") {
|
|
318
|
+
const what = result.status >= 500 ? EXIT.network : EXIT.refused;
|
|
319
|
+
return fail(what, `${hostOf(url)} answered HTTP ${result.status}. Is ${url} the Convex site URL? Nothing was saved.`, key);
|
|
320
|
+
}
|
|
321
|
+
const error = errorOf(result.body);
|
|
322
|
+
if (error)
|
|
323
|
+
return fail(EXIT.refused, `${error.code}: ${error.message} Nothing was saved.`, key);
|
|
324
|
+
const who = result.body;
|
|
325
|
+
const name = typeof who.user?.name === "string" ? who.user.name : "";
|
|
326
|
+
const workspace = typeof who.workspace?.name === "string" ? who.workspace.name : "";
|
|
327
|
+
let path;
|
|
328
|
+
try {
|
|
329
|
+
path = await writeCredentials(io.home, { url, key });
|
|
330
|
+
}
|
|
331
|
+
catch (e) {
|
|
332
|
+
const message = e instanceof Error ? e.message : String(e);
|
|
333
|
+
return fail(EXIT.local, `Could not save the sign-in: ${message}`, key);
|
|
334
|
+
}
|
|
335
|
+
const as = name ? ` as ${oneLine(name)}${workspace ? ` in ${oneLine(workspace)}` : ""}` : "";
|
|
336
|
+
io.stdout(`Signed in${as}. Saved to ${path} (readable only by you).\n`);
|
|
337
|
+
return EXIT.ok;
|
|
338
|
+
}
|
|
339
|
+
/** Runs one command; returns the exit code. Never throws. */
|
|
340
|
+
export async function runCli(argv, io) {
|
|
341
|
+
const [command, ...rest] = argv;
|
|
342
|
+
try {
|
|
343
|
+
if (command === "login")
|
|
344
|
+
return await runLogin(rest, io);
|
|
345
|
+
if (command === "call")
|
|
346
|
+
return await runCall(rest, io);
|
|
347
|
+
if (command === "help" || command === "--help" || command === "-h") {
|
|
348
|
+
io.stdout(USAGE);
|
|
349
|
+
return EXIT.ok;
|
|
350
|
+
}
|
|
351
|
+
io.stderr(`corkcrm-mcp: unknown command "${oneLine(command ?? "")}".\n${USAGE}`);
|
|
352
|
+
return EXIT.usage;
|
|
353
|
+
}
|
|
354
|
+
catch (e) {
|
|
355
|
+
// Unreachable in practice; kept so a bug never prints a stack (or anything near the key) to a hook.
|
|
356
|
+
io.stderr(`corkcrm-mcp ${command}: ${oneLine(e instanceof Error ? e.message : String(e))}\n`);
|
|
357
|
+
return EXIT.local;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
export const CLI_COMMANDS = ["login", "call", "help", "--help", "-h"];
|
|
361
|
+
/** Reads all of process.stdin as text. */
|
|
362
|
+
export function readProcessStdin() {
|
|
363
|
+
return new Promise((resolve, reject) => {
|
|
364
|
+
const chunks = [];
|
|
365
|
+
process.stdin.on("data", (c) => chunks.push(c));
|
|
366
|
+
process.stdin.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
|
|
367
|
+
process.stdin.on("error", reject);
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
/** Hidden prompt on a terminal: raw mode, nothing echoed. Piped stdin: its first line. */
|
|
371
|
+
export async function readProcessSecret(prompt) {
|
|
372
|
+
const input = process.stdin;
|
|
373
|
+
if (!input.isTTY) {
|
|
374
|
+
const text = await readProcessStdin();
|
|
375
|
+
return text.split(/\r?\n/)[0] ?? "";
|
|
376
|
+
}
|
|
377
|
+
process.stderr.write(prompt);
|
|
378
|
+
return new Promise((resolve, reject) => {
|
|
379
|
+
let buffer = "";
|
|
380
|
+
const finish = () => {
|
|
381
|
+
input.off("data", onData);
|
|
382
|
+
input.setRawMode(false);
|
|
383
|
+
input.pause();
|
|
384
|
+
process.stderr.write("\n");
|
|
385
|
+
};
|
|
386
|
+
const onData = (chunk) => {
|
|
387
|
+
for (const ch of chunk) {
|
|
388
|
+
if (ch === "\r" || ch === "\n" || ch === "\u0004") {
|
|
389
|
+
finish();
|
|
390
|
+
resolve(buffer);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
393
|
+
if (ch === "\u0003") {
|
|
394
|
+
finish();
|
|
395
|
+
reject(new Error("Cancelled. Nothing was saved."));
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
if (ch === "\u007f" || ch === "\b")
|
|
399
|
+
buffer = buffer.slice(0, -1);
|
|
400
|
+
else if (ch >= " ")
|
|
401
|
+
buffer += ch;
|
|
402
|
+
}
|
|
403
|
+
};
|
|
404
|
+
input.setEncoding("utf8");
|
|
405
|
+
input.setRawMode(true);
|
|
406
|
+
input.resume();
|
|
407
|
+
input.on("data", onData);
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
/** The real process's IO for runCli. */
|
|
411
|
+
export const processIO = () => ({
|
|
412
|
+
env: process.env,
|
|
413
|
+
home: homedir(),
|
|
414
|
+
stdout: (t) => process.stdout.write(t),
|
|
415
|
+
stderr: (t) => process.stderr.write(t),
|
|
416
|
+
readStdin: () => process.stdin.isTTY
|
|
417
|
+
? Promise.reject(new Error("stdin is a terminal. Pipe the JSON arguments in: corkcrm-mcp call <tool> < args.json"))
|
|
418
|
+
: readProcessStdin(),
|
|
419
|
+
readSecret: readProcessSecret,
|
|
420
|
+
});
|
|
421
|
+
//# sourceMappingURL=cli.js.map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
|
9
|
-
|
|
2
|
+
import { CLI_COMMANDS, EXIT, processIO, runCli } from "./cli.js";
|
|
3
|
+
const command = process.argv[2];
|
|
4
|
+
if (command !== undefined && CLI_COMMANDS.includes(command)) {
|
|
5
|
+
// login and call (cli.ts): run the command and exit; the server's modules are never loaded. Exit outright
|
|
6
|
+
// once stdout and stderr have flushed: after a timeout, a pending DNS lookup, socket, or stdin read could
|
|
7
|
+
// otherwise keep the process alive well past --timeout.
|
|
8
|
+
const code = await runCli(process.argv.slice(2), processIO()).catch(() => EXIT.local);
|
|
9
|
+
const flush = (stream) => new Promise((resolve) => stream.write("", () => resolve()));
|
|
10
|
+
await Promise.all([flush(process.stdout), flush(process.stderr)]);
|
|
11
|
+
process.exit(code);
|
|
12
|
+
}
|
|
13
|
+
else {
|
|
14
|
+
const { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
|
|
15
|
+
const { getApiKey, getConvexUrl } = await import("./auth.js");
|
|
16
|
+
const { initClient } = await import("./client.js");
|
|
17
|
+
const { buildServer } = await import("./instructions.js");
|
|
18
|
+
initClient(getConvexUrl(), getApiKey());
|
|
19
|
+
const server = buildServer("0.37.0");
|
|
20
|
+
const transport = new StdioServerTransport();
|
|
21
|
+
await server.connect(transport);
|
|
22
|
+
}
|
|
10
23
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEjE,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAEhC,IAAI,OAAO,KAA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