toolscript-mcp 1.0.3 → 1.0.4
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 +273 -1
- package/dist/host/broker.js +15 -9
- package/dist/host/main.js +6439 -2287
- package/package.json +1 -1
- package/runtime/task-job.ps1 +184 -0
- package/runtime/task-reap.pl +141 -0
package/README.md
CHANGED
|
@@ -12,6 +12,7 @@ The goal is a server that works with any MCP client, for example Claude Code, Cl
|
|
|
12
12
|
- [Measured](#measured)
|
|
13
13
|
- [Install](#install)
|
|
14
14
|
- [Configuration](#configuration)
|
|
15
|
+
- [Workspace](#workspace)
|
|
15
16
|
- [Claude Code as a downstream server](#claude-code-as-a-downstream-server)
|
|
16
17
|
- [Comparison with Claude Code Code Mode](#toolscript-mcp-and-claude-code-code-mode)
|
|
17
18
|
|
|
@@ -23,7 +24,7 @@ The goal is a server that works with any MCP client, for example Claude Code, Cl
|
|
|
23
24
|
| Calls | Programs can filter, join and batch results, with at most 8 downstream calls at a time per run. |
|
|
24
25
|
| Servers | Local stdio and remote HTTP servers, with per-server environment variables and an optional stdio `cwd`. |
|
|
25
26
|
| Authentication | HTTP headers or native OAuth login, token refresh, dynamic client registration and static client credentials. |
|
|
26
|
-
| Local development | The optional `claude mcp serve` bridge offers file tools and a shell. See its [policy and risks](#claude-code-as-a-downstream-server). |
|
|
27
|
+
| Local development | The built-in [Workspace](#workspace) lists, searches and reads the files of one folder, and with a write grant it edits them, with no other process. It is off by default. The optional `claude mcp serve` bridge offers file tools and a shell. See its [policy and risks](#claude-code-as-a-downstream-server). |
|
|
27
28
|
| Policy | Ordered `allow`, `deny` and `ask` rules. Tools marked for user interaction need approval for each run. |
|
|
28
29
|
| Results | Compact output, `await recall(n)` for kept results, and `await saveFile(name, data)` for exports. Images and other non-text blocks become files, and a returned image shows to the model. |
|
|
29
30
|
| Clients | Setup examples for Claude Code, Claude Desktop, Cursor and Codex. Tests cover Claude Code and the MCP TypeScript SDK client. A manual smoke test passed in Codex CLI 0.171.0 with `codex exec`. See the [result](bench/CODEX.md#smoke-test-result). |
|
|
@@ -112,6 +113,7 @@ init imports user-scope servers from Claude Code, Claude Desktop and Cursor. It
|
|
|
112
113
|
and prints the client changes. Use [Client setup](#client-setup) for Codex or a manual setup. Then follow
|
|
113
114
|
[Configure downstream servers](#configure-downstream-servers).
|
|
114
115
|
|
|
116
|
+
To print the version of the package, run `npx -y toolscript-mcp --version`.
|
|
115
117
|
To update, run `npx -y toolscript-mcp@latest --help` and restart your client. If your client entry pins a version,
|
|
116
118
|
change the version in that entry before you restart.
|
|
117
119
|
|
|
@@ -159,6 +161,12 @@ something:
|
|
|
159
161
|
`/toolscript:doctor` checks the whole setup and changes no setting. It runs [doctor](#doctor), then checks the Claude
|
|
160
162
|
Code registration and the direct copies of your servers. For each problem, it names the step that fixes it.
|
|
161
163
|
|
|
164
|
+
`/toolscript:workspace` turns on the built-in [Workspace](#workspace) for a project folder. It first runs
|
|
165
|
+
`toolscript-mcp --version` and stops when the package is older than 1.0.4, because an older package refuses a config
|
|
166
|
+
with a `workspace` section. It proposes the folder where Claude Code started, adds it as a root, and asks before each
|
|
167
|
+
extra grant: write access and one named task. It checks the root with `doctor`. After you restart Claude Code in that
|
|
168
|
+
folder, `/toolscript:workspace verify` lists the folder through a program and reports a count of entries.
|
|
169
|
+
|
|
162
170
|
The skills do not edit the config files of your clients. They show the lines to change. To update or uninstall
|
|
163
171
|
toolscript-mcp, ask Claude again.
|
|
164
172
|
|
|
@@ -1101,6 +1109,270 @@ code. Read [SECURITY.md](SECURITY.md).
|
|
|
1101
1109
|
your client. Then send a program that reads the result.
|
|
1102
1110
|
- The Claude Code bridge starts another process. It adds memory use, and `cwd` does not restrict file or shell access.
|
|
1103
1111
|
- The Codex bench is a [test plan](bench/CODEX.md). No Codex performance results are published in this repo.
|
|
1112
|
+
- Workspace reads files, runs the named tasks that you put in the config, and with a write grant changes files. A task is not contained. Its change tools write in place on Windows and macOS. See [Workspace](#workspace) and [Named tasks](#named-tasks).
|
|
1113
|
+
|
|
1114
|
+
## Workspace
|
|
1115
|
+
|
|
1116
|
+
Workspace is a built-in server that reads the files of one project folder and runs its named tasks. With a write grant,
|
|
1117
|
+
it also changes the files. It runs inside toolscript-mcp, so it needs no Claude Code and no other process. Its tools are
|
|
1118
|
+
named `mcp__workspace__<tool>`, and a program calls them as it calls any tool. It is off by default.
|
|
1119
|
+
|
|
1120
|
+
### Turn it on
|
|
1121
|
+
|
|
1122
|
+
In Claude Code, run `/toolscript:workspace` to add a root with no hand edit (see
|
|
1123
|
+
[With the Claude Code plugin](#with-the-claude-code-plugin)). Otherwise add a `workspace` section to the config. The key
|
|
1124
|
+
`workspace` is then reserved: `mcpServers` cannot hold a server of
|
|
1125
|
+
that name.
|
|
1126
|
+
|
|
1127
|
+
```json
|
|
1128
|
+
{
|
|
1129
|
+
"mcpServers": {},
|
|
1130
|
+
"workspace": {
|
|
1131
|
+
"roots": [{ "path": "/home/me/app" }],
|
|
1132
|
+
"exclude": ["fixtures/secrets/**", "*.sqlite"]
|
|
1133
|
+
}
|
|
1134
|
+
}
|
|
1135
|
+
```
|
|
1136
|
+
|
|
1137
|
+
- `roots` holds 1 to 16 entries. Each `path` is absolute and must be a folder that exists. `write` is `false` by default. See [Change files](#change-files). `tasks` holds the [named tasks](#named-tasks) of the entry.
|
|
1138
|
+
- `exclude` holds globs of paths that no tool reads or shows. They add to the built-in list below. A glob is relative to the `path` of the entry, not to the root of the session: `app/fixtures/**` still holds when the session root is `app` under an entry `Projects`. A start folder that an `exclude` glob hides makes Workspace unavailable. A client root that a glob hides is dropped.
|
|
1139
|
+
- `skip` holds the folder names that `list` and `search` do not enter. It replaces the default list: `node_modules`, `dist`, `build`, `target`, `vendor`, `coverage`, `.venv`, `venv` and `__pycache__`. A call can still name such a folder in `path`.
|
|
1140
|
+
- `gitignore` is `true` by default. Set it to `false` and `list` and `search` never read the `.gitignore` of the root. See [What the read tools cover](#what-the-read-tools-cover).
|
|
1141
|
+
|
|
1142
|
+
The server reads the section one time, at the start. A policy reload never reads it. To change a root, edit the config and
|
|
1143
|
+
restart toolscript-mcp. An error in the section makes only the `workspace` entry invalid, and the other servers start.
|
|
1144
|
+
|
|
1145
|
+
### The root of a session
|
|
1146
|
+
|
|
1147
|
+
The model never names a root. The server binds one root at the start, from the real path of each entry and of the
|
|
1148
|
+
folder where your client started it:
|
|
1149
|
+
|
|
1150
|
+
1. If that folder is inside one or more entries, the deepest entry gives the grants, and the folder is the root.
|
|
1151
|
+
2. Else, if the config has one entry, its path is the root.
|
|
1152
|
+
3. Else Workspace is unavailable, and `search_tools` says to start the client in one of the entries.
|
|
1153
|
+
|
|
1154
|
+
Workspace reads `workspace.roots` only at its start. After a change, reconnect toolscript-mcp or restart the client.
|
|
1155
|
+
When the config cannot bind, the instructions of the server tell the model that Workspace is not available. Each reason ends with that restart advice.
|
|
1156
|
+
|
|
1157
|
+
So two sessions in two folders under one entry see only their own folder. The folder where the client started never grants
|
|
1158
|
+
access alone. Workspace refuses a root in these cases, and the reason names the entry:
|
|
1159
|
+
|
|
1160
|
+
- The root is a drive or the root of a file system.
|
|
1161
|
+
- The root is your home folder, or a folder that holds it.
|
|
1162
|
+
- The root is a Windows network path.
|
|
1163
|
+
- A part of the root path has a name such as `.git` or `.ssh`.
|
|
1164
|
+
|
|
1165
|
+
Roots of the client can make the root smaller, and never larger. If your client declares the `roots` capability, the
|
|
1166
|
+
server asks for its roots one time, after the client starts. The root becomes the deepest folder that holds every client
|
|
1167
|
+
root inside the bound root. A client root outside the bound root, a link to a folder outside it, a file, or a refused
|
|
1168
|
+
folder grants nothing. The server waits at most 2 seconds for the answer. Until then no Workspace call runs. After that
|
|
1169
|
+
time, or after an error, the bound root stays. A change of the roots needs a restart of toolscript-mcp. A task still runs
|
|
1170
|
+
in its `cwd` under the entry, which can be outside a smaller root. The prompt and the stderr log show the root.
|
|
1171
|
+
|
|
1172
|
+
### The tools
|
|
1173
|
+
|
|
1174
|
+
| Tool | What it does |
|
|
1175
|
+
| --- | --- |
|
|
1176
|
+
| `list` | Lists entries under a folder, sorted by path, with `depth` from 1 to 8. A link shows as `link` and is never entered. |
|
|
1177
|
+
| `search` | Finds literal text in the text files under a folder. It returns the path, line and column of each match. |
|
|
1178
|
+
| `read` | Reads one text file with its line ends as they are. It returns the text, its encoding and the `sha256` of its bytes. |
|
|
1179
|
+
| `stat` | Tells if a path is a file, a folder, something else or missing. |
|
|
1180
|
+
| `run_task` | Runs one [named task](#named-tasks) from the config. It exists only when the entry of the root has a valid task. It asks first. |
|
|
1181
|
+
| `diff` | Previews a change and writes nothing. It takes the arguments of `edit` or of `write`, and returns the unified diff. |
|
|
1182
|
+
| `edit` | Replaces exact text in one file. It is listed only with `"write": true`. |
|
|
1183
|
+
| `write` | Makes a new file, or replaces a whole file. It is listed only with `"write": true`. |
|
|
1184
|
+
|
|
1185
|
+
Paths in arguments and results are relative to the root and use `/`. Each failed call throws in the program. The message
|
|
1186
|
+
starts with a code, such as `excluded`, `link`, `hard-link`, `bad-path`, `too-large`, `binary` or `not-found`. The change
|
|
1187
|
+
tools add `stale`, `busy`, `exists`, `no-match`, `many-matches` and `read-only`.
|
|
1188
|
+
|
|
1189
|
+
### What the read tools cover
|
|
1190
|
+
|
|
1191
|
+
- Each call goes through the policy as any call does. The read tools and `diff` run with no rule while Workspace is on. An `ask` or `deny` rule that matches still decides.
|
|
1192
|
+
- Each result is untrusted text. The run result is in the untrusted wrapper, and the run learns no result shape.
|
|
1193
|
+
- The built-in exclusions hold for all tools, with no regard to case, after Unicode NFC. They cover version control data (`.git`, `.hg` and `.svn`) and `.toolscript-mcp`.
|
|
1194
|
+
- They also cover secrets: `.env`, `.env.*`, `*.pem`, `*.key`, `id_rsa*`, `.npmrc`, `.aws` and `.ssh`. And they cover the settings of clients: `.claude`, `.vscode` and `.mcp.json`.
|
|
1195
|
+
- The toolscript-mcp config file is excluded too, by its real path.
|
|
1196
|
+
- No tool follows a symlink or a junction, and `read` refuses a file with more than one hard link. `search` skips such a file.
|
|
1197
|
+
- `read` refuses a file over 4 MiB, a file with a NUL byte and a file that is not UTF-8. `search` skips these files and files over 1 MiB, and counts them in `skipped`.
|
|
1198
|
+
- `search` and `list` stop after they read 20,000 names or run 10 seconds, and `list` also stops at 5,000 entries. Each then sets `truncated`. Excluded names do not count toward the 20,000, and only the 10 seconds bound them. A folder with more names than the rest of the budget gives a part of its names, in the order of the volume. A cancel ends a `search` within one second.
|
|
1199
|
+
- `search` takes literal text on one line, not a regular expression. Filter the lines in your program. `include` takes up to 16 globs with `*`, `?` and `**`, over paths from the root.
|
|
1200
|
+
- `list` and `search` leave out the names that the `.gitignore` in the root ignores. Each call reads that file again. The files below the root, `.git/info/exclude` and the global ignore file count for nothing.
|
|
1201
|
+
- The rules are discovery only. `read`, `stat`, `diff`, `edit`, `write` and `run_task` never use them, so an ignored file reads and changes as before. A `path` that is ignored, or inside an ignored folder, applies no rule.
|
|
1202
|
+
- The syntax has `#` comments, `*`, `?`, `**` as a whole part, and classes such as `[Bb]in/`. A trailing `/` takes folders only. A `/` at the start or in the middle anchors the pattern to the root.
|
|
1203
|
+
- A `!` rule un-ignores a name, and the last rule that matches wins. A `!` rule below an ignored folder shows nothing, as in git.
|
|
1204
|
+
- A line with another `\`, a `**` beside other characters, an unclosed class, over 200 characters or over 6 wildcards is skipped. At most 500 rules count. A file that is missing, excluded, a link, with more than one hard link, not UTF-8 or over 64 KiB gives no rules.
|
|
1205
|
+
- An exclusion and `skip` decide first: no rule shows an excluded name. An ignored name still counts as one of the 20,000 names. Set `"gitignore": false` to turn the rules off.
|
|
1206
|
+
|
|
1207
|
+
### Named tasks
|
|
1208
|
+
|
|
1209
|
+
A task is a fixed command that you write in the config, for example your test command. The model sends only the name of
|
|
1210
|
+
the task. It can never choose the program, the arguments, the folder or the variables. A task is how a program checks
|
|
1211
|
+
its own change, for example after it edits a file.
|
|
1212
|
+
|
|
1213
|
+
```json
|
|
1214
|
+
{
|
|
1215
|
+
"workspace": {
|
|
1216
|
+
"roots": [
|
|
1217
|
+
{
|
|
1218
|
+
"path": "/home/me/app",
|
|
1219
|
+
"tasks": {
|
|
1220
|
+
"test": { "command": "node", "args": ["--test"], "timeoutSeconds": 60, "env": { "CI": "1" } },
|
|
1221
|
+
"lint": { "command": "node", "args": ["scripts/lint.mjs"], "cwd": "packages/app" }
|
|
1222
|
+
}
|
|
1223
|
+
}
|
|
1224
|
+
]
|
|
1225
|
+
}
|
|
1226
|
+
}
|
|
1227
|
+
```
|
|
1228
|
+
|
|
1229
|
+
- A task name has 1 to 32 characters from `a-z`, `0-9`, `-` and `_`. An entry has at most 32 tasks.
|
|
1230
|
+
- `command` is needed. It is an absolute path, or a bare name that toolscript-mcp looks up on its `PATH` one time, at the start.
|
|
1231
|
+
- `args` is a list of strings. `cwd` is a folder relative to the `path` of the entry, `.` by default. It must exist, and it can have no link on the way.
|
|
1232
|
+
- `timeoutSeconds` is 60 by default. A value over `sandbox.callTimeoutSeconds` is a config error. The limit that applies
|
|
1233
|
+
is at most one second under `sandbox.callTimeoutSeconds`, which is 59 seconds with the default call limit. So the
|
|
1234
|
+
program usually sees `timedOut` and not a cancel. A process that keeps the output open after the task ends can hold
|
|
1235
|
+
the call. The program then sees a cancel at the call limit.
|
|
1236
|
+
- `env` holds the variables of the task. The child gets only these, and a short list of variables of the server: `PATH`, the home and temp folders, and `SystemRoot` on Windows. No other variable of the server reaches it.
|
|
1237
|
+
- `${NAME}` in `command`, `args` and `env` takes the value of a variable of the server, as it does in a server entry.
|
|
1238
|
+
|
|
1239
|
+
The task list of one session is the list of the entry that the root is in. A session whose entry has no task has no
|
|
1240
|
+
`run_task` tool and cannot run a task of another entry. A task that cannot run, for example a command that `PATH` does
|
|
1241
|
+
not hold, is listed by `toolscript-mcp doctor` with the reason. The other tasks still run.
|
|
1242
|
+
|
|
1243
|
+
How a task runs:
|
|
1244
|
+
|
|
1245
|
+
- There is no shell. The program starts with the arguments as you wrote them, and standard input is closed. `a && echo x` is one argument.
|
|
1246
|
+
- Each stream keeps the first 64 KiB and the last 192 KiB, and the result sets `stdoutTruncated` or `stderrTruncated`.
|
|
1247
|
+
- A non-zero exit code is a result, not an error. At the time limit, `timedOut` is `true`.
|
|
1248
|
+
- One task runs at a time in a session. A second call waits for the first.
|
|
1249
|
+
- A task ends with its process tree, however it ends: at its own exit, at the time limit, at a cancel, at a shutdown and
|
|
1250
|
+
when the server is killed. Whatever the task started in the background ends with it, and there is no switch to keep it.
|
|
1251
|
+
A build server that the task starts ends with it, so the next build starts cold. Examples are the MSBuild node reuse,
|
|
1252
|
+
the dotnet build server and the Gradle daemon.
|
|
1253
|
+
- On Windows, one warm Windows PowerShell 5.1 helper makes a Job Object for each task. Every process that the task
|
|
1254
|
+
started ends with it, also one whose parent already exited. A process that a service, the Task Scheduler or WMI
|
|
1255
|
+
starts is not in the job and stays. The helper starts at the first task, and stops after 10 minutes with no task.
|
|
1256
|
+
While it waits it holds about 60 MiB.
|
|
1257
|
+
- On Linux, a small perl helper (`/usr/bin/perl`) is the child subreaper of the task. It ends every descendant, also after
|
|
1258
|
+
`setsid`, `nohup` or a double fork. A process that a daemon outside the tree starts, such as `systemd-run`, stays.
|
|
1259
|
+
- macOS has no kernel object that holds descendants, so the same helper searches. It ends the process group, each
|
|
1260
|
+
process with a live parent chain, and each process whose environment still shows the variable `TOOLSCRIPT_TASK`.
|
|
1261
|
+
That variable, a new random value for each task, is the only difference from the environment of a direct start. A
|
|
1262
|
+
process that left the group, lost its parent and hides the variable stays. So does a process that `launchd` starts.
|
|
1263
|
+
- Costs, measured: on Windows the first task after the helper starts waits for it. That is about 0.6 s on a quiet
|
|
1264
|
+
laptop and up to 3 s on a busy one. Each later task adds under 20 ms. On Linux each task adds about 7 ms. On macOS the
|
|
1265
|
+
helper runs one `ps` at the end of each task.
|
|
1266
|
+
- The time limit starts when the task starts, not before.
|
|
1267
|
+
- The helper can be missing or blocked: PowerShell by AppLocker, a policy or Constrained Language Mode, or no
|
|
1268
|
+
`/usr/bin/perl`. Then the task runs by the direct start, and nothing ends at a hard kill of the server. On Windows
|
|
1269
|
+
the task ends with the `taskkill /T` tree, elsewhere with its process group, so a process that left either can stay.
|
|
1270
|
+
toolscript-mcp writes one line to its stderr about it, one time for each process.
|
|
1271
|
+
|
|
1272
|
+
#### Set a task up safely
|
|
1273
|
+
|
|
1274
|
+
- A task runs project code with your rights. Nothing contains it. The prompt says so each time, and this page does not claim more.
|
|
1275
|
+
- By default each program that calls `run_task` asks you first. Only an `allow` rule with the exact name `mcp__workspace__run_task` skips the prompt. The rules `*`, `mcp__*` and `mcp__workspace__*` do not allow it. A client that cannot ask gets no task without that rule.
|
|
1276
|
+
- Write only commands that you trust. A test command runs the code of the project, and that code can read, change and send what your account can reach.
|
|
1277
|
+
- On Windows, a `.cmd`, `.bat` or `.ps1` file cannot be a command: a shell must parse it. Set `command` to `node` and give the script as the first argument.
|
|
1278
|
+
|
|
1279
|
+
### Change files
|
|
1280
|
+
|
|
1281
|
+
Set `"write": true` on the root entry to list `edit` and `write`. Without it, the tools are not listed, and a call of one
|
|
1282
|
+
fails with `read-only`. The grant belongs to the entry that holds the root of the session. The server reads it one time,
|
|
1283
|
+
at the start.
|
|
1284
|
+
|
|
1285
|
+
```json
|
|
1286
|
+
{ "workspace": { "roots": [{ "path": "/home/me/app", "write": true }] } }
|
|
1287
|
+
```
|
|
1288
|
+
|
|
1289
|
+
A change goes in three steps. First, preview it with `diff`. Then call `edit` with the hash that `read` returned. Then
|
|
1290
|
+
check the result:
|
|
1291
|
+
|
|
1292
|
+
```js
|
|
1293
|
+
const file = await call("mcp__workspace__read", { path: "src/retry.ts" })
|
|
1294
|
+
const edits = [{ old: "maxAttempts: 3", new: "maxAttempts: 5" }]
|
|
1295
|
+
const preview = await call("mcp__workspace__diff", { path: file.path, expectedHash: file.hash, edits })
|
|
1296
|
+
const change = await call("mcp__workspace__edit", { path: file.path, expectedHash: file.hash, edits })
|
|
1297
|
+
return { diff: change.diff, newHash: change.newHash }
|
|
1298
|
+
```
|
|
1299
|
+
|
|
1300
|
+
**The approval.** `edit` and `write` ask the person, one time for each program. The prompt names the session root. A
|
|
1301
|
+
client that cannot ask gets no change. The rules `*` and `mcp__*` do not allow these tools. A rule that starts with
|
|
1302
|
+
`mcp__workspace__` does, for example `mcp__workspace__*` or `mcp__workspace__edit`. A name that a program builds at run
|
|
1303
|
+
time runs only under such a rule. A `deny` rule wins. The approval covers one run, and each call still checks the hash.
|
|
1304
|
+
|
|
1305
|
+
**The hash rule.** `edit` needs `expectedHash`. If the file changed after the `read`, the call fails with `stale` and
|
|
1306
|
+
changes nothing. `write` with no `expectedHash` makes a new file, or fails with `exists`. `write` with `expectedHash`
|
|
1307
|
+
replaces the whole file. Two calls with one hash change the file one time. The second fails with `stale`.
|
|
1308
|
+
|
|
1309
|
+
**Exact bytes.** Each `old` is matched against the file as `read` returned it, and the order of the edits changes
|
|
1310
|
+
nothing. An `old` must occur one time, or `all` must be `true`. Two edits cannot replace the same text. No line end, byte
|
|
1311
|
+
order mark or space is changed for you. If `old` matches only with other line ends, the error says so. A changed file
|
|
1312
|
+
keeps its byte order mark and its mode. A file over 4 MiB, a binary file and a file that is not UTF-8 are refused.
|
|
1313
|
+
|
|
1314
|
+
**The lock.** A change holds a lock in the process and a lock file in the folder `.toolscript-mcp/locks` of your home.
|
|
1315
|
+
Two sessions never lose an update. A call waits 2 seconds for a lock, then fails with `busy`. A lock of a dead process, or
|
|
1316
|
+
one older than 30 seconds, is taken over. The lock goes after a failed or cancelled call.
|
|
1317
|
+
|
|
1318
|
+
**In-place writes.** Linux writes a temp file in the held folder and renames it, so a failed write leaves the old file.
|
|
1319
|
+
The new file keeps the mode, but not the access lists, the extended attributes or another owner of the old file.
|
|
1320
|
+
Windows and macOS write in place through the proven handle. A write that fails part way can leave that file damaged, and
|
|
1321
|
+
the error names the file. Atomic replace on these systems is a follow-up.
|
|
1322
|
+
|
|
1323
|
+
**The audit.** A run result lists each applied change, also when the program returns nothing:
|
|
1324
|
+
`- changed src/retry.ts (+1 -1)`. The run log keeps the relative path and the counts of added and removed lines. No log
|
|
1325
|
+
holds file content, `old` or `new` text, or a diff.
|
|
1326
|
+
|
|
1327
|
+
**What stays possible.** A change tool can edit any file that the root allows, for example a build script. A later run
|
|
1328
|
+
of your tests or your editor then runs that code. Keep `write` off for a root that you do not trust. The cases of
|
|
1329
|
+
[What stays possible](#what-stays-possible) also hold for a write: on Windows a swap can write a file outside the root
|
|
1330
|
+
whose bytes match the hash.
|
|
1331
|
+
|
|
1332
|
+
### How a file is opened
|
|
1333
|
+
|
|
1334
|
+
Workspace opens each file through a handle that it proves to be inside the root. It never opens a path by name and then
|
|
1335
|
+
trusts a check that it made before. The proof differs by system:
|
|
1336
|
+
|
|
1337
|
+
| System | Proof |
|
|
1338
|
+
| --- | --- |
|
|
1339
|
+
| Linux | Each part of the path is opened with `O_NOFOLLOW`, relative to the folder that is held open. A later swap of a name changes nothing that is held. On a volume with short names (vfat, NTFS, SMB, a share of a Windows folder), a name such as `GIT~1` is found under the name that the folder lists, so an exclusion holds for it. |
|
|
1340
|
+
| macOS | The full path is opened with `O_NOFOLLOW_ANY`, which refuses a symlink in any part. |
|
|
1341
|
+
| Windows | The full path is opened. A handle on another volume than the root is refused. Then `realpath` and `lstat` must agree with the identity of the handle, two times. |
|
|
1342
|
+
|
|
1343
|
+
At its first use, Workspace tests its method in a temp folder. If the test fails, Workspace is unavailable and the reason
|
|
1344
|
+
says why. On macOS, the CI run of the repo decides if the method works. A macOS system where it does not work has Workspace unavailable.
|
|
1345
|
+
|
|
1346
|
+
On Windows, Workspace does not cross to another volume: a folder inside the root that mounts another volume is refused.
|
|
1347
|
+
|
|
1348
|
+
### What stays possible
|
|
1349
|
+
|
|
1350
|
+
- On Windows, a process that writes in the root can swap a folder for a junction at each lookup of one proof. Then `read` can return a file outside the root, if that file is on the same volume as the root. `edit` and `write` can write such a file whose bytes match `expectedHash`. A new empty file or folder can be made outside the root, on any volume.
|
|
1351
|
+
- On Windows, a swap can alternate with each lookup of a `list` or a `stat`. On macOS it can do so for a `list`. It can also do so for a `stat` of an entry that the process cannot open. Then it can show a name, a size or a kind from outside the root. It never shows the bytes of a file.
|
|
1352
|
+
- On Windows, the same can happen for a folder in the middle of a path, such as `b` in `list b/c`: the swap must be out at the open of `b/c` and then alternate. Later lookups can be outside in a row.
|
|
1353
|
+
- On macOS, a swap while a new folder is made can make an empty folder outside the root.
|
|
1354
|
+
- Both cases need a process of another account, or a process with fewer rights. Code that runs as you can read the files itself.
|
|
1355
|
+
- Give Workspace a root that only your account can write. On Windows, `toolscript-mcp doctor` reads the access rules of the root and warns when another account can write.
|
|
1356
|
+
- A program that Workspace feeds with file text can send that text to any other tool that the policy allows. Keep the policy narrow for a root with private files.
|
|
1357
|
+
- A tool of another server can write the config. A new root, grant or task applies at the next start, as a new policy does.
|
|
1358
|
+
- A task is not confined to the root. It has the rights of your account, so it can read or write any file that you can.
|
|
1359
|
+
|
|
1360
|
+
### Check it
|
|
1361
|
+
|
|
1362
|
+
Run `toolscript-mcp tools workspace` to list the tools with their policy decision. Run `toolscript-mcp doctor` for one
|
|
1363
|
+
line on Workspace: off, the root with its grants and task names, or the reason that it is unavailable. A task that cannot run has its own line. `toolscript-mcp runs` shows the
|
|
1364
|
+
Workspace calls of a run. A program or a client config that names the Claude Code bridge still works as before.
|
|
1365
|
+
|
|
1366
|
+
### Tested clients
|
|
1367
|
+
|
|
1368
|
+
One program did search, read, diff, edit and `run_task` on a test project, with Workspace as the only server and no
|
|
1369
|
+
Claude Code bridge. The file bytes, the hash and the task exit code were checked after each run.
|
|
1370
|
+
|
|
1371
|
+
| Client | Version | Result |
|
|
1372
|
+
| --- | --- | --- |
|
|
1373
|
+
| Codex CLI | 0.172.0 | Passed. `codex exec` declines every prompt, so the config held allow rules for `edit` and `run_task`. |
|
|
1374
|
+
| Claude Code | 2.1.331 | Passed, with `claude -p --restricted --strict-mcp-config`. |
|
|
1375
|
+
| Cursor | | Not tested. |
|
|
1104
1376
|
|
|
1105
1377
|
## Claude Code as a downstream server
|
|
1106
1378
|
|
package/dist/host/broker.js
CHANGED
|
@@ -542,6 +542,7 @@ var FUNCTIONS = "functions";
|
|
|
542
542
|
var LEARNED = "learned";
|
|
543
543
|
var OAUTH = "oauth";
|
|
544
544
|
var BROKER = "broker";
|
|
545
|
+
var LOCKS = "locks";
|
|
545
546
|
var normalizePath = (path2) => {
|
|
546
547
|
const drive = /^[A-Za-z]:(?=[\\/]|$)/.exec(path2)?.[0];
|
|
547
548
|
const rest = drive === void 0 ? path2 : path2.slice(drive.length).replaceAll("\\", "/");
|
|
@@ -555,7 +556,9 @@ var normalizePath = (path2) => {
|
|
|
555
556
|
};
|
|
556
557
|
var appPath = (root, ...parts) => normalizePath([root, APP, ...parts].join("/"));
|
|
557
558
|
var brokerFolder = (home) => appPath(home, BROKER);
|
|
558
|
-
var GUARD_MARKERS = [HINTS, FUNCTIONS, LEARNED, OAUTH, BROKER].map(
|
|
559
|
+
var GUARD_MARKERS = [HINTS, FUNCTIONS, LEARNED, OAUTH, BROKER, LOCKS].map(
|
|
560
|
+
(name) => `${APP}/${name}`
|
|
561
|
+
);
|
|
559
562
|
|
|
560
563
|
// src/core/share.ts
|
|
561
564
|
var STATE_WORDS = [
|
|
@@ -1006,21 +1009,24 @@ var makeLog = (file2) => {
|
|
|
1006
1009
|
};
|
|
1007
1010
|
};
|
|
1008
1011
|
var endTree = (proc) => {
|
|
1009
|
-
if (proc.pid === void 0) return;
|
|
1012
|
+
if (proc.pid === void 0) return Promise.resolve();
|
|
1010
1013
|
if (process.platform === "win32") {
|
|
1011
|
-
if (proc.exitCode !== null || proc.signalCode !== null) return;
|
|
1012
|
-
|
|
1013
|
-
"
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1014
|
+
if (proc.exitCode !== null || proc.signalCode !== null) return Promise.resolve();
|
|
1015
|
+
return new Promise((resolve) => {
|
|
1016
|
+
const killer = nodeSpawn("taskkill", ["/pid", String(proc.pid), "/T", "/F"], {
|
|
1017
|
+
windowsHide: true,
|
|
1018
|
+
stdio: "ignore"
|
|
1019
|
+
});
|
|
1020
|
+
killer.on("error", () => resolve());
|
|
1021
|
+
killer.on("close", () => resolve());
|
|
1022
|
+
});
|
|
1018
1023
|
}
|
|
1019
1024
|
try {
|
|
1020
1025
|
process.kill(-proc.pid, "SIGKILL");
|
|
1021
1026
|
} catch {
|
|
1022
1027
|
proc.kill("SIGKILL");
|
|
1023
1028
|
}
|
|
1029
|
+
return Promise.resolve();
|
|
1024
1030
|
};
|
|
1025
1031
|
var RECOVER_MS = 8e3;
|
|
1026
1032
|
var LOCK_STALE_MS = 5e3;
|