@goodtiming/baton-sdk 0.6.1 → 0.6.3

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 CHANGED
@@ -42,7 +42,7 @@ With no DSN and no sink, events go to `StdoutSink`, which writes to stderr, so a
42
42
 
43
43
  For a hosted server, where the process starts from your own environment, set `BATON_DSN` and call `withBaton(server)` with no config. An explicit `dsn` wins over `BATON_DSN`, and both win over every other `BATON_*` variable. That ordering matters when you **re-onboard** a server: the new DSN beats the old install's leftover `.env`, rather than filing your events under the previous server's name.
44
44
 
45
- Sending to your own collector instead, or trying the package before you have a key, means naming the parts rather than passing a DSN: [Without a DSN](https://goodtiming.ai/docs.html#without-dsn). That section's examples are Python. The config field names carry over as camelCase, and `HttpSink` takes its options as an object: `new HttpSink(url, { apiKey })`. Its timeouts do **not** carry over. Python's `request_timeout_seconds` / `backoff_base_seconds` / `backoff_max_seconds` / `circuit_breaker_reset_seconds` are `requestTimeoutMs` / `backoffBaseMs` / `backoffMaxMs` / `circuitBreakerResetMs` here, in milliseconds rather than seconds, and there is no equivalent of `shutdown_flush_timeout_seconds`.
45
+ Sending to your own collector instead, or trying the package before you have a key, means naming the parts rather than passing a DSN: [Without a DSN](https://goodtiming.ai/docs.html#without-dsn). That section's examples are Python. The config field names carry over as camelCase, and `HttpSink` takes its options as an object: `new HttpSink(url, { apiKey })`. Its timeouts do **not** carry over. Python's `request_timeout_seconds` / `backoff_base_seconds` / `backoff_max_seconds` / `circuit_breaker_reset_seconds` / `shutdown_flush_timeout_seconds` are `requestTimeoutMs` / `backoffBaseMs` / `backoffMaxMs` / `circuitBreakerResetMs` / `shutdownFlushTimeoutMs` here, in milliseconds rather than seconds.
46
46
 
47
47
  ## A server per request
48
48
 
@@ -60,7 +60,7 @@ app.post("/mcp", async (req, res) => {
60
60
  });
61
61
  ```
62
62
 
63
- Call `await baton.aclose()` in your own shutdown path, after the HTTP server stops taking requests. It sends what is still buffered.
63
+ Call `await baton.aclose()` in your own shutdown path, after the HTTP server stops taking requests. It sends what is still buffered, and returns soon after `shutdownFlushTimeoutMs` (3 seconds by default) even if the collector does not answer.
64
64
 
65
65
  `createBaton` takes the same config as `withBaton`. The Baton owns the sink, so there is nothing to close per request. Calling `withBaton` per request instead builds a new sink each time and re-sends the tool surface on every request.
66
66
 
@@ -107,13 +107,19 @@ app.use((req, res, next) =>
107
107
  );
108
108
  ```
109
109
 
110
- - **`session(options, fn)`** gives every `trace()` and `annotate()` inside `fn` the same session, principal, client and turn, including after `await`. Its options are `sessionId`, `principal`, `clientInfo`, `headers` and `turnId`, all optional. Without a `sessionId` the block makes one up. Pass the same `turnId` to every block that serves one user request.
110
+ - **`session(options, fn)`** gives every `trace()` and `annotate()` inside `fn` the same session, principal, client and turn, including after `await`. Its options are `sessionId`, `principal`, `clientInfo`, `headers`, `turnId` and `meta`, all optional. Without a `sessionId` the block makes one up. Pass the same `turnId` to every block that serves one user request.
111
111
  - **`trace(options, fn)`** runs `fn` as one tool call and returns what it returns. If `fn` returns a promise, the call ends when the promise settles, and `trace()` returns a new native Promise of the same value. Its `then` is called once, so a lazy query builder is not run twice, but its own methods are not on what comes back. A throw or rejection is recorded and passed on unchanged. The options are `toolName`, `intent`, `expectedOutcome`, `workflow`, `params` and `consentToken`. The callback's return value is the recorded result unless `fn` calls `trace.observed(...)`.
112
112
  - **`wrap(toolName, fn)`** returns `fn` traced on every call, for code with no single place to put `trace()`. A single plain-object argument is recorded as `params`.
113
113
  - **`annotate(...)`** and `trace.annotate(...)` send a report your code relays from the agent.
114
114
 
115
115
  `INTENT_PARAMS` holds the name and wording of the one param `withBaton` adds to MCP tools. Use them to ask for the same values in your own API, then pass the answers to `trace()`.
116
116
 
117
+ **Serving MCP yourself**, with a server `withBaton` does not wrap:
118
+
119
+ - **`await listTools(tools, { serverInfo, capabilities, instructions })`** returns your `tools/list` entries with `user_goal` added to each `inputSchema`, exactly as `withBaton` adds it. It also sends a `surface_snapshot` of the tools you passed, once for each distinct surface. Pass your tools before anything else is added to them, and your own `initialize` values. Your list is not changed.
120
+ - **`session({ meta })`** takes the request's `_meta`. It is sent as `runtime_meta`, and a client declaration in it wins over `clientInfo`.
121
+ - **`INTENT_INSTRUCTIONS`** is the sentence to add to your server's instructions.
122
+
117
123
  Capture never throws into your code. Only the constructor throws, on a bad config. Call `await baton.aclose()` at shutdown.
118
124
 
119
125
  ## PII scrubbing
@@ -155,7 +161,7 @@ If you know only the company, for example from an org-wide API key, return `{ or
155
161
 
156
162
  ## Not capturing responses at all
157
163
 
158
- `resultCaptureMode: "off"` and nothing **derived from what your tool returns** leaves your process — not the result, and not the reason text on a failure your handler returns rather than throws. Requests are unaffected: `params` are captured either way.
164
+ `resultCaptureMode: "off"` and nothing **derived from what your tool returns** leaves your process — not the result, and not the reason text on a failure, whether your handler returns it or throws it. Requests are unaffected: `params` are captured either way.
159
165
 
160
166
  ```ts
161
167
  withBaton(server, { dsn, resultCaptureMode: "off" });
@@ -163,7 +169,7 @@ withBaton(server, { dsn, resultCaptureMode: "off" });
163
169
 
164
170
  Each affected event says so, in its own field (`result_capture: "off"`), rather than leaving a reader to guess from what is missing. That is the difference between the two levers: a scrubber TRANSFORMS a value that still crosses the network, this DECLARES that nothing crosses.
165
171
 
166
- **What is still captured, and it is deliberate:** the tool name, the duration, and whether the call failed — so failure detection, pairing and timing all keep working. Also the message of an error your handler **throws**, which is your own code speaking about a call that never returned, and the most useful diagnostic the product has. ⚠ Thrown messages are a classic leak channel — a failed query echoed back, a record id in the message. If that is also a problem for you, say so and we will add a stricter setting.
172
+ **What is still captured, and it is deliberate:** the tool name, the duration, and whether the call failed — so failure detection, pairing and timing all keep working. The message of an error your handler **throws** is withheld too: thrown messages often echo the data a call was handling.
167
173
 
168
174
  **What it costs you:** anything that needs to read a response body. A call that returns `200` with a useless body can no longer be detected, and those calls sit outside the denominator of body-level analysis rather than counting as passes or failures.
169
175
 
@@ -222,9 +228,8 @@ can carry paths, query strings and account identifiers.
222
228
  `resultCaptureMode: "off"` does not withhold it.** These twelve events never
223
229
  carry the `result_capture` marker — the rule is that nothing on them is derived
224
230
  from a result — so a failing read's `error_body` is kept in both modes and the
225
- wire says nothing either way. That is the same leak channel as a thrown tool
226
- error above, with one difference worth your attention: for a tool the marker
227
- tells a consumer what happened, and here there is no marker. If your read fails
231
+ wire says nothing either way. A tool's thrown message is withheld under
232
+ `"off"`; a resource or prompt read's is not, and no marker says so. If your read fails
228
233
  with `could not parse ${body.slice(0, 200)}`, that content leaves your process
229
234
  under a mode you set to stop exactly that. Throw a message that names the
230
235
  resource, not its contents.
@@ -253,11 +258,10 @@ Checking it worked: `handle.sink` is still an object, so finding one there is no
253
258
 
254
259
  None of it blocks the quickstart above.
255
260
 
256
- - Only `StdoutSink` and `HttpSink`. `FileSink` and `MultiSink` are deferred; the Python package has all four.
257
261
  - Only the high-level `McpServer`. The low-level `Server` is not wrapped.
258
262
  - **Task-based tools are not wrapped, and are not left alone either.** A 1.x tool registered with an object at `.handler` rather than a function produces no `tool_call_*` events at all, and nothing reports that. It still gets the intent parameters added to its advertised schema, because injection runs before the wrap is skipped and the strip only happens inside the wrapper. So `user_goal` can arrive in your own handler's arguments. Tools on the same server registered the ordinary way are unaffected. ⚠ **The request-level seam above does not rescue this one**: it reports only on tools this package wrapped, so a task-based tool emits nothing even for a rejected argument, where an unknown tool now emits a `tool_call_error`.
259
263
  - Intent parameters need a Zod schema. On the 2.x SDK a tool registered with a non-Zod standard schema is still wrapped and still emits `tool_call_*`; it just advertises no intent parameters.
260
- - v2's `createMcpHandler` is untested. A server built per request by your own code is supported: see [A server per request](#a-server-per-request).
264
+ - v2's `createMcpHandler` is tested only for calls that pause for input. A server built per request by your own code is supported: see [A server per request](#a-server-per-request).
261
265
 
262
266
  ## Wire compatibility
263
267