toolsplice 0.0.0-stage → 0.0.1
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 +372 -2
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +923 -0
- package/dist/codegen.d.ts +44 -0
- package/dist/codegen.js +479 -0
- package/dist/contract-caller.d.ts +22 -0
- package/dist/contract-caller.js +307 -0
- package/dist/contract-corrections.d.ts +35 -0
- package/dist/contract-corrections.js +159 -0
- package/dist/contract-schema.d.ts +5 -0
- package/dist/contract-schema.js +126 -0
- package/dist/contracts.d.ts +71 -0
- package/dist/contracts.js +366 -0
- package/dist/core.d.ts +14 -0
- package/dist/core.js +16 -0
- package/dist/doctor.d.ts +22 -0
- package/dist/doctor.js +91 -0
- package/dist/drift.d.ts +23 -0
- package/dist/drift.js +111 -0
- package/dist/execution.d.ts +38 -0
- package/dist/execution.js +66 -0
- package/dist/extract.d.ts +34 -0
- package/dist/extract.js +73 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +19 -0
- package/dist/ordered-transport.d.ts +12 -0
- package/dist/ordered-transport.js +106 -0
- package/dist/pattern.d.ts +2 -0
- package/dist/pattern.js +32 -0
- package/dist/postgres.d.ts +41 -0
- package/dist/postgres.js +264 -0
- package/dist/probe.d.ts +29 -0
- package/dist/probe.js +134 -0
- package/dist/proxy.d.ts +40 -0
- package/dist/proxy.js +436 -0
- package/dist/runtime.d.ts +6 -0
- package/dist/runtime.js +26 -0
- package/dist/schema.d.ts +17 -0
- package/dist/schema.js +299 -0
- package/dist/shape.d.ts +91 -0
- package/dist/shape.js +499 -0
- package/dist/splice-diagnostics.d.ts +40 -0
- package/dist/splice-diagnostics.js +80 -0
- package/dist/splice-project.d.ts +119 -0
- package/dist/splice-project.js +296 -0
- package/dist/splice-recording.d.ts +105 -0
- package/dist/splice-recording.js +464 -0
- package/dist/splice.d.ts +84 -0
- package/dist/splice.js +1065 -0
- package/dist/storage.d.ts +17 -0
- package/dist/storage.js +1 -0
- package/dist/store.d.ts +151 -0
- package/dist/store.js +735 -0
- package/dist/v2.d.ts +49 -0
- package/dist/v2.js +396 -0
- package/dist/validate-output.d.ts +3 -0
- package/dist/validate-output.js +73 -0
- package/dist/version.d.ts +1 -0
- package/dist/version.js +1 -0
- package/dist/workflow-json.d.ts +8 -0
- package/dist/workflow-json.js +74 -0
- package/docs/PROJECTS-AND-UPGRADES.md +115 -0
- package/docs/RECORDING-AND-CORRECTIONS.md +176 -0
- package/package.json +95 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 toolsplice contributors
|
|
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,373 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Toolsplice
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
**Test your MCP handoffs against saved responses and changed contracts.** Dry-run an explicit output-to-input mapping, replay captured calls offline, and generate a typed adapter that validates every destination argument before sending the first destination call.
|
|
4
|
+
|
|
5
|
+
```text
|
|
6
|
+
issues.list_issues[] people.get_person
|
|
7
|
+
assignee.personId ───→ id
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
A source field can be missing, nullable, inside a JSON string, or the wrong type for the next tool. A batch can contain one bad row halfway through. Toolsplice makes the mapping explicit and checks these assumptions using declared schemas or shapes learned from actual responses.
|
|
11
|
+
|
|
12
|
+
**Initial release, v0.0.1. Node.js 22+, ESM.** The package was previously called Callshape. `callshape` and `mcp-shape` remain CLI aliases, and existing learning stores remain readable.
|
|
13
|
+
|
|
14
|
+
An author-run [maintenance comparison](docs/MAINTENANCE-TRIAL.md) checks three existing project workflows against handwritten integrations using saved public responses and labelled mutations. Equally guarded code makes the same decisions; Toolsplice's proposed value is reusable artifacts, offline replay and diagnostics. Structural checks do not establish content accuracy. No independent adoption or developer-time savings have been measured. See the [developer trial](docs/DEVELOPER-TRIAL.md) for the next acceptance test.
|
|
15
|
+
|
|
16
|
+
## Start with one command
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install toolsplice@0.0.1
|
|
20
|
+
npx toolsplice init ./my-handoff
|
|
21
|
+
toolsplice project ./my-handoff --allow-review --json
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
When building from a local checkout, use `node dist/cli.js` in place of `toolsplice` after `npm run build`. The starter has synthetic contracts, an explicit plan, input/context, a source fixture and a generated adapter. Its check validates source arguments, context, source output, every mapped destination argument and whether the adapter is current. It calls no tools and installs no packages. Existing directories are refused.
|
|
25
|
+
|
|
26
|
+
Use a successful payload recording to scaffold an existing handoff without guessing its mapping:
|
|
27
|
+
|
|
28
|
+
```sh
|
|
29
|
+
toolsplice init ./my-handoff --from-recording recording.json
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Redacted recordings need an explicit private `--restorations` file. Restored project inputs/fixtures may contain confidential values and are written into a new private directory; the retained recording remains redacted. See the [projects and upgrades guide](docs/PROJECTS-AND-UPGRADES.md).
|
|
33
|
+
|
|
34
|
+
## Choose the package
|
|
35
|
+
|
|
36
|
+
- **`toolsplice`**: existing full library and CLI, SDK convenience adapters, learning proxy and optional PostgreSQL support. Existing imports and binary aliases remain supported.
|
|
37
|
+
- **`toolsplice-core`**: independently packaged Node library with handoff validation, typed adapter generation, recording/replay and corrections. Its production dependencies are Ajv and re2js; it requires no MCP SDK, Zod, transport/server stack or PostgreSQL driver. Applications provide raw-result `ToolCaller` functions.
|
|
38
|
+
|
|
39
|
+
Install `toolsplice@0.0.1` or `toolsplice-core@0.0.1`. For local development, `npm run build` prepares both; `npm pack` and `npm pack ./packages/core` create their respective tarballs for local installation. Core generation defaults to importing `toolsplice-core`; full-package generation defaults to `toolsplice`. Splitting the packages reduces installation dependencies for core consumers; the full package continues to include its transport features.
|
|
40
|
+
|
|
41
|
+
## Python
|
|
42
|
+
|
|
43
|
+
The [native Python SDK](packages/python/README.md) accepts async tool callers and optional MCP/HTTP adapters. No agent framework or Node runtime is required. Install with `python -m pip install toolsplice==0.0.1` (Python 3.11+), or `python -m pip install ./packages/python` from this checkout.
|
|
44
|
+
|
|
45
|
+
Version `0.0.1` includes static preflight, portable contracts/recordings/corrections, typed Python adapters, project CLI, shape learning, file/PostgreSQL stores, transparent MCP proxy and HTTPX middleware alongside the existing runtime checks. Shared artifacts/fingerprints and database/file locks are checked against JavaScript; generated Python/TypeScript files remain language-specific. See the [parity matrix](docs/PYTHON-PARITY.md) for tests and boundaries; the historical v0.1 preview report remains separately versioned.
|
|
46
|
+
|
|
47
|
+
## Check an upgrade offline
|
|
48
|
+
|
|
49
|
+
```sh
|
|
50
|
+
toolsplice replay recording.json --target-contract new-target.json --json
|
|
51
|
+
toolsplice replay recording.json --source-contract new-source.json \
|
|
52
|
+
--target-contract new-target.json --allow-review --json
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Candidate contracts are checked against the saved requests/responses, with schema diffs and field-origin explanations. `upgrade.status` is `passed`, `failed` or `inconclusive`. Previously failed/cancelled recordings cannot establish successful upgrade compatibility. Candidate checks exit 2 for failures or inconclusive results; ordinary replay still treats a matching expected failure as a passing regression. This verifies captured cases, not every possible provider response. Saved artifacts are never changed.
|
|
56
|
+
|
|
57
|
+
## Run the demo
|
|
58
|
+
|
|
59
|
+
For the handoff and recording workflow, run:
|
|
60
|
+
|
|
61
|
+
```sh
|
|
62
|
+
npm ci
|
|
63
|
+
npm run demo:handoff
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
It starts two synthetic MCP servers, writes four new Markdown files inside a private demo folder, and proves invalid context/source inputs, no-data responses and duplicate destination paths stop at the expected boundary. It compiles two generated adapters with five negative type checks and runs a compact offline CLI review. It records success/failure, shuts down both servers and replays those runs with zero further tool calls. There are ten native MCP tool calls and no model/API account is needed. Inspect the printed `demo-output/handoff-*/` directory, including `saved/`, `plan.json`, `context.json`, `adapter.ts`, `offline-review.json`, `recording-success.json`, `recording-failure.json` and `report.json`. `--out` selects a new directory, and `--json` prints the machine-readable report.
|
|
67
|
+
|
|
68
|
+
The existing issue → person demo also covers learning from ordinary traffic. From this checkout:
|
|
69
|
+
|
|
70
|
+
```sh
|
|
71
|
+
npm ci
|
|
72
|
+
npm run demo
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
The demo starts two synthetic MCP servers and:
|
|
76
|
+
|
|
77
|
+
1. Observes an issue-list result and a person lookup, including JSON returned after a prose prefix.
|
|
78
|
+
2. Checks an explicit mapping and dry-runs a saved result with **zero additional tool calls**.
|
|
79
|
+
3. Blocks numeric `issue.id → person.id` before either server is called.
|
|
80
|
+
4. Generates and compiles a TypeScript adapter, checking six incorrect type usages.
|
|
81
|
+
5. Runs the corrected adapter: **one source call and two destination calls**.
|
|
82
|
+
6. Changes the source output and verifies that neither destination lookup runs.
|
|
83
|
+
|
|
84
|
+
Inspect the printed `demo-output/run-*/` folder: `splice.json`, `preflight.json`, `bad-plan-report.json`, `adapter.ts`, `workflow.ts`, and `report.json`. Runs use fresh folders. `npm run demo -- --out /absolute/path/to/new-folder` selects a new directory whose parent exists. The fixture data is synthetic; no model, API key or external account is needed. The generated folder links to this checkout for package resolution.
|
|
85
|
+
|
|
86
|
+
## Record, explain and replay
|
|
87
|
+
|
|
88
|
+
Capture one run through the standalone library. No Cloudflare service or account is required:
|
|
89
|
+
|
|
90
|
+
```ts
|
|
91
|
+
import { createSpliceRecorder, replaySpliceRecording } from 'toolsplice';
|
|
92
|
+
|
|
93
|
+
const recorder = createSpliceRecorder(plan, sourceContract, targetContract, {
|
|
94
|
+
capture: 'payloads', // Default is metadata only.
|
|
95
|
+
redactKeys: ['customerEmail'],
|
|
96
|
+
redactValues: [process.env.PROVIDER_SECRET].filter((v): v is string => !!v),
|
|
97
|
+
});
|
|
98
|
+
await recorder.run(sourceCaller, targetCaller, input, {
|
|
99
|
+
allowReview: true,
|
|
100
|
+
context: { path: 'saved.md' },
|
|
101
|
+
});
|
|
102
|
+
const recording = recorder.snapshot(); // Also available after a rejected run.
|
|
103
|
+
// Application owns storage; save explicitly to a private file.
|
|
104
|
+
|
|
105
|
+
// Later, using an unredacted recording or explicit private restorations:
|
|
106
|
+
const report = await replaySpliceRecording(savedRecording);
|
|
107
|
+
console.log(report.matched, report.networkCalls); // expected true, 0
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
```sh
|
|
111
|
+
node dist/cli.js replay recording.json --json
|
|
112
|
+
node dist/cli.js replay recording.json --restorations private-values.json --json
|
|
113
|
+
node dist/cli.js correct baseline.json --correction reviewed-correction.json \
|
|
114
|
+
--out corrected.json --json
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
Replay uses saved raw MCP responses and the saved contracts with the current guard implementation. It accepts no live caller/connection. A matching expected failure exits 0; a different call sequence, arguments or outcome exits 2. Invalid, incomplete or unrestored artifacts exit 1. CLI reports omit returned result payloads. Redaction is configurable and does not guarantee anonymization. Every redacted artifact path requires an explicit restoration before replay.
|
|
118
|
+
|
|
119
|
+
Use `explainSpliceError(plan, error)` for path-only failure details: binding index, destination path, source/context path, source selection/JSON parsing and row number where available. Literal values and raw exception causes are excluded. Fixture CLI reports include this explanation automatically.
|
|
120
|
+
|
|
121
|
+
Reviewed corrections pin the baseline fingerprint, replace explicit tool input/output schemas and require positive and negative fixtures. All fixtures must pass offline before a separate corrected contract is returned or written. The original is retained; output corrections are labelled `corrected`, and correction metadata is fingerprinted. Applications explicitly choose the corrected contract for execution. There is no automatic schema weakening or claim that fixtures prove live-provider behavior.
|
|
122
|
+
|
|
123
|
+
See [recording and corrections guide](docs/RECORDING-AND-CORRECTIONS.md) for complete formats, redaction/restoration, limits and examples.
|
|
124
|
+
|
|
125
|
+
## Define the handoff
|
|
126
|
+
|
|
127
|
+
A plan names the endpoints and maps JSON pointers explicitly:
|
|
128
|
+
|
|
129
|
+
```json
|
|
130
|
+
{
|
|
131
|
+
"format": "toolsplice-splice",
|
|
132
|
+
"formatVersion": 1,
|
|
133
|
+
"source": { "server": "issues", "tool": "list_issues" },
|
|
134
|
+
"target": { "server": "people", "tool": "get_person" },
|
|
135
|
+
"forEach": true,
|
|
136
|
+
"maxItems": 50,
|
|
137
|
+
"bindings": [
|
|
138
|
+
{ "to": "/id", "from": "/assignee/personId" }
|
|
139
|
+
]
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
`forEach` is opt-in. It changes the binding's source to one array item and caps the entire batch before destination dispatch. The default cap is 100; supported caps are 1–1,000. Without `forEach`, one destination argument object is produced. Empty batches make no destination calls. Exceeding the cap rejects the whole batch; it never silently truncates it.
|
|
144
|
+
|
|
145
|
+
Use `{ "to": "/state", "value": "open" }` for a literal. Destination paths can build nested objects, such as `/body/id`; they cannot overlap or create array elements. Map an entire array into its argument field instead. Paths use RFC 6901 escaping (`~1` for `/`, `~0` for `~`). Values are copied without coercion, and missing fields are errors.
|
|
146
|
+
|
|
147
|
+
For a JSON string inside an output wrapper, select and decode it explicitly:
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
"source": {
|
|
151
|
+
"server": "filesystem",
|
|
152
|
+
"tool": "directory_tree",
|
|
153
|
+
"path": "/content",
|
|
154
|
+
"parseJson": true
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
For APIs with a business success flag, add an explicit source expectation:
|
|
159
|
+
|
|
160
|
+
```json
|
|
161
|
+
"source": {
|
|
162
|
+
"server": "firecrawl",
|
|
163
|
+
"tool": "firecrawl_search",
|
|
164
|
+
"expect": [{ "path": "/success", "equals": true }],
|
|
165
|
+
"path": "/data/web/0"
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Expectations check the whole decoded response before `path`, `parseJson` or fanout. Missing fields and unequal JSON values stop execution before any destination call. Equality ignores object key order. Plans support up to 16 conditions and require review approval; Toolsplice does not guess which API flags mean success. Protocol `isError` responses already stop execution.
|
|
170
|
+
|
|
171
|
+
Toolsplice's ordinary MCP decoder already handles structured content and JSON text with a short prose prefix. `parseJson` handles an additional JSON document stored inside a string. It does not invent a parser for arbitrary prose.
|
|
172
|
+
|
|
173
|
+
Validation evidence and measured limits: [v0.6 report](docs/PIVOT-VALIDATION.md), [real-workflow assessment](docs/USEFULNESS-ASSESSMENT.md).
|
|
174
|
+
|
|
175
|
+
## Add explicit data requirements
|
|
176
|
+
|
|
177
|
+
A valid string can still say “No documentation found.” Add a consumer schema to the selected source value:
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
"source": {
|
|
181
|
+
"server": "gitmcp", "tool": "fetch_typescript_sdk_docs",
|
|
182
|
+
"valueSchema": {
|
|
183
|
+
"type": "string", "minLength": 100,
|
|
184
|
+
"not": { "const": "No documentation found." }
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
`valueSchema` runs after `path` and `parseJson`, before `forEach` or any destination dispatch. Use an array schema with `minItems` to reject an empty result set, or an object schema to require particular fields. It adds a consumer requirement; it does not change the saved server contract or prove that content is true. These plans require review, and unsupported validator assertions block setup. A failed requirement is a mapping-stage error in both fixtures and live runs.
|
|
190
|
+
|
|
191
|
+
For a batch whose destination identifiers must be distinct, declare explicit keys:
|
|
192
|
+
|
|
193
|
+
```json
|
|
194
|
+
"target": {
|
|
195
|
+
"server": "filesystem", "tool": "write_file",
|
|
196
|
+
"uniqueBy": ["/path"]
|
|
197
|
+
}
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
Toolsplice rejects the whole batch before its first destination call if a key is absent or two rows have the same tuple of key values. Multiple paths form one composite tuple, such as `["/tenantId", "/id"]`. JSON types remain distinct and object key order does not matter. Keys use destination argument paths; specify 1–8 paths without duplicates or overlaps. Uniqueness is optional, requires review, and applies only inside one mapped batch. It does not deduplicate, normalize identifiers, provide cross-run idempotency, or detect collisions in fields you did not select. Per-call context is shared by every row; using one file path for a multi-row batch will collide when `/path` is the declared key.
|
|
201
|
+
|
|
202
|
+
## Bound returned data
|
|
203
|
+
|
|
204
|
+
Plans can set `"maxResultBytes": 65536` to cap the UTF-8 JSON encoding of the final result array. The default is 5 MiB; supported limits are 2 bytes–64 MiB. Destination values are copied as bounded JSON before collection. A result that exceeds the remaining budget throws a target-stage `result-batch-byte-limit` error and prevents later destination calls; it does not truncate data or return partial success. The overflowing remote call may already have completed or committed. The count records earlier validated, collected results, not all remote side effects. This cap applies after a response is decoded; it is not a transport download limit or a model-token budget.
|
|
205
|
+
|
|
206
|
+
## Real-server verification
|
|
207
|
+
|
|
208
|
+
`npm run test:handoffs` explicitly downloads pinned official filesystem/memory servers into a disposable directory and calls the public DeepWiki and Microsoft Learn MCP endpoints. It compiles and executes generated adapters for DeepWiki → file, Learn search → fetch, file → memory lookup and explicit memory fanout. It also proves actual source errors and exceeded fanout caps prevent destination calls. Evidence goes to `test-results/`; remote responses and schemas can change.
|
|
209
|
+
|
|
210
|
+
`FIRECRAWL_API_KEY=... npm run test:firecrawl` runs a small authenticated search → scrape test using the real Firecrawl MCP server. It makes two live tool calls and consumes provider credits. It verifies a generated adapter, source success expectations, and invalid-input prevention; the credential is never written by the harness. The initial keyless connection listed tools but refused search from the test network. An authenticated run succeeded. No model API is used by these harnesses; provider-side implementation and billing remain the provider's responsibility.
|
|
211
|
+
|
|
212
|
+
`npm run test:firecrawl:workflows` exercises map → three scrapes, search → three link scrapes and paper search → two paper inspections. `npm run test:firecrawl:files` compiles a reusable scrape → filesystem adapter with per-call paths, then exposes it as one ordinary MCP tool. Both are explicitly opt-in, consume Firecrawl credits and retain public response fixtures locally. The filesystem harness installs a pinned reference server into disposable storage. No model API is called.
|
|
213
|
+
|
|
214
|
+
`npm run test:public:files` exercises public Context7, Hugging Face, Exa and GitMCP outputs against the official filesystem server, including an explicit no-data requirement. `npm run test:catalogs` lists public remote catalogs and checks validator setup without calling tools. Catalog coverage is not an execution or semantic-accuracy guarantee.
|
|
215
|
+
|
|
216
|
+
A real Firecrawl JSON-extraction probe found a declared-input/provider disagreement: its catalog rejects fields inside `jsonOptions.schema` that the server accepted. Toolsplice honors the reviewed catalog; it does not silently weaken a schema to make a request succeed. Review an explicit application-owned contract correction when a provider declaration is inaccurate. Shape validation also cannot verify extracted facts.
|
|
217
|
+
|
|
218
|
+
## Check, dry-run and generate
|
|
219
|
+
|
|
220
|
+
Use portable contract snapshots without a database or server connection:
|
|
221
|
+
|
|
222
|
+
```sh
|
|
223
|
+
node dist/cli.js splice plan.json \
|
|
224
|
+
--source-contract issues.json --target-contract people.json --json
|
|
225
|
+
|
|
226
|
+
node dist/cli.js splice plan.json \
|
|
227
|
+
--source-contract issues.json --target-contract people.json \
|
|
228
|
+
--fixture saved-result.json --fixture-format mcp \
|
|
229
|
+
--out adapter.ts --json
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
Saved MCP `tools/list` responses also work directly. No learning proxy or database is required:
|
|
233
|
+
|
|
234
|
+
```sh
|
|
235
|
+
node dist/cli.js splice plan.json \
|
|
236
|
+
--source-catalog source-tools.json --target-catalog target-tools.json \
|
|
237
|
+
--fixture result.json --fixture-format mcp --out adapter.ts --json
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Each endpoint accepts exactly one contract or catalog file; mixing a source contract with a target catalog is supported. Catalog identities come from the explicit plan. Catalogs describe declared schemas only; an omitted output remains unknown. Applications must collect the page containing the selected tool, or combine all `tools/list` pages. Missing selected tools and duplicate names are rejected.
|
|
241
|
+
|
|
242
|
+
Alternatively, read existing learning from files or PostgreSQL:
|
|
243
|
+
|
|
244
|
+
```sh
|
|
245
|
+
node dist/cli.js splice plan.json --store /private/learning --json
|
|
246
|
+
node dist/cli.js splice plan.json --database-env TOOL_STORAGE_URL --namespace project --json
|
|
247
|
+
```
|
|
248
|
+
|
|
249
|
+
These commands **never execute tools**. File-based checking does not open a learning store. `--fixture-format decoded` is the default; `mcp` decodes a saved MCP result envelope first. Dry-run output can contain the fixture values you explicitly supplied. `--out` writes a new `.ts` source file and refuses to overwrite it; blocked plans do not produce adapters.
|
|
250
|
+
|
|
251
|
+
Reports identify the exact plan and both endpoint contracts with fingerprints. Save the plan, contracts, fixture and report together to make a review reproducible. Add `--summary` to JSON fixture reports to keep mapped values out of the report while retaining row count and total argument bytes. It does not change validation or what an adapter would send. `--allow-review` changes a reviewed plan’s CLI exit to 0; `status` stays `review`, blocked plans still exit 2, and generated adapters still require their own runtime `allowReview: true`. This supports an intentional CI gate without treating uncertainty as compatibility.
|
|
252
|
+
|
|
253
|
+
Statuses are deliberately conservative:
|
|
254
|
+
|
|
255
|
+
| Status | Meaning | CLI exit | Adapter execution |
|
|
256
|
+
|---|---|---:|---|
|
|
257
|
+
| `ready` | Supported structural checks establish the mapping | 0 | Runtime guards still apply |
|
|
258
|
+
| `review` | Missing observations, optional fields or constraints leave uncertainty | 2 | Requires explicit `allowReview: true` |
|
|
259
|
+
| `blocked` | A known incompatibility or unsupported runtime schema prevents execution | 2 | Cannot execute |
|
|
260
|
+
|
|
261
|
+
A valid JSON fixture that fails source or mapping validation produces `status: blocked`, a structured `fixture` failure and exit 2; it does not create an adapter. `preflightStatus` preserves the static result. Raw MCP error fixtures are reported without echoing the provider error text. Malformed plans, unreadable files and configuration errors exit 1. Shape compatibility is not semantic identity: a `customerId` and an `orderId` can both be strings. **Toolsplice never guesses which fields mean the same thing.** Review the mapping yourself. Observed schemas remain provisional, and `ready` is not a provider guarantee.
|
|
262
|
+
|
|
263
|
+
If a server has no usable output schema, the optional learning proxy can observe ordinary traffic and save its return shape. It makes no extra calls to learn. See [learning and storage](docs/LEARNING-AND-STORAGE.md) for config generation, file paths/PVCs, PostgreSQL and snapshots. A developer with declared schemas can also construct a snapshot through `newServer`, `recordToolList` and `createContractSnapshot`.
|
|
264
|
+
|
|
265
|
+
## Use the generated adapter
|
|
266
|
+
|
|
267
|
+
Compile `adapter.ts` with your application:
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
import { createToolCaller } from 'toolsplice';
|
|
271
|
+
import { createSplice } from './adapter.js';
|
|
272
|
+
|
|
273
|
+
const lookupOwners = createSplice(
|
|
274
|
+
createToolCaller(issueClient),
|
|
275
|
+
createToolCaller(peopleClient),
|
|
276
|
+
);
|
|
277
|
+
const owners = await lookupOwners({ state: 'open' }, {
|
|
278
|
+
signal: abortController.signal,
|
|
279
|
+
timeoutMs: 30_000,
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
Use `createV2ToolCaller` from `toolsplice/v2` for SDK 2.x clients. Applications establish connections, authentication and authorization. Generated source input and destination output types come from the selected contracts. The result array follows source-row order; destination calls run sequentially. This is a two-tool adapter, not a general workflow executor or an execution sandbox.
|
|
284
|
+
|
|
285
|
+
The library surface is also usable directly:
|
|
286
|
+
|
|
287
|
+
```ts
|
|
288
|
+
import { prepareSplice } from 'toolsplice';
|
|
289
|
+
|
|
290
|
+
const splice = prepareSplice(plan, sourceContract, targetContract);
|
|
291
|
+
console.log(splice.report);
|
|
292
|
+
const argumentsForReview = await splice.mapOutput(savedDecodedOutput); // no tool calls
|
|
293
|
+
const results = await splice.run(sourceCaller, targetCaller, sourceArgs);
|
|
294
|
+
```
|
|
295
|
+
|
|
296
|
+
`parseSpliceSpec`, `preflightSplice` and `emitSpliceModule` are also exported. `prepareSplice` includes runtime-schema setup checks; `preflightSplice` performs only static analysis. `mapOutput` checks the whole fixture against the known source contract before validating mapped arguments. It can test a `review` plan against a fixture; live execution still requires `allowReview: true`. A `blocked` plan cannot map or run.
|
|
297
|
+
|
|
298
|
+
Source inputs are checked before the source call, source outputs after it, and **every mapped destination argument before any destination call**. Known destination output schemas are checked too; unknown outputs remain `unknown`. Cancellation and progress options pass through; `timeoutMs` applies to each tool call, not the whole splice. Use a deadline-backed `AbortSignal` to bound the entire operation. There are no retries or automatic skips. A destination failure throws `SpliceError` with `stage`, path-only `issues`, `completedTargets`, and its original `cause`. Completed destination calls are not rolled back; a failed or canceled remote request may already have committed. Output checks cannot undo the source's effects.
|
|
299
|
+
|
|
300
|
+
## Supply values for each call
|
|
301
|
+
|
|
302
|
+
A reusable scrape → file adapter needs both scraped content and an application-selected file path. Declare context separately from the source tool's arguments:
|
|
303
|
+
|
|
304
|
+
```json
|
|
305
|
+
{
|
|
306
|
+
"format": "toolsplice-splice",
|
|
307
|
+
"formatVersion": 1,
|
|
308
|
+
"source": { "server": "firecrawl", "tool": "firecrawl_scrape" },
|
|
309
|
+
"target": { "server": "filesystem", "tool": "write_file" },
|
|
310
|
+
"contextSchema": {
|
|
311
|
+
"type": "object",
|
|
312
|
+
"properties": { "path": { "type": "string", "minLength": 1 } },
|
|
313
|
+
"required": ["path"],
|
|
314
|
+
"additionalProperties": false
|
|
315
|
+
},
|
|
316
|
+
"bindings": [
|
|
317
|
+
{ "to": "/content", "from": "/markdown" },
|
|
318
|
+
{ "to": "/path", "fromContext": "/path" }
|
|
319
|
+
]
|
|
320
|
+
}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
```ts
|
|
324
|
+
const savePage = createSplice(firecrawlCaller, filesystemCaller);
|
|
325
|
+
await savePage({ url, formats: ['markdown'], objective: 'Save this documentation.' }, {
|
|
326
|
+
allowReview: true,
|
|
327
|
+
context: { path: '/application-approved-output/page.md' },
|
|
328
|
+
});
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
Generated adapters require typed `context` options when the plan declares `contextSchema`. The schema must have an object root and follows the same bounded runtime validation rules as endpoint contracts. Invalid context and missing mapped context paths stop before the source call. Context is copied before awaiting tools, isolated between runs, and excluded from caller options; explicitly mapped context fields are sent to the destination. Applications own filesystem permissions and allowed paths; a string schema does not authorize a path. Context bindings require review and all destination arguments remain validated before dispatch.
|
|
332
|
+
|
|
333
|
+
For offline fixtures, pass `--context context.json`, or `splice.mapOutput(savedOutput, { context: { path } })`. Context files are used only with `--fixture`; they are not embedded in generated adapters. A fixture rejected at the context stage creates no adapter.
|
|
334
|
+
|
|
335
|
+
Build contracts in application code directly from catalogs:
|
|
336
|
+
|
|
337
|
+
```ts
|
|
338
|
+
import { createContractFromCatalog } from 'toolsplice';
|
|
339
|
+
const source = createContractFromCatalog(
|
|
340
|
+
{ name: 'firecrawl' }, await firecrawlClient.listTools(),
|
|
341
|
+
{ tools: ['firecrawl_scrape'] },
|
|
342
|
+
);
|
|
343
|
+
```
|
|
344
|
+
|
|
345
|
+
## Expose one tool to an agent
|
|
346
|
+
|
|
347
|
+
The [application-side example](examples/compose-mcp-tool.ts) wraps a generated adapter as an ordinary MCP tool and validates its advertised outer input schema before running the adapter. Applications supply the reviewed input schema, connected callers and any explicit approval for a `review` plan. It forwards cancellation, normalizes progress events from multiple internal calls, and returns only `{ results: [...] }` from the destination.
|
|
348
|
+
|
|
349
|
+
The real-server harness uses this example: one external `save_wiki_outline` tool call performs a DeepWiki read and a filesystem write. Intermediate documentation stays inside the application. This is an optional example, not an automatically installed server or new MCP protocol.
|
|
350
|
+
|
|
351
|
+
## Scope and current limits
|
|
352
|
+
|
|
353
|
+
Static analysis supports a conservative subset of object/array paths, types, enums, presence and bounds. Complex schema relationships require review rather than a claim of compatibility. Runtime guards support bounded structural subsets of explicit Draft 7 and JSON Schema 2020-12; format/content annotations are not enforced, a bounded ASCII regex subset runs through the non-backtracking RE2JS engine, external refs are rejected, and unsupported assertions fail setup. [The reference](docs/LEARNING-AND-STORAGE.md#guard-a-tool-chain-at-runtime) documents dialect, size and resource limits. Plan limits are 1 MiB, 64 non-overlapping bindings and 32 path segments. All mapped arguments together are capped at 5 MiB. Patterns are capped at 1,024 characters and 64 per input/output schema; unsupported regex constructs fail setup.
|
|
354
|
+
|
|
355
|
+
No automatic field matching, numeric/string conversion, semantic ID validation, joins, arbitrary transforms, rollback, distributed execution, sandbox, or Python client is included. Existing file/PostgreSQL learning and contract checks support the adapter workflow; they are not the product's differentiation.
|
|
356
|
+
|
|
357
|
+
## Why this direction
|
|
358
|
+
|
|
359
|
+
[Cloudflare Code Mode](https://developers.cloudflare.com/agents/tools/codemode/) and [Model Context Shell](https://github.com/StacklokLabs/model-context-shell) already compose tools. [SEP-1610](https://github.com/modelcontextprotocol/modelcontextprotocol/issues/1610) proposed declarative MCP chaining with JSON-pointer mapping; it was closed as dormant on June 26, 2026 and was not adopted. Toolsplice uses ordinary MCP calls and does not implement that draft extension. [mcp-contracts](https://github.com/mcp-contracts/mcp-contracts), [Covenant](https://github.com/Mhemd139/Covenant) and [Agothe](https://agothe.ai/mcp-breaking-change-checker/) cover contract snapshots/drift or release checks. Toolsplice concentrates on an explicit **output-to-input handoff**, fixture dry-runs and generated adapters, including undeclared outputs learned from traffic. Related building blocks exist; there is no claim of complete uniqueness.
|
|
360
|
+
|
|
361
|
+
It can prevent demonstrably invalid destination calls and remove repeated parsing/mapping code. Fewer model turns or lower total agent cost remain hypotheses until measured in a real workflow. Learning and checks make no model calls; validation and descriptions also add overhead. Paid model benchmarks remain paused.
|
|
362
|
+
|
|
363
|
+
## Validation
|
|
364
|
+
|
|
365
|
+
```sh
|
|
366
|
+
npm run typecheck
|
|
367
|
+
npm test
|
|
368
|
+
npm run demo
|
|
369
|
+
npm run test:package
|
|
370
|
+
npm run test:real
|
|
371
|
+
```
|
|
372
|
+
|
|
373
|
+
Tests use synthetic data, local MCP servers and disposable reference-server storage. Clean-package checks pack/install locally without publishing. Optional PostgreSQL and longer lifecycle tests are documented in the [reference](docs/LEARNING-AND-STORAGE.md#testing). Historical evidence remains in `docs/VALIDATION.md`, `POSTGRES-VALIDATION.md` and `BINDINGS-VALIDATION.md`; those earlier runs do not prove the new adapter behavior.
|
package/dist/cli.d.ts
ADDED