@taskade/cli 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/README.md +154 -2
- package/bin/cli.mjs +25 -0
- package/package.json +37 -4
- package/src/cli.mjs +146 -0
- package/src/clients.mjs +176 -0
- package/src/config-file.mjs +250 -0
- package/src/doctor.mjs +373 -0
- package/src/plug.mjs +354 -0
- package/src/system.mjs +142 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 TASKCADE INC.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,155 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @taskade/cli
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Connect your AI client to Taskade with one command:
|
|
4
|
+
|
|
5
|
+
```bash
|
|
6
|
+
npx @taskade/cli plug
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
The command lists the MCP clients on your machine and the command to run for each. It changes nothing.
|
|
10
|
+
|
|
11
|
+
## Most people need no CLI
|
|
12
|
+
|
|
13
|
+
Paste this line into your agent. The agent reads the steps and connects itself:
|
|
14
|
+
|
|
15
|
+
```text
|
|
16
|
+
Set up Taskade for me. Read and follow https://www.taskade.com/SKILL.md
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
- The Taskade skills: [taskade/skills](https://github.com/taskade/skills)
|
|
20
|
+
- The Taskade MCP server and plugin: [taskade/mcp](https://github.com/taskade/mcp)
|
|
21
|
+
- The hosted server guide: [Hosted Taskade MCP](https://www.taskade.com/docs/mcp/hosted-mcp)
|
|
22
|
+
|
|
23
|
+
The hosted server is `https://www.taskade.com/mcp`. It is part of every paid Taskade plan. Clients sign in with your Taskade account in the browser (OAuth), so you need no token.
|
|
24
|
+
|
|
25
|
+
## Connect a client: `plug`
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npx @taskade/cli plug claude-code
|
|
29
|
+
npx @taskade/cli plug codex
|
|
30
|
+
npx @taskade/cli plug cursor
|
|
31
|
+
npx @taskade/cli plug vscode
|
|
32
|
+
npx @taskade/cli plug claude-desktop
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
Each command shows the change first. In a terminal, it asks for a "y" before it changes anything. On a pipe or in CI, it only prints. `connect` is an alias of `plug`, and `claude` is an alias of `claude-code`.
|
|
36
|
+
|
|
37
|
+
| Client | What the CLI does | What changes on your machine |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| `claude-code` | Runs `claude mcp add --transport http --scope user taskade https://www.taskade.com/mcp`. | Claude Code adds the server to `~/.claude.json`. With `--project`, it writes `.mcp.json` in the current folder. |
|
|
40
|
+
| `codex` | Runs `codex mcp add taskade --url https://www.taskade.com/mcp`, then `codex mcp login taskade` if the add step did not sign you in. | Codex adds the server to `~/.codex/config.toml` and keeps the sign-in. |
|
|
41
|
+
| `cursor` | Merges one `taskade` entry into the Cursor config file. | `~/.cursor/mcp.json`, or `.cursor/mcp.json` in the current folder with `--project`. |
|
|
42
|
+
| `vscode` | Runs `code --add-mcp` with the `taskade` entry. With `--project`, merges one entry into the file. | Your VS Code user profile, or `.vscode/mcp.json` in the current folder with `--project`. |
|
|
43
|
+
| `claude-desktop` | Prints the 3 steps for the Connectors screen and copies the URL to the clipboard. | Only the clipboard. Claude keeps connectors in your Claude account, not in a file, so the CLI cannot add one for you. |
|
|
44
|
+
|
|
45
|
+
When a client command (`claude`, `codex`, `code`) is not on your PATH, the CLI prints the command and the install step, and exits 0.
|
|
46
|
+
|
|
47
|
+
When the CLI changes a JSON file, it:
|
|
48
|
+
|
|
49
|
+
- Shows the file and the exact change as a diff.
|
|
50
|
+
- Keeps every other key and every other server, and the format of the rest of the file.
|
|
51
|
+
- Writes a backup copy beside the file first (`<file>.bak-<timestamp>`).
|
|
52
|
+
- Writes a temp file, then renames it over the file. The file keeps its mode.
|
|
53
|
+
- Refuses a file that is not valid JSON and leaves it unchanged. (JSON with comments counts as not valid.)
|
|
54
|
+
- Says "Already connected" and changes nothing when an equal `taskade` entry exists. When a different entry exists, it shows both and asks.
|
|
55
|
+
|
|
56
|
+
Run `plug` with no client name to see which clients are on your machine.
|
|
57
|
+
|
|
58
|
+
### Options for `plug`
|
|
59
|
+
|
|
60
|
+
| Option | Effect |
|
|
61
|
+
| --- | --- |
|
|
62
|
+
| `--yes`, `-y` | Apply the change with no question. |
|
|
63
|
+
| `--print` | Show the command or the config block. Change nothing. This is the default on a pipe or in CI. |
|
|
64
|
+
| `--project` | Write the project file of the current folder, not the user file (Claude Code, Cursor, VS Code). |
|
|
65
|
+
| `--token` | Use a personal access token in place of the browser sign-in. See below. |
|
|
66
|
+
|
|
67
|
+
### A machine with no browser: `--token`
|
|
68
|
+
|
|
69
|
+
A headless machine cannot sign in with a browser. Create a personal access token at [https://www.taskade.com/settings/api](https://www.taskade.com/settings/api), put it in the environment variable `TASKADE_TOKEN`, and add `--token`:
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
export TASKADE_TOKEN=... # your token
|
|
73
|
+
npx @taskade/cli plug cursor --token
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
- The CLI reads the token only from `TASKADE_TOKEN`. It refuses a token on the command line, because your shell history keeps it.
|
|
77
|
+
- The CLI never prints the full token. It shows the first 6 characters and "…".
|
|
78
|
+
- The config file then holds your token, and anyone who can read the file can use your Taskade account. A new file gets mode 600. Do not commit a project file that holds a token.
|
|
79
|
+
- Codex keeps only the name `TASKADE_TOKEN` in its config and reads the token from the environment each time it starts.
|
|
80
|
+
- Claude Desktop takes no token from the CLI.
|
|
81
|
+
|
|
82
|
+
## Check a connection: `doctor`
|
|
83
|
+
|
|
84
|
+
```bash
|
|
85
|
+
npx @taskade/cli doctor
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
`doctor` answers "why does my connection fail?" in plain lines. Each line starts with `ok`, `fail`, or `--` (skipped), and a failed line gives the next step. It changes nothing on your machine. `whoami` is an alias of `doctor`.
|
|
89
|
+
|
|
90
|
+
It checks:
|
|
91
|
+
|
|
92
|
+
1. The Node.js version.
|
|
93
|
+
2. The server: a request with no sign-in must return 401 with a `www-authenticate` header that names the sign-in metadata. It then reads that metadata and the metadata of the authorization server.
|
|
94
|
+
3. With `TASKADE_TOKEN` set: an MCP `initialize` request and a `tools/list` request with your token. It reports that the token works and the server lists its tools, or the exact refusal of the server.
|
|
95
|
+
4. The clients on your machine, and whether each one has a `taskade` server entry. It only reads the files.
|
|
96
|
+
|
|
97
|
+
Example, with a token that the server does not accept:
|
|
98
|
+
|
|
99
|
+
```text
|
|
100
|
+
ok The server answers. Without sign-in it returns 401 and names its sign-in metadata.
|
|
101
|
+
ok Sign-in metadata: https://www.taskade.com/mcp/.well-known/oauth-protected-resource
|
|
102
|
+
ok Authorization server: https://www.taskade.com/.well-known/oauth-authorization-server
|
|
103
|
+
|
|
104
|
+
fail The server refused the token (401: Invalid or expired token).
|
|
105
|
+
Next: Create a new token at https://www.taskade.com/settings/api and set TASKADE_TOKEN to it.
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
| Option | Effect |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| `--json` | Print the result as JSON, for scripts. |
|
|
111
|
+
| `--verbose` | Print the names of the tools that the server lists. |
|
|
112
|
+
|
|
113
|
+
The exit code is 0 when every check passes and 1 when a check fails. `doctor` sends your token only to the server URL, and it does not follow a redirect with the token.
|
|
114
|
+
|
|
115
|
+
## Environment
|
|
116
|
+
|
|
117
|
+
| Variable | Use |
|
|
118
|
+
| --- | --- |
|
|
119
|
+
| `TASKADE_TOKEN` | A personal access token. `plug` reads it only with `--token`. `doctor` uses it for the token check. |
|
|
120
|
+
| `TASKADE_MCP_URL` | Another server URL, for tests. It must use `https://`, except for `localhost` and `127.0.0.1`. |
|
|
121
|
+
|
|
122
|
+
## Other commands
|
|
123
|
+
|
|
124
|
+
| Command | Effect |
|
|
125
|
+
| --- | --- |
|
|
126
|
+
| `help`, `--help`, `-h` | Show the help. |
|
|
127
|
+
| `--version`, `-v` | Show the version. |
|
|
128
|
+
|
|
129
|
+
An unknown command prints a short message and exits 1.
|
|
130
|
+
|
|
131
|
+
## Requirements
|
|
132
|
+
|
|
133
|
+
Node.js 18 or later. The CLI has no dependencies.
|
|
134
|
+
|
|
135
|
+
## For maintainers
|
|
136
|
+
|
|
137
|
+
Run the tests with `npm test`. The tests use a temporary HOME and PATH, fake client commands, and a fake MCP server on `127.0.0.1`. They never touch the config of your machine.
|
|
138
|
+
|
|
139
|
+
To release a version:
|
|
140
|
+
|
|
141
|
+
1. Set the version in `package.json` and add a section to `CHANGELOG.md`.
|
|
142
|
+
2. Publish a GitHub release with the tag `v<version>`. The `Release` workflow checks that the tag equals the version, runs the tests, and publishes to npm with provenance.
|
|
143
|
+
|
|
144
|
+
The `Release` workflow uses npm trusted publishing (OIDC), so the repository holds no npm token. It cannot work before these two steps, which an owner of the npm scope must do once:
|
|
145
|
+
|
|
146
|
+
1. Publish the first version by hand from a clean checkout: `npm publish --access public`.
|
|
147
|
+
2. On npmjs.com, open the settings of `@taskade/cli` and add a trusted publisher: GitHub Actions, organization `taskade`, repository `cli`, workflow `release.yml`.
|
|
148
|
+
|
|
149
|
+
## Security
|
|
150
|
+
|
|
151
|
+
Report a vulnerability to security@taskade.com. See [SECURITY.md](SECURITY.md).
|
|
152
|
+
|
|
153
|
+
## License
|
|
154
|
+
|
|
155
|
+
MIT. See [LICENSE](LICENSE).
|
package/bin/cli.mjs
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// @taskade/cli: connect an MCP client to Taskade, and check the connection.
|
|
4
|
+
// Run `taskade help` for the commands.
|
|
5
|
+
|
|
6
|
+
import { main } from "../src/cli.mjs";
|
|
7
|
+
import { askOnTerminal } from "../src/system.mjs";
|
|
8
|
+
|
|
9
|
+
main(process.argv.slice(2), {
|
|
10
|
+
env: process.env,
|
|
11
|
+
cwd: process.cwd(),
|
|
12
|
+
platform: process.platform,
|
|
13
|
+
interactive: Boolean(process.stdin.isTTY && process.stdout.isTTY),
|
|
14
|
+
stdout: process.stdout,
|
|
15
|
+
stderr: process.stderr,
|
|
16
|
+
ask: askOnTerminal,
|
|
17
|
+
}).then(
|
|
18
|
+
(code) => {
|
|
19
|
+
process.exitCode = code;
|
|
20
|
+
},
|
|
21
|
+
(err) => {
|
|
22
|
+
process.stderr.write(`Error: ${err.message}\n`);
|
|
23
|
+
process.exitCode = 1;
|
|
24
|
+
},
|
|
25
|
+
);
|
package/package.json
CHANGED
|
@@ -1,6 +1,39 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@taskade/cli",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Connect Claude Code, Codex, Cursor, VS Code, or Claude Desktop to the hosted Taskade MCP server, and check the connection.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"taskade": "./bin/cli.mjs"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin/",
|
|
11
|
+
"src/"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"test": "node --test test/cli.test.mjs test/plug.test.mjs test/doctor.test.mjs test/system.test.mjs"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"taskade",
|
|
18
|
+
"mcp",
|
|
19
|
+
"cli",
|
|
20
|
+
"claude-code",
|
|
21
|
+
"codex",
|
|
22
|
+
"cursor",
|
|
23
|
+
"vscode",
|
|
24
|
+
"ai-agent"
|
|
25
|
+
],
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"homepage": "https://github.com/taskade/cli",
|
|
28
|
+
"bugs": "https://github.com/taskade/cli/issues",
|
|
29
|
+
"repository": {
|
|
30
|
+
"type": "git",
|
|
31
|
+
"url": "git+https://github.com/taskade/cli.git"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18"
|
|
35
|
+
},
|
|
36
|
+
"publishConfig": {
|
|
37
|
+
"access": "public"
|
|
38
|
+
}
|
|
39
|
+
}
|
package/src/cli.mjs
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
// Parse the command line and run one command.
|
|
2
|
+
// `main` takes all input from `io`, so that the tests can run it in process.
|
|
3
|
+
|
|
4
|
+
import { readFileSync } from "node:fs";
|
|
5
|
+
import { CLIENTS, DEFAULT_SERVER_URL, RUN, findClient } from "./clients.mjs";
|
|
6
|
+
import { doctor } from "./doctor.mjs";
|
|
7
|
+
import { plug } from "./plug.mjs";
|
|
8
|
+
|
|
9
|
+
export const VERSION = JSON.parse(readFileSync(new URL("../package.json", import.meta.url), "utf8")).version;
|
|
10
|
+
|
|
11
|
+
const FLAGS = {
|
|
12
|
+
"--yes": "yes",
|
|
13
|
+
"-y": "yes",
|
|
14
|
+
"--print": "print",
|
|
15
|
+
"--project": "project",
|
|
16
|
+
"--token": "token",
|
|
17
|
+
"--json": "json",
|
|
18
|
+
"--verbose": "verbose",
|
|
19
|
+
"--help": "help",
|
|
20
|
+
"-h": "help",
|
|
21
|
+
"--version": "version",
|
|
22
|
+
"-v": "version",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const COMMAND_FLAGS = {
|
|
26
|
+
plug: ["yes", "print", "project", "token"],
|
|
27
|
+
doctor: ["json", "verbose"],
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const TOKEN_REFUSAL =
|
|
31
|
+
"Never pass a token on the command line. It stays in your shell history.\n" +
|
|
32
|
+
"Set the environment variable TASKADE_TOKEN, then add --token.";
|
|
33
|
+
|
|
34
|
+
export function helpText() {
|
|
35
|
+
const clients = CLIENTS.map((c) => c.id + (c.aliases.length ? ` (${c.aliases.join(", ")})` : "")).join(", ");
|
|
36
|
+
return `taskade ${VERSION}: connect an MCP client to Taskade
|
|
37
|
+
|
|
38
|
+
USAGE
|
|
39
|
+
${RUN} <command> [options]
|
|
40
|
+
|
|
41
|
+
COMMANDS
|
|
42
|
+
plug [client] Connect a client to ${DEFAULT_SERVER_URL}.
|
|
43
|
+
With no client, list the clients on this machine.
|
|
44
|
+
Alias: connect
|
|
45
|
+
doctor Check why a connection fails. Changes nothing.
|
|
46
|
+
Alias: whoami
|
|
47
|
+
help Show this help.
|
|
48
|
+
|
|
49
|
+
CLIENTS
|
|
50
|
+
${clients}
|
|
51
|
+
|
|
52
|
+
PLUG OPTIONS
|
|
53
|
+
--yes Apply the change with no question.
|
|
54
|
+
--print Show the command or the config block. Change nothing.
|
|
55
|
+
This is the default when the CLI does not run in a terminal.
|
|
56
|
+
--project Write the project file of this folder, not the user file.
|
|
57
|
+
--token Send a personal access token from TASKADE_TOKEN in a header,
|
|
58
|
+
for a machine that cannot sign in with a browser.
|
|
59
|
+
|
|
60
|
+
DOCTOR OPTIONS
|
|
61
|
+
--json Print the result as JSON.
|
|
62
|
+
--verbose Print the names of the tools that the server lists.
|
|
63
|
+
|
|
64
|
+
OTHER OPTIONS
|
|
65
|
+
--help, -h Show this help.
|
|
66
|
+
--version, -v Show the version.
|
|
67
|
+
|
|
68
|
+
ENVIRONMENT
|
|
69
|
+
TASKADE_TOKEN A personal access token, read only with --token and by doctor.
|
|
70
|
+
Create one at https://www.taskade.com/settings/api
|
|
71
|
+
TASKADE_MCP_URL Another server URL, for tests. https:// only, except
|
|
72
|
+
for localhost and 127.0.0.1.
|
|
73
|
+
|
|
74
|
+
Most people need no CLI. Paste this into your agent:
|
|
75
|
+
Set up Taskade for me. Read and follow https://www.taskade.com/SKILL.md
|
|
76
|
+
`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function parseArgs(argv) {
|
|
80
|
+
const opts = {};
|
|
81
|
+
const positionals = [];
|
|
82
|
+
for (const arg of argv) {
|
|
83
|
+
if (arg.startsWith("--token=")) return { error: TOKEN_REFUSAL };
|
|
84
|
+
if (/^tskdp_/i.test(arg)) return { error: TOKEN_REFUSAL };
|
|
85
|
+
if (arg.startsWith("-")) {
|
|
86
|
+
const flag = FLAGS[arg];
|
|
87
|
+
if (!flag) return { error: `Unknown option: ${arg}` };
|
|
88
|
+
opts[flag] = true;
|
|
89
|
+
} else {
|
|
90
|
+
positionals.push(arg);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return { opts, positionals };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Run the CLI. `io` holds: env, cwd, platform, interactive, version,
|
|
98
|
+
* stdout and stderr (objects with a write method), and ask (question -> Promise<boolean>).
|
|
99
|
+
* Returns the exit code.
|
|
100
|
+
*/
|
|
101
|
+
export async function main(argv, io) {
|
|
102
|
+
io = { version: VERSION, ...io };
|
|
103
|
+
const parsed = parseArgs(argv);
|
|
104
|
+
if (parsed.error) {
|
|
105
|
+
io.stderr.write(parsed.error + "\n");
|
|
106
|
+
return 1;
|
|
107
|
+
}
|
|
108
|
+
const { opts, positionals } = parsed;
|
|
109
|
+
if (opts.version) {
|
|
110
|
+
io.stdout.write(VERSION + "\n");
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
const [command, ...rest] = positionals;
|
|
114
|
+
if (opts.help || command === undefined || command === "help") {
|
|
115
|
+
io.stdout.write(helpText());
|
|
116
|
+
return 0;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const name = { connect: "plug", whoami: "doctor" }[command] || command;
|
|
120
|
+
if (!COMMAND_FLAGS[name]) {
|
|
121
|
+
io.stderr.write(`Unknown command: ${command}\nRun "${RUN} help" to see the commands.\n`);
|
|
122
|
+
return 1;
|
|
123
|
+
}
|
|
124
|
+
const wrong = Object.keys(opts).find((flag) => !COMMAND_FLAGS[name].includes(flag));
|
|
125
|
+
if (wrong) {
|
|
126
|
+
io.stderr.write(`The option --${wrong} does not apply to ${command}.\n`);
|
|
127
|
+
return 1;
|
|
128
|
+
}
|
|
129
|
+
// With --token, a word that is not a client name can be the token itself. Do not echo it.
|
|
130
|
+
if (opts.token && (rest.length > 1 || (rest[0] && !findClient(rest[0])))) {
|
|
131
|
+
io.stderr.write(TOKEN_REFUSAL + "\n");
|
|
132
|
+
return 1;
|
|
133
|
+
}
|
|
134
|
+
const maxArgs = name === "plug" ? 1 : 0;
|
|
135
|
+
if (rest.length > maxArgs) {
|
|
136
|
+
io.stderr.write(`Too many arguments for ${command}: ${rest.slice(maxArgs).join(" ")}\n`);
|
|
137
|
+
return 1;
|
|
138
|
+
}
|
|
139
|
+
if (opts.print && opts.yes) {
|
|
140
|
+
io.stderr.write("Use --print or --yes, not both.\n");
|
|
141
|
+
return 1;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
if (name === "plug") return plug(io, { ...opts, client: rest[0] });
|
|
145
|
+
return doctor(io, opts);
|
|
146
|
+
}
|
package/src/clients.mjs
ADDED
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
// The MCP clients that this CLI supports, how to find them on the machine,
|
|
2
|
+
// and where each one keeps its MCP servers. Each client cites the public
|
|
3
|
+
// documentation that shows its config shape and file location.
|
|
4
|
+
|
|
5
|
+
import { readFileSync } from "node:fs";
|
|
6
|
+
import { join } from "node:path";
|
|
7
|
+
import { readConfig } from "./config-file.mjs";
|
|
8
|
+
import { exists, getEnv, homeDir, which } from "./system.mjs";
|
|
9
|
+
|
|
10
|
+
export const SERVER_NAME = "taskade";
|
|
11
|
+
export const DEFAULT_SERVER_URL = "https://www.taskade.com/mcp";
|
|
12
|
+
// The command that runs this CLI.
|
|
13
|
+
export const RUN = "npx @taskade/cli";
|
|
14
|
+
export const TOKEN_PAGE = "https://www.taskade.com/settings/api";
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The server URL: TASKADE_MCP_URL, or the hosted Taskade server.
|
|
18
|
+
* Only https is allowed, except for localhost and 127.0.0.1 (for tests).
|
|
19
|
+
*/
|
|
20
|
+
export function serverUrl(io) {
|
|
21
|
+
const raw = getEnv(io.env, "TASKADE_MCP_URL") || DEFAULT_SERVER_URL;
|
|
22
|
+
let url;
|
|
23
|
+
try {
|
|
24
|
+
url = new URL(raw);
|
|
25
|
+
} catch {
|
|
26
|
+
throw new Error(`TASKADE_MCP_URL is not a URL: ${raw}`);
|
|
27
|
+
}
|
|
28
|
+
const local = url.hostname === "localhost" || url.hostname === "127.0.0.1";
|
|
29
|
+
if (url.protocol !== "https:" && !(url.protocol === "http:" && local)) {
|
|
30
|
+
throw new Error(`The server URL must use https:// (http:// only for localhost or 127.0.0.1): ${raw}`);
|
|
31
|
+
}
|
|
32
|
+
return raw;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const CLIENTS = [
|
|
36
|
+
{
|
|
37
|
+
id: "claude-code",
|
|
38
|
+
name: "Claude Code",
|
|
39
|
+
aliases: ["claude"],
|
|
40
|
+
// Command, scopes, ~/.claude.json and .mcp.json: https://code.claude.com/docs/en/mcp
|
|
41
|
+
docs: "https://code.claude.com/docs/en/mcp",
|
|
42
|
+
detect: (io) => Boolean(which(io, "claude")),
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "claude-desktop",
|
|
46
|
+
name: "Claude Desktop",
|
|
47
|
+
aliases: [],
|
|
48
|
+
// A remote server is a custom connector in the app, not an entry in a file:
|
|
49
|
+
// https://support.claude.com/en/articles/11175166-getting-started-with-custom-connectors-using-remote-mcp
|
|
50
|
+
docs: "https://support.claude.com/en/articles/11175166-getting-started-with-custom-connectors-using-remote-mcp",
|
|
51
|
+
detect: (io) => {
|
|
52
|
+
if (io.platform === "darwin") return exists(join(homeDir(io), "Library", "Application Support", "Claude"));
|
|
53
|
+
if (io.platform === "win32") {
|
|
54
|
+
const appData = getEnv(io.env, "APPDATA");
|
|
55
|
+
return Boolean(appData) && exists(join(appData, "Claude"));
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
{
|
|
61
|
+
id: "cursor",
|
|
62
|
+
name: "Cursor",
|
|
63
|
+
aliases: [],
|
|
64
|
+
// ~/.cursor/mcp.json and .cursor/mcp.json, a remote server has "url": https://cursor.com/docs/context/mcp
|
|
65
|
+
docs: "https://cursor.com/docs/context/mcp",
|
|
66
|
+
detect: (io) => Boolean(which(io, "cursor")) || exists(join(homeDir(io), ".cursor")),
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
id: "codex",
|
|
70
|
+
name: "Codex",
|
|
71
|
+
aliases: [],
|
|
72
|
+
// `codex mcp add <name> --url`, `codex mcp login`, ~/.codex/config.toml: https://developers.openai.com/codex/mcp
|
|
73
|
+
// --bearer-token-env-var: https://github.com/openai/codex/blob/main/codex-rs/cli/src/mcp_cmd.rs
|
|
74
|
+
docs: "https://developers.openai.com/codex/mcp",
|
|
75
|
+
detect: (io) => Boolean(which(io, "codex")),
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: "vscode",
|
|
79
|
+
name: "VS Code",
|
|
80
|
+
aliases: ["code"],
|
|
81
|
+
// .vscode/mcp.json with "servers" and "type": "http", and `code --add-mcp`:
|
|
82
|
+
// https://code.visualstudio.com/docs/copilot/reference/mcp-configuration
|
|
83
|
+
docs: "https://code.visualstudio.com/docs/copilot/reference/mcp-configuration",
|
|
84
|
+
detect: (io) => Boolean(which(io, "code")),
|
|
85
|
+
},
|
|
86
|
+
];
|
|
87
|
+
|
|
88
|
+
export function findClient(name) {
|
|
89
|
+
return CLIENTS.find((c) => c.id === name || c.aliases.includes(name)) || null;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The entry that each client keeps for the Taskade server. */
|
|
93
|
+
export function expectedEntry(clientId, url, token) {
|
|
94
|
+
const headers = token ? { headers: { Authorization: `Bearer ${token}` } } : {};
|
|
95
|
+
switch (clientId) {
|
|
96
|
+
case "claude-code":
|
|
97
|
+
case "vscode":
|
|
98
|
+
return { type: "http", url, ...headers };
|
|
99
|
+
case "cursor":
|
|
100
|
+
return { url, ...headers };
|
|
101
|
+
case "codex":
|
|
102
|
+
return token ? { url, bearer_token_env_var: "TASKADE_TOKEN" } : { url };
|
|
103
|
+
default:
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export function claudeUserFile(io) {
|
|
109
|
+
return join(homeDir(io), ".claude.json");
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
export function codexConfigFile(io) {
|
|
113
|
+
return join(getEnv(io.env, "CODEX_HOME") || join(homeDir(io), ".codex"), "config.toml");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Read the [mcp_servers.taskade] table of a Codex config.toml.
|
|
118
|
+
* Reads only the plain `key = "value"` lines that this CLI compares.
|
|
119
|
+
*/
|
|
120
|
+
export function readCodexEntry(file) {
|
|
121
|
+
let text;
|
|
122
|
+
try {
|
|
123
|
+
text = readFileSync(file, "utf8");
|
|
124
|
+
} catch {
|
|
125
|
+
return null;
|
|
126
|
+
}
|
|
127
|
+
const lines = text.split(/\r?\n/);
|
|
128
|
+
const start = lines.findIndex((l) => /^\s*\[\s*mcp_servers\.(taskade|"taskade")\s*\]\s*(#.*)?$/.test(l));
|
|
129
|
+
if (start === -1) return null;
|
|
130
|
+
const entry = {};
|
|
131
|
+
for (const line of lines.slice(start + 1)) {
|
|
132
|
+
if (/^\s*\[/.test(line)) break;
|
|
133
|
+
const m = /^\s*([A-Za-z_]+)\s*=\s*"([^"]*)"\s*(#.*)?$/.exec(line);
|
|
134
|
+
if (m && (m[1] === "url" || m[1] === "bearer_token_env_var")) entry[m[1]] = m[2];
|
|
135
|
+
}
|
|
136
|
+
return entry;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function jsonEntry(file, key) {
|
|
140
|
+
const config = readConfig(file, key);
|
|
141
|
+
if (!config.exists) return { file, missing: true };
|
|
142
|
+
if (config.error) return { file, error: config.error };
|
|
143
|
+
return { file, entry: config.data[key]?.[SERVER_NAME] };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Every place where a client can hold a Taskade server entry. Read only.
|
|
148
|
+
* Returns a list of { file, entry, error, missing, label }.
|
|
149
|
+
*/
|
|
150
|
+
export function clientEntries(io, clientId) {
|
|
151
|
+
const home = homeDir(io);
|
|
152
|
+
switch (clientId) {
|
|
153
|
+
case "claude-code": {
|
|
154
|
+
const user = jsonEntry(claudeUserFile(io), "mcpServers");
|
|
155
|
+
const found = [{ ...user, label: "user" }];
|
|
156
|
+
const config = readConfig(claudeUserFile(io), "mcpServers");
|
|
157
|
+
const local = config.data?.projects?.[io.cwd]?.mcpServers?.[SERVER_NAME];
|
|
158
|
+
if (local) found.push({ file: claudeUserFile(io), entry: local, label: "local" });
|
|
159
|
+
found.push({ ...jsonEntry(join(io.cwd, ".mcp.json"), "mcpServers"), label: "project" });
|
|
160
|
+
return found;
|
|
161
|
+
}
|
|
162
|
+
case "cursor":
|
|
163
|
+
return [
|
|
164
|
+
{ ...jsonEntry(join(home, ".cursor", "mcp.json"), "mcpServers"), label: "user" },
|
|
165
|
+
{ ...jsonEntry(join(io.cwd, ".cursor", "mcp.json"), "mcpServers"), label: "project" },
|
|
166
|
+
];
|
|
167
|
+
case "codex": {
|
|
168
|
+
const file = codexConfigFile(io);
|
|
169
|
+
return [{ file, entry: readCodexEntry(file) || undefined, missing: !exists(file), label: "user" }];
|
|
170
|
+
}
|
|
171
|
+
case "vscode":
|
|
172
|
+
return [{ ...jsonEntry(join(io.cwd, ".vscode", "mcp.json"), "servers"), label: "project" }];
|
|
173
|
+
default:
|
|
174
|
+
return [];
|
|
175
|
+
}
|
|
176
|
+
}
|