toolfunnel 0.5.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.
Files changed (72) hide show
  1. package/README.md +235 -167
  2. package/SECURITY.md +84 -0
  3. package/bin/toolfunnel.js +451 -147
  4. package/docs/KNOWN_BUGS.md +80 -33
  5. package/docs/MANUAL.pdf +0 -0
  6. package/docs/design.md +84 -0
  7. package/docs/packaging.md +115 -115
  8. package/hooks/hooks.manifest.json +27 -27
  9. package/hooks/scripts/example-audit.js +21 -21
  10. package/hooks/scripts/example-deny-dangerous.js +39 -31
  11. package/mcp/expose.example.json +30 -30
  12. package/mcp/servers/mock-modern/server.js +147 -0
  13. package/mcp/servers/mock-upstream/server.js +222 -12
  14. package/package.json +67 -65
  15. package/src/auth/config.js +174 -174
  16. package/src/auth/install.js +181 -181
  17. package/src/auth/resource-server.js +353 -344
  18. package/src/core/child-reaper.js +61 -0
  19. package/src/core/config-home.js +134 -134
  20. package/src/core/events.js +105 -105
  21. package/src/core/hook-engine.js +329 -275
  22. package/src/core/hook-loader.js +824 -791
  23. package/src/core/hook-runner.js +566 -346
  24. package/src/core/logger.js +297 -171
  25. package/src/core/matcher.js +100 -51
  26. package/src/core/metrics.js +75 -75
  27. package/src/core/rename-migration.js +163 -0
  28. package/src/core/requires.js +138 -138
  29. package/src/core/server-config.js +98 -77
  30. package/src/extend/add-hook.md +152 -142
  31. package/src/extend/add-mcp.md +119 -121
  32. package/src/extend/configure.md +88 -0
  33. package/src/extend/create-tool.md +168 -152
  34. package/src/extend/howto.js +102 -98
  35. package/src/extend/package.md +190 -187
  36. package/src/extend/wrap.md +99 -0
  37. package/src/mcp/aggregator.js +1674 -807
  38. package/src/mcp/expose-store.js +577 -430
  39. package/src/mcp/gated-run.js +210 -194
  40. package/src/mcp/http-transport.js +1563 -1012
  41. package/src/mcp/mcp-client.js +1070 -530
  42. package/src/mcp/modern.js +406 -0
  43. package/src/mcp/protocol.js +468 -466
  44. package/src/mcp/server.js +3112 -1405
  45. package/src/tools/registry.js +661 -513
  46. package/src/tools/tool-state.js +170 -104
  47. package/src/ui/public/app.js +1187 -1055
  48. package/src/ui/public/index.html +286 -249
  49. package/src/ui/public/styles.css +535 -535
  50. package/src/ui/server.js +1616 -1190
  51. package/tools/scripts/base64.js +139 -139
  52. package/tools/scripts/danger.js +61 -61
  53. package/tools/scripts/echo.js +39 -39
  54. package/tools/scripts/hash.js +101 -101
  55. package/tools/scripts/json.js +109 -109
  56. package/tools/scripts/text-stats.js +131 -131
  57. package/tools/scripts/tf-env.js +43 -43
  58. package/tools/scripts/tf-hook-add.js +151 -151
  59. package/tools/scripts/tf-hook-set.js +120 -112
  60. package/tools/scripts/tf-list.js +192 -192
  61. package/tools/scripts/tf-log.js +86 -86
  62. package/tools/scripts/tf-mcp-add.js +117 -117
  63. package/tools/scripts/tf-mcp-set.js +121 -102
  64. package/tools/scripts/tf-pack.js +237 -237
  65. package/tools/scripts/tf-tool-add.js +134 -129
  66. package/tools/scripts/tf-tool-set.js +142 -142
  67. package/tools/scripts/tf-wrap.js +103 -0
  68. package/tools/scripts/uuid.js +102 -102
  69. package/tools/tools.register.json +14 -3
  70. package/src/core/tool-registry.js +0 -180
  71. package/src/packages/packager.js +0 -715
  72. package/src/tools/drift.js +0 -138
@@ -1,33 +1,80 @@
1
- # Known issues & roadmap
2
-
3
- ToolFunnel has no known correctness bugs at this release. This file tracks the upcoming
4
- compatibility work and any limitations worth knowing about.
5
-
6
- ## Coming in 0.6.0 — the 2026-07-28 MCP specification
7
-
8
- The 2026-07-28 MCP revision is a **breaking** change to the protocol: it removes the `initialize`
9
- handshake, protocol-level sessions, and the standalone GET/SSE endpoint, and adds new required
10
- behaviours — per-request protocol metadata, `Mcp-Method` / `Mcp-Name` request headers, a
11
- `server/discover` endpoint, a `subscriptions/listen` change-notification stream, and
12
- `resultType` / `ttlMs` / `cacheScope` result fields.
13
-
14
- ToolFunnel 0.5.0 speaks the current `2024-11-05` protocol and works with every MCP client shipping
15
- today. **0.6.0** will add **dual-era** support — answering both the current handshake-based clients
16
- *and* the 2026-07-28 modern clients — built against the finalised spec after 28 July.
17
-
18
- Planned for 0.6.0:
19
-
20
- - **Dual-era transport** (current + 2026-07-28) so old and new clients both keep working.
21
- - `server/discover`, the new request-header validation, and the `subscriptions/listen` stream.
22
- - An **opt-in, per-upstream legacy-protocol shim**: keep an ageing MCP server working past the
23
- cutover by pinning the protocol version ToolFunnel speaks *to that upstream* — off by default,
24
- it names the exact version it drops to and warns at startup and on every call.
25
-
26
- ## Current limitations
27
-
28
- - The OAuth 2.1 resource-server and Streamable-HTTP support are recent and less battle-tested than
29
- the core — test your setup before relying on them in a networked deployment.
30
- - No Prometheus / OpenTelemetry metrics — a toggleable JSONL audit log and in-memory `/health`
31
- call counters only.
32
-
33
- Found a bug, or want to help with the 0.6.0 work? Issues and PRs are welcome.
1
+ # Known bugs
2
+
3
+ The **Open** list is what remains open as of 0.7.0. **Fixed in 0.7.0** marks the items from
4
+ 0.6.0's file that this release closed - kept and marked rather than silently deleted, so a
5
+ 0.6.0 reader can see their fate. The full change list is in the
6
+ [release notes](https://github.com/Rendeverance/toolfunnel/releases).
7
+
8
+ ## Open
9
+
10
+ - **OPEN - Modern-upstream subscriptions are not received.** The client does not yet open a
11
+ `subscriptions/listen` stream to modern upstreams, so their change-notifications never arrive;
12
+ the listen ack honestly refuses `resourceSubscriptions` when no legacy subscribe-capable
13
+ upstream is in scope.
14
+ - **OPEN - The elicitation bridge does not cover legacy clients.** A wrapped upstream's mid-call
15
+ `elicitation/create` bridges to MODERN clients as MRTR (`input_required` + retry), form and url
16
+ mode, gated on the caller's declared capability (0.7.0). A LEGACY client gets an automatic
17
+ decline instead - relaying backwards requests to legacy clients is unbuilt - and
18
+ `sampling/createMessage` / `roots/list` from upstreams are answered `-32601`. An elicitation can
19
+ only be bound to a call when exactly ONE wrapped call is in flight for that upstream (always
20
+ true on stdio); ambiguous concurrent HTTP calls decline rather than guess.
21
+ - **OPEN (deferred) - HTTP cancels are dropped rather than translated.** The sessionless modern
22
+ era gives a POST no connection identity, so a client `notifications/cancelled` arriving over
23
+ HTTP is dropped rather than risk cancelling another client's call. Fixing this needs design
24
+ thought - identifying the caller without reintroducing sessions - so it is deferred rather than
25
+ patched. stdio (one client per pipe) translates and forwards cancels for both forwarded methods
26
+ and wrapped tool calls; the remaining best-effort windows there are sub-millisecond (a cancel
27
+ racing the instant a forward is issued) plus the PreToolUse gate-evaluation phase of a tool
28
+ call (registered at upstream-issue time, post-gate).
29
+
30
+ ## Fixed in 0.7.0
31
+
32
+ - ***FIXED*** - **Legacy version negotiation.** 0.6.0 answered every `initialize` with
33
+ 2024-11-05 whatever the client asked for, and supported exactly one legacy revision. The
34
+ gateway now echoes the requested version when it supports it (else answers its latest legacy),
35
+ and the legacy set spans 2024-11-05 / 2025-03-26 / 2025-06-18 / 2025-11-25. Pinned by
36
+ `test/negotiation.test.js`. One direction remains conservative: the client still offers
37
+ 2024-11-05 to legacy upstreams (field fidelity is unaffected; only the advertised version
38
+ string is older than either end requires).
39
+ - ***FIXED*** - **Header validation used a generic error code for an unsupported version.** An
40
+ unsupported `MCP-Protocol-Version` header answered the generic `-32600`; it now answers
41
+ `-32022` with `data.supported` and `data.requested` - the same code and shape the `_meta`
42
+ path already used for the same condition, so a client can renegotiate without parsing prose.
43
+ Pinned by `test/header-enforcement.test.js`.
44
+ - ***FIXED*** - **The wrap's identity-mirror reconnect re-ran the full era negotiation** (worst
45
+ case roughly 3 s per respawn against an upstream that ignores `server/discover`). The
46
+ negotiated era is now remembered per upstream, and a death-driven reconnect goes straight to
47
+ the era it knows. A failed hinted connect or an explicit reconnect re-negotiates in full, so
48
+ an upstream upgraded across a restart is never pinned down an era. Pinned by
49
+ `test/reconnect-era-memo.test.js`.
50
+ - ***FIXED*** - **`io.modelcontextprotocol/logLevel` was stripped on wrapped forwards.** Now
51
+ era-keyed at the client boundary: a modern upstream gets the caller's level verbatim in
52
+ `_meta`; a legacy upstream that declared the `logging` capability gets `logging/setLevel`
53
+ issued before the call (and the key never leaks into legacy `_meta`). Pinned by
54
+ `test/loglevel.test.js`.
55
+
56
+ ## By design (not bugs)
57
+
58
+ These answer "why doesn't it do X". They are considered decisions, not defects.
59
+
60
+ - **The config home defaults to the package root.** A git clone keeps working unchanged, and
61
+ seeding protects it from `npm update`, with an every-start relocation hint. Defaulting it to a
62
+ per-user directory instead needs a migration story for existing installs, so it ships as its own
63
+ release rather than as a rider. (`preuninstall` as a rescue mechanism is tested DEAD on npm
64
+ 11.9.0 - it will not be built.)
65
+ - **Funnel-mode curated descriptions carry an `[upstream]` title prefix** that lean passthrough
66
+ does not. A toggle to reconcile the two is cosmetic.
67
+ - **The `command` slot is not path-guarded, and `PATH` is deliberately permitted.** The command
68
+ names the interpreter (`node`, a system binary), which by definition lives outside the config
69
+ home, and guarding `PATH` would break how commands resolve at all - so an upstream entry
70
+ combining `command: "node"` with a caller-supplied `env.PATH` runs whatever that PATH resolves.
71
+ This is a documented boundary, not an oversight: an upstream entry already specifies an
72
+ arbitrary command to execute, so the isolation guard is a **tripwire** for configs that quietly
73
+ reach outside an auditable config home - not a sandbox against an untrusted pack author.
74
+ Installing a pack is installing software (see [SECURITY.md](../SECURITY.md)).
75
+ - **A meta-less `server/discover` is answered rather than refused** - permissive by design.
76
+ - **Discover works on a DISABLED upstream**, so its tools can be inspected before enabling. An
77
+ explicit allowance on the discover path only; the disabled upstream never reaches the tool
78
+ surface.
79
+
80
+ Found a bug, or want to help with the open work? Issues and PRs are welcome.
package/docs/MANUAL.pdf CHANGED
Binary file
package/docs/design.md ADDED
@@ -0,0 +1,84 @@
1
+ # Design decisions
2
+
3
+ Short notes on the decisions that shape ToolFunnel, so you can judge the reasoning without
4
+ reading the source. Each one is also documented at the place in the code where it bites.
5
+
6
+ ## 1. Zero runtime dependencies
7
+
8
+ ToolFunnel sits in a privileged position: it executes tools and enforces policy. Every
9
+ transitive dependency in that position is something you have to trust or audit. So the gateway
10
+ uses Node built-ins only; "dependencies" in package.json is empty and stays empty. The one
11
+ exception is deliberate and opt-in: OAuth token validation uses jose, installed only when you
12
+ run `toolfunnel install-oauth`, version-pinned, because hand-rolled JWT crypto is how security
13
+ holes are born. Dev tooling for the test suite (jose, the MCP SDK for interop tests) never
14
+ ships.
15
+
16
+ ## 2. No SDK
17
+
18
+ The gateway hand-rolls JSON-RPC over stdio and HTTP rather than building on the official MCP
19
+ SDK. Two reasons. First, the zero-dependency stance above. Second, ToolFunnel has to speak two
20
+ protocol eras at once, on both sides, which the SDK does not do; owning the wire layer is what
21
+ makes the dual-era serving and the wrap possible at all.
22
+
23
+ ## 3. The gate: a deny is absolute, an unreadable decision is a deny
24
+
25
+ Every server-side execution path goes through one function, gatedRun, and that function treats
26
+ every failure it can *see* as a deny: a hook that blocks, a hook engine that crashes, a malformed
27
+ engine result, a decision too large or too mangled to parse - all of them mean the tool does not
28
+ run. An answer we cannot read is never treated as permission. Denies carry a flag distinguishing
29
+ operator policy ("your hook said no") from wiring failure ("the gate itself broke"), so a broken
30
+ gate can never be mistaken for an approving one.
31
+
32
+ The line is drawn at a hook that never answered at all. A hook *script* that crashes, is missing,
33
+ or hangs past its timeout is a non-blocking error and the call proceeds. That is Claude Code's
34
+ hook protocol and it is a deliberate trade: denying there would mean a single broken hook file -
35
+ a typo, a deleted script, a slow disk - silently taking every tool in the gateway offline, and an
36
+ operator debugging that has no signal to follow. So the runtime failure is reported and the call
37
+ continues, while the *decision* path stays strict. The consequence for anyone writing a gate is
38
+ concrete: deny with `exit 2`, never with a bare non-zero, and if your policy cannot decide, exit 2
39
+ deliberately. Both halves of this contract are pinned by test/gate-semantics.test.js.
40
+
41
+ ## 4. The isolation boundary
42
+
43
+ Upstream server definitions can name any executable, but every field that decides what code the
44
+ spawned process runs must stay inside the config home: path-shaped arguments (including the
45
+ value after `=` in a `--flag=value` form), the working directory (`cwd`) bare arguments resolve
46
+ against, and the small set of environment variables that load code on their own (`NODE_OPTIONS`,
47
+ `NODE_PATH`, and their equivalents for other runtimes). The command is not guarded - it is the
48
+ interpreter you chose, not the code it runs. The guard relaxes only by explicit opt-out, each
49
+ per upstream and each with a warning naming itself: wrapping (a wrap is an explicit statement
50
+ that this one server is your entire surface), `allowOutsidePaths: true` on the upstream's own
51
+ entry (its paths and path-list env), and `allowCodeLoadingEnv: true` (the env class on its own).
52
+
53
+ ## 5. Two eras, served per request
54
+
55
+ The 2026-07-28 revision removes the handshake that defines the older protocol, so "which era"
56
+ is a property of each request, and that is how the gateway treats it: era detection per
57
+ request, no mode switch, no configuration. Legacy answers stay byte-identical to what a
58
+ pre-0.6.0 client saw; the gateway's own modern decoration only ever appears on modern
59
+ requests. (A wrapped modern upstream's results are relayed verbatim, whatever era the
60
+ caller speaks - stripping a server's own fields would be data loss and a wrapper tell.)
61
+
62
+ ## 6. Config lives in one folder
63
+
64
+ Everything mutable (tools, upstreams, hooks, identity, logs) lives in the config home,
65
+ relocatable with `--config-dir` or `TOOLFUNNEL_HOME`, seeded once, never overwritten by
66
+ updates. One folder to back up, one folder to package, one folder to hand a colleague. The
67
+ gateway prints the resolved home at every start so there is never any doubt about where state
68
+ lives.
69
+
70
+ ## 7. Single operator by design
71
+
72
+ Each ToolFunnel instance serves one operator. That is a decision, not an oversight: one
73
+ instance per user gives process isolation, crash containment, per-user wrap state, and a
74
+ security boundary you can reason about in one sentence. Multi-user deployment composes *in
75
+ front of* the gateway rather than inside it - an authenticating proxy at the OAuth boundary
76
+ (ToolFunnel is already an OAuth 2.1 resource server) routing each authenticated user to their
77
+ own instance, with the per-request `_meta` lane carrying user context through to upstreams
78
+ that want it. Nothing in the core couples the operator to a token subject, so that door stays
79
+ open without the core ever growing user-shaped complexity.
80
+
81
+ A Team edition built on this pattern - per-user identity, audit trails, quotas, per-user
82
+ policy - is on the roadmap if there is interest. If your team wants that sooner, or you need a
83
+ bespoke gateway built on ToolFunnel for your own requirements, open an issue on this
84
+ repository titled `enquiry` - tailored builds are available.
package/docs/packaging.md CHANGED
@@ -1,115 +1,115 @@
1
- # Packaging: ship what you built
2
-
3
- ToolFunnel's config is a folder. That single fact is the whole packaging story: everything you
4
- build in a gateway — your tools and their scripts, which of them are promoted hot or hidden, the
5
- upstream MCPs you attached and the tools you chose to expose from them, the policy hooks that gate
6
- every call, and the identity the server introduces itself with — lives in one directory tree, the
7
- **config home**. Ship the tree and you have shipped the product.
8
-
9
- ## The config home
10
-
11
- By default the home is the package/clone root — a git clone works exactly as it always did. Point
12
- the gateway elsewhere and the config lives there instead:
13
-
14
- ```
15
- toolfunnel --config-dir D:\my-setup # flag (wins)
16
- TOOLFUNNEL_HOME=D:\my-setup toolfunnel # env var
17
- ```
18
-
19
- An empty home is **seeded** on first use from the shipped defaults (the register + management
20
- scripts, an empty `mcp/expose.json`, the default hooks manifest) and is **never overwritten**
21
- afterwards — which is the point: with the home outside the package, `npm update toolfunnel`
22
- can never eat your tools.
23
-
24
- ```
25
- <home>/
26
- toolfunnel.json # identity (serverName/serverVersion), port defaults, `requires`
27
- tools/
28
- tools.register.json # your tool entries (incl. their inputSchema)
29
- tools.state.json # the hot/hidden/enabled curation — part of the product
30
- scripts/ # the tool scripts
31
- mcp/expose.json # upstream references + curated exposure
32
- hooks/ # the policy gate: manifest + hook scripts
33
- ```
34
-
35
- ## `tf_pack` — one call to a deployment artifact
36
-
37
- The `tf_pack` management tool snapshots the LIVE setup into `<home>/dist/<name>/` — always a
38
- separate location, never the live tree. `auth/` (environment-specific) and `logs/` never ship.
39
-
40
- **`{ format: "home" }`** → a portable config home. Zip it, commit it to a repo, or run it as-is:
41
-
42
- ```
43
- toolfunnel --config-dir path/to/the-pack
44
- ```
45
-
46
- **`{ format: "npm", name: "my-mcp", version: "1.0.0" }`** → a publishable npm package:
47
-
48
- ```
49
- dist/my-mcp/
50
- package.json # name, bin, files, dependencies: { "toolfunnel": "^0.4.0" }
51
- bin/my-mcp.js # 2 lines: pin --config-dir at ../home, delegate to toolfunnel
52
- home/ # the bundled config home (identity rewritten to my-mcp@1.0.0)
53
- README.md # a stub to make your own
54
- ```
55
-
56
- Review it, then `cd dist/my-mcp && npm publish`. Your users run `npx my-mcp` and get **your**
57
- server: your name in the MCP `initialize` handshake, your tools with your schemas, your curation,
58
- and — the part nobody else can say — **your gate**. The hooks travel inside the pack and enforce
59
- your policy on the recipient's machine regardless of which MCP client calls it.
60
-
61
- ### Depend, never copy
62
-
63
- The generated package **depends on** `toolfunnel` (caret range) rather than vendoring it. Your own
64
- runtime dependencies go in **your** `package.json` exactly as with any npm package — npm installs
65
- the whole tree on `npx my-mcp`; toolfunnel itself adds zero. Why depending matters:
66
-
67
- - security and bug fixes reach every wrapped MCP through a normal `npm update` — no stale forks
68
- carrying old bugs;
69
- - your package stays a few KB of config instead of a copied engine;
70
- - (and honestly) every install of your MCP counts as a toolfunnel download, which keeps the thing
71
- you depend on alive.
72
-
73
- Your users can move the bundled home out of `node_modules` (so *their* edits survive *your*
74
- updates) via the `<NAME>_HOME` env var the generated launcher supports.
75
-
76
- ## Declaring runtimes: `requires`
77
-
78
- Your tools may need runtimes the gateway doesn't (python, git, ffmpeg…). Declare them in the
79
- home's `toolfunnel.json` and they travel with every pack:
80
-
81
- ```json
82
- {
83
- "serverName": "my-mcp",
84
- "requires": [
85
- { "command": "python", "min": "3.10", "why": "the pdf-extract tools" },
86
- { "command": "git" }
87
- ]
88
- }
89
- ```
90
-
91
- The gateway probes them once at startup and prints one clear stderr line per problem — found
92
- version vs needed, plus your `why`. Advisory by design: a missing runtime breaks only the tools
93
- that need it, so the server still starts and everything else keeps working.
94
-
95
- ## Composite packs
96
-
97
- A pack is not just your own scripts. Because `mcp/expose.json` lives in the home, a pack carries
98
- **upstream references too**: "attach `@example/weather-mcp` (pin the version) and expose exactly
99
- these four tools under these names." The upstream itself travels as a *reference* — `npx` fetches
100
- it on the recipient's machine — while your **curation** and your **gate** travel as config. One
101
- pack = your tools + other people's servers, curated, renamed, and policed, as a single artifact.
102
-
103
- ## Audit honesty
104
-
105
- Packs spawn commands — that is what they are for. Before you run anyone's pack (including one of
106
- ours), read **three files** — every command it can run is declared in plain JSON:
107
-
108
- - `tools/tools.register.json` — the tool invokes (scripts and shell commands);
109
- - `mcp/expose.json` — the upstream server commands it will spawn;
110
- - `toolfunnel.json` — the `requires` probes. Note these run **at gateway startup** (each declared
111
- program is executed once with its version flag), which is why a `requires` command must be a
112
- bare program name — the gateway rejects paths, spaces, and shell characters outright.
113
-
114
- Ship your own packs expecting the same scrutiny, and say so in your README (the `tf_pack` stub
115
- already does).
1
+ # Packaging: ship what you built
2
+
3
+ ToolFunnel's config is a folder. That single fact is the whole packaging story: everything you
4
+ build in a gateway - your tools and their scripts, which of them are promoted hot or hidden, the
5
+ upstream MCPs you attached and the tools you chose to expose from them, the policy hooks that gate
6
+ every call, and the identity the server introduces itself with - lives in one directory tree, the
7
+ **config home**. Ship the tree and you have shipped the product.
8
+
9
+ ## The config home
10
+
11
+ By default the home is the package/clone root - a git clone works exactly as it always did. Point
12
+ the gateway elsewhere and the config lives there instead:
13
+
14
+ ```
15
+ toolfunnel --config-dir D:\my-setup # flag (wins)
16
+ TOOLFUNNEL_HOME=D:\my-setup toolfunnel # env var
17
+ ```
18
+
19
+ An empty home is **seeded** on first use from the shipped defaults (the register + management
20
+ scripts, an empty `mcp/expose.json`, the default hooks manifest) and is **never overwritten**
21
+ afterwards - which is the point: with the home outside the package, `npm update toolfunnel`
22
+ can never eat your tools.
23
+
24
+ ```
25
+ <home>/
26
+ toolfunnel.json # identity (serverName/serverVersion), port defaults, `requires`
27
+ tools/
28
+ tools.register.json # your tool entries (incl. their inputSchema)
29
+ tools.state.json # the hot/hidden/enabled curation - part of the product
30
+ scripts/ # the tool scripts
31
+ mcp/expose.json # upstream references + curated exposure
32
+ hooks/ # the policy gate: manifest + hook scripts
33
+ ```
34
+
35
+ ## `tf_pack` - one call to a deployment artifact
36
+
37
+ The `tf_pack` management tool snapshots the LIVE setup into `<home>/dist/<name>/` - always a
38
+ separate location, never the live tree. `auth/` (environment-specific) and `logs/` never ship.
39
+
40
+ **`{ format: "home" }`** → a portable config home. Zip it, commit it to a repo, or run it as-is:
41
+
42
+ ```
43
+ toolfunnel --config-dir path/to/the-pack
44
+ ```
45
+
46
+ **`{ format: "npm", name: "my-mcp", version: "1.0.0" }`** → a publishable npm package:
47
+
48
+ ```
49
+ dist/my-mcp/
50
+ package.json # name, bin, files, dependencies: { "toolfunnel": "^<current version>" }
51
+ bin/my-mcp.js # 2 lines: pin --config-dir at ../home, delegate to toolfunnel
52
+ home/ # the bundled config home (identity rewritten to my-mcp@1.0.0)
53
+ README.md # a stub to make your own
54
+ ```
55
+
56
+ Review it, then `cd dist/my-mcp && npm publish`. Your users run `npx my-mcp` and get **your**
57
+ server: your name in the MCP `initialize` handshake, your tools with your schemas, your curation,
58
+ and - the part nobody else can say - **your gate**. The hooks travel inside the pack and enforce
59
+ your policy on the recipient's machine regardless of which MCP client calls it.
60
+
61
+ ### Depend, never copy
62
+
63
+ The generated package **depends on** `toolfunnel` (caret range) rather than vendoring it. Your own
64
+ runtime dependencies go in **your** `package.json` exactly as with any npm package - npm installs
65
+ the whole tree on `npx my-mcp`; toolfunnel itself adds zero. Why depending matters:
66
+
67
+ - security and bug fixes reach every wrapped MCP through a normal `npm update` (the pack pins the caret range of the version that built it, so patch releases flow automatically) - no stale forks
68
+ carrying old bugs;
69
+ - your package stays a few KB of config instead of a copied engine;
70
+ - (and honestly) every install of your MCP counts as a toolfunnel download, which keeps the thing
71
+ you depend on alive.
72
+
73
+ Your users can move the bundled home out of `node_modules` (so *their* edits survive *your*
74
+ updates) via the `<NAME>_HOME` env var the generated launcher supports.
75
+
76
+ ## Declaring runtimes: `requires`
77
+
78
+ Your tools may need runtimes the gateway doesn't (python, git, ffmpeg...). Declare them in the
79
+ home's `toolfunnel.json` and they travel with every pack:
80
+
81
+ ```json
82
+ {
83
+ "serverName": "my-mcp",
84
+ "requires": [
85
+ { "command": "python", "min": "3.10", "why": "the pdf-extract tools" },
86
+ { "command": "git" }
87
+ ]
88
+ }
89
+ ```
90
+
91
+ The gateway probes them once at startup and prints one clear stderr line per problem - found
92
+ version vs needed, plus your `why`. Advisory by design: a missing runtime breaks only the tools
93
+ that need it, so the server still starts and everything else keeps working.
94
+
95
+ ## Composite packs
96
+
97
+ A pack is not just your own scripts. Because `mcp/expose.json` lives in the home, a pack carries
98
+ **upstream references too**: "attach `@example/weather-mcp` (pin the version) and expose exactly
99
+ these four tools under these names." The upstream itself travels as a *reference* - `npx` fetches
100
+ it on the recipient's machine - while your **curation** and your **gate** travel as config. One
101
+ pack = your tools + other people's servers, curated, renamed, and policed, as a single artifact.
102
+
103
+ ## Audit honesty
104
+
105
+ Packs spawn commands - that is what they are for. Before you run anyone's pack (including one of
106
+ ours), read **three files** - every command it can run is declared in plain JSON:
107
+
108
+ - `tools/tools.register.json` - the tool invokes (scripts and shell commands);
109
+ - `mcp/expose.json` - the upstream server commands it will spawn;
110
+ - `toolfunnel.json` - the `requires` probes. Note these run **at gateway startup** (each declared
111
+ program is executed once with its version flag), which is why a `requires` command must be a
112
+ bare program name - the gateway rejects paths, spaces, and shell characters outright.
113
+
114
+ Ship your own packs expecting the same scrutiny, and say so in your README (the `tf_pack` stub
115
+ already does).
@@ -1,27 +1,27 @@
1
- {
2
- "version": 1,
3
- "hooks": [
4
- {
5
- "id": "pre-tool-use/example-deny-dangerous",
6
- "event": "PreToolUse",
7
- "matcher": "*",
8
- "type": "command",
9
- "command": "node \"${HOOKS_DIR}/scripts/example-deny-dangerous.js\"",
10
- "script": "scripts/example-deny-dangerous.js",
11
- "timeout": 10,
12
- "enabled": false,
13
- "description": "EXAMPLE (disabled by default). A PreToolUse policy gate: denies any tool call whose arguments contain an obviously-destructive shell pattern (rm -rf, mkfs, drive format, fork bomb). A non-zero exit fails closed and blocks the call before it runs. Enable it in the UI Hooks tab (or set enabled:true here) to see the gate bite; edit scripts/example-deny-dangerous.js to encode your own policy."
14
- },
15
- {
16
- "id": "post-tool-use/example-audit",
17
- "event": "PostToolUse",
18
- "matcher": "*",
19
- "type": "command",
20
- "command": "node \"${HOOKS_DIR}/scripts/example-audit.js\"",
21
- "script": "scripts/example-audit.js",
22
- "timeout": 10,
23
- "enabled": false,
24
- "description": "EXAMPLE (disabled by default). A PostToolUse observer: runs AFTER a tool executes (advisory — it cannot un-run the call) and receives the tool result on stdin. The stub exits 0 (clean pass); replace its body to forward results to your own audit sink, metrics, or SIEM. Enable it in the UI Hooks tab (or set enabled:true here)."
25
- }
26
- ]
27
- }
1
+ {
2
+ "version": 1,
3
+ "hooks": [
4
+ {
5
+ "id": "pre-tool-use/example-deny-dangerous",
6
+ "event": "PreToolUse",
7
+ "matcher": "*",
8
+ "type": "command",
9
+ "command": "node \"${HOOKS_DIR}/scripts/example-deny-dangerous.js\"",
10
+ "script": "scripts/example-deny-dangerous.js",
11
+ "timeout": 10,
12
+ "enabled": false,
13
+ "description": "EXAMPLE (disabled by default). A PreToolUse policy gate: denies any tool call whose arguments contain an obviously-destructive shell pattern (rm -rf, mkfs, drive format, fork bomb). Exit 2 denies and blocks the call before it runs; exit 0 allows. Any OTHER exit (a crash, a missing script, a timeout) is a non-blocking error and the call PROCEEDS - write denies as exit 2, never as a bare non-zero. Enable it in the UI Hooks tab (or set enabled:true here) to see the gate bite; edit scripts/example-deny-dangerous.js to encode your own policy."
14
+ },
15
+ {
16
+ "id": "post-tool-use/example-audit",
17
+ "event": "PostToolUse",
18
+ "matcher": "*",
19
+ "type": "command",
20
+ "command": "node \"${HOOKS_DIR}/scripts/example-audit.js\"",
21
+ "script": "scripts/example-audit.js",
22
+ "timeout": 10,
23
+ "enabled": false,
24
+ "description": "EXAMPLE (disabled by default). A PostToolUse observer: runs AFTER a tool executes (advisory - it cannot un-run the call) and receives the tool result on stdin. The stub exits 0 (clean pass); replace its body to forward results to your own audit sink, metrics, or SIEM. Enable it in the UI Hooks tab (or set enabled:true here)."
25
+ }
26
+ ]
27
+ }
@@ -1,21 +1,21 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * EXAMPLE PostToolUse observer — DISABLED by default.
6
- *
7
- * PostToolUse is ADVISORY: it runs AFTER a tool has executed and CANNOT un-run it — it observes the
8
- * outcome. The lifecycle event (including the tool result) arrives as JSON on stdin. This stub just
9
- * exits 0 (a clean pass). Replace the body to forward results to your own audit sink, metrics, an
10
- * external SIEM, etc. Exit 0 = observed; a non-zero exit on PostToolUse is a non-blocking error.
11
- *
12
- * Zero dependencies — Node built-ins only.
13
- */
14
-
15
- let raw = '';
16
- process.stdin.on('data', (c) => { raw += c; });
17
- process.stdin.on('end', () => {
18
- // let ev = JSON.parse(raw || '{}'); // { tool_name, tool_input, tool_response, ... }
19
- // ... forward ev to your audit sink here ...
20
- process.exit(0);
21
- });
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * EXAMPLE PostToolUse observer - DISABLED by default.
6
+ *
7
+ * PostToolUse is ADVISORY: it runs AFTER a tool has executed and CANNOT un-run it - it observes the
8
+ * outcome. The lifecycle event (including the tool result) arrives as JSON on stdin. This stub just
9
+ * exits 0 (a clean pass). Replace the body to forward results to your own audit sink, metrics, an
10
+ * external SIEM, etc. Exit 0 = observed; a non-zero exit on PostToolUse is a non-blocking error.
11
+ *
12
+ * Zero dependencies - Node built-ins only.
13
+ */
14
+
15
+ let raw = '';
16
+ process.stdin.on('data', (c) => { raw += c; });
17
+ process.stdin.on('end', () => {
18
+ // let ev = JSON.parse(raw || '{}'); // { tool_name, tool_input, tool_response, ... }
19
+ // ... forward ev to your audit sink here ...
20
+ process.exit(0);
21
+ });
@@ -1,31 +1,39 @@
1
- #!/usr/bin/env node
2
- 'use strict';
3
-
4
- /**
5
- * EXAMPLE PreToolUse gate — DISABLED by default (enable it in hooks/hooks.manifest.json, or via the
6
- * UI Hooks tab / the per-tool "Pre" toggle on the Tools tab).
7
- *
8
- * This is the shape of a real policy gate: it runs INSIDE the gateway, BEFORE a tool executes, and a
9
- * non-zero exit DENIES the call (the gate fails closed). The lifecycle event arrives as JSON on
10
- * stdin; here we block any call whose arguments contain an obviously-destructive shell pattern.
11
- *
12
- * Block protocol (the simple one): write the reason to stderr and `process.exit(2)`. (A richer JSON
13
- * protocol is also supported — see docs/hooks-and-gating.md.) Exit 0 = allow.
14
- *
15
- * Zero dependencies — Node built-ins only.
16
- */
17
-
18
- let raw = '';
19
- process.stdin.on('data', (c) => { raw += c; });
20
- process.stdin.on('end', () => {
21
- let ev = {};
22
- try { ev = JSON.parse(raw || '{}'); } catch (_e) { /* malformed payload → allow (don't block on a parse error) */ }
23
- const args = JSON.stringify((ev && ev.tool_input) || {});
24
- // A small illustrative denylist: recursive-force delete, mkfs, drive format, fork bomb.
25
- const DANGER = /\brm\s+-[a-z]*r[a-z]*f|\bmkfs\b|\bformat\s+[a-z]:|:\(\)\s*\{\s*:/i;
26
- if (DANGER.test(args)) {
27
- process.stderr.write('example-deny-dangerous: blocked — the arguments contain a destructive pattern.\n');
28
- process.exit(2); // DENY — the gateway refuses to run the tool
29
- }
30
- process.exit(0); // allow
31
- });
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+
4
+ /**
5
+ * EXAMPLE PreToolUse gate - DISABLED by default (enable it in hooks/hooks.manifest.json, or via the
6
+ * UI Hooks tab / the per-tool "Pre" toggle on the Tools tab).
7
+ *
8
+ * This is the shape of a real policy gate: it runs INSIDE the gateway, BEFORE a tool executes, and
9
+ * `process.exit(2)` DENIES the call. The lifecycle event arrives as JSON on stdin; here we block any
10
+ * call whose arguments contain an obviously-destructive shell pattern.
11
+ *
12
+ * Block protocol (the simple one): write the reason to stderr and `process.exit(2)`. (A richer JSON
13
+ * protocol is also supported - see docs/MANUAL.pdf section 10.) Exit 0 = allow.
14
+ *
15
+ * EXIT 2, NOT "non-zero" - the difference matters when you write your own. Every OTHER exit (a
16
+ * crash, a syntax error, a missing file, a timeout) is a NON-BLOCKING ERROR and the call proceeds,
17
+ * so `exit(1)` on an error path allows the very call you meant to stop. If your policy cannot
18
+ * reach a decision, exit 2 deliberately. (The gateway does refuse a decision it cannot READ -
19
+ * output past the cap, unparseable JSON - because an unreadable answer is not permission. It
20
+ * cannot do the same for a script that never answered: one broken hook file would take every tool
21
+ * offline.) test/gate-semantics.test.js pins all of this.
22
+ *
23
+ * Zero dependencies - Node built-ins only.
24
+ */
25
+
26
+ let raw = '';
27
+ process.stdin.on('data', (c) => { raw += c; });
28
+ process.stdin.on('end', () => {
29
+ let ev = {};
30
+ try { ev = JSON.parse(raw || '{}'); } catch (_e) { /* malformed payload -> allow (don't block on a parse error) */ }
31
+ const args = JSON.stringify((ev && ev.tool_input) || {});
32
+ // A small illustrative denylist: recursive-force delete, mkfs, drive format, fork bomb.
33
+ const DANGER = /\brm\s+-[a-z]*r[a-z]*f|\bmkfs\b|\bformat\s+[a-z]:|:\(\)\s*\{\s*:/i;
34
+ if (DANGER.test(args)) {
35
+ process.stderr.write('example-deny-dangerous: blocked - the arguments contain a destructive pattern.\n');
36
+ process.exit(2); // DENY - the gateway refuses to run the tool
37
+ }
38
+ process.exit(0); // allow
39
+ });