@goodtiming/baton-sdk 0.6.7 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @goodtiming/baton-sdk
2
2
 
3
- **Pre-1.0.** The public API is not yet stable.
3
+ **Stable from 1.0.** This package follows [semver](https://semver.org). [What is public](#what-is-public) lists the public API and what in it is experimental. The wire format only grows: nothing is removed or changes meaning, except what SPEC marks experimental ([SPEC §13](https://github.com/good-timing/baton/blob/main/docs/SPEC.md#stability-from-10)).
4
4
 
5
5
  MCP standardizes how agents discover and call your tools. It does not capture *why* a call happened or whether it helped the user. Baton instruments those interactions on the vendor side by wrapping your MCP server. It captures intent, the tool calls, expected outcomes and observed outcomes, plus friction signals, and hands each one to a sink.
6
6
 
@@ -122,6 +122,26 @@ app.use((req, res, next) =>
122
122
 
123
123
  Capture never throws into your code. Only the constructor throws, on a bad config. Call `await baton.aclose()` at shutdown.
124
124
 
125
+ ### Agent reports on your own API
126
+
127
+ `withBaton` gives agents a report tool, so an agent can tell you when a call went wrong or no tool covers what the user asked. On your own API, offer the same tool with `reportTool`. It has the name, description and input schema `withBaton` registers on a server with that name, so an agent reads the same words.
128
+
129
+ ```ts
130
+ import { reportTool } from "@goodtiming/baton-sdk";
131
+
132
+ const tool = reportTool({ vendorDisplayName: "Acme" });
133
+ // Offer tool.name, tool.description and tool.inputSchema to the agent.
134
+ // Serving MCP yourself? Send tool.instructions in place of INTENT_INSTRUCTIONS.
135
+
136
+ // When the agent calls it:
137
+ const options = tool.annotateArgs(args);
138
+ if (options === null) return { ok: false, error: tool.refusal };
139
+ await baton.annotate(options);
140
+ return { ok: true };
141
+ ```
142
+
143
+ `annotateArgs` returns `null` when the agent sent no `what_happened`. Send `tool.refusal` back and nothing to Baton, because a call with no account is not a report. Call it inside the same `session(...)` block as the calls it is about, or use `await trace.annotate(options)` for one traced call.
144
+
125
145
  ## PII scrubbing
126
146
 
127
147
  **On by default**, a rule-for-rule port of the Python SDK's ruleset: email, `Bearer` values, `sk-*` and `AKIA*` keys, JWTs, phone numbers, Luhn-checked card numbers, plus force-redaction on sensitive field names. Pass `identityScrub` to opt out, or supply your own `(value: unknown) => unknown`.
@@ -151,7 +171,7 @@ The hook runs on every tool call, every `tools/list` request and every resource
151
171
 
152
172
  The id is sent exactly as your hook returns it, so the hook decides what is safe to send. To send a pseudonym instead, hash the id inside your hook and return `form: "hashed"` with it.
153
173
 
154
- If your users belong to your customers' companies, return the company too, so you can filter by it:
174
+ If your users belong to your customers' companies, return the company too. Each event then carries it:
155
175
 
156
176
  ```ts
157
177
  { principalId: "u_123", organization: { organizationId: "org_acme", displayName: "Acme" } }
@@ -171,10 +191,36 @@ Each affected event says so, in its own field (`result_capture: "off"`), rather
171
191
 
172
192
  **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.
173
193
 
174
- **What it does not withhold:** the message of a failed resource or prompt request. `resource_list_error`, `resource_read_error`, `prompt_list_error` and `prompt_get_error` keep it under `"off"`, so `withBaton` and `createBaton` print a warning saying so when you set the mode (see [Resources and prompts](#resources-and-prompts)).
194
+ **What it does not withhold:** the message of a failed tool list, resource or prompt request. `tool_list_error`, `resource_list_error`, `resource_read_error`, `prompt_list_error` and `prompt_get_error` keep it under `"off"`, so `withBaton` and `createBaton` print a warning saying so when you set the mode (see [Tool listings](#tool-listings) and [Resources and prompts](#resources-and-prompts)).
175
195
 
176
196
  **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.
177
197
 
198
+ ## Settings from the Console
199
+
200
+ **Change what is captured without a redeploy.** With `settings: "console"`, the SDK reads the settings saved on the Console's Capture page, and each caller gets the settings of the first audience that matches it. An audience can match on the caller's labels, the app it runs in (such as `claude-code`), a share of your callers, or several of these, and then all of them must match.
201
+
202
+ ```ts
203
+ withBaton(server, { dsn, settings: "console" });
204
+ ```
205
+
206
+ On a hosted server, `BATON_DSN` in the environment works here too. Pass `{ settings: "console" }` without a `dsn`. There is no environment variable for `settings` itself, so turning it on is a change to your code.
207
+
208
+ Three things can differ by audience.
209
+
210
+ | Setting | What it changes | When it applies |
211
+ |---|---|---|
212
+ | `results` | Whether results and error messages are sent, as `resultCaptureMode` does | The next call |
213
+ | `goal` | Whether the `user_goal` Baton adds is required or optional. A tool that declares its own `user_goal` keeps it as it is. | The next `tools/list` |
214
+ | `reports` | Whether the caller sees the report tool. A report from a caller with reports off, such as one from an older tool list, is still recorded. | The next `tools/list` |
215
+
216
+ The SDK reads the settings every 60 seconds, in the background: a read never delays startup or a call. Set `settingsRefreshMs` to change that, down to 15000. Until the first read succeeds, and while nothing is saved, the values in your config apply. Once settings are read, each event says which ones it ran under, in `capture`. One `createBaton` reads them once for every server it wraps.
217
+
218
+ `reportMode` is `"on"` by default here, so the Console decides who sees the report tool. Set `reportMode: "off"` to keep it off for everyone. The report sentence in your server's instructions stays while any audience has reports on. A client reads the instructions when it connects, so a change reaches new connections only.
219
+
220
+ Labels come from your `resolvePrincipal` hook, as `labels` on the `Principal` or the `Organization` it returns. Up to 20 per caller, sent on every event, so send only names you are happy for Baton to see. A share of callers is picked by the principal's id, or the company's when there is no principal, so the same person always lands in the same group. A caller with neither is never in a share.
221
+
222
+ These settings, `labels` and `capture` are **experimental** and may change in a minor release.
223
+
178
224
  ## Failures your handler never saw
179
225
 
180
226
  A wrapper around your tool executor only sees calls that reach it. Three kinds
@@ -248,6 +294,10 @@ that response held and how long it took. No tool name, description or schema
248
294
  is on these events. They carry the principal your `resolvePrincipal` hook
249
295
  returns ([Who is calling](#who-is-calling)).
250
296
 
297
+ A failed listing's `tool_list_error` carries the message that was thrown, and
298
+ `resultCaptureMode: "off"` does not withhold it. That message can be your own
299
+ text, from a `tools/list` handler you set on the server.
300
+
251
301
  ## Turning capture off entirely
252
302
 
253
303
  Not the same thing as **Not capturing responses at all**: that one keeps the signal and drops the response bodies, this one emits nothing at all. It also belongs to a different person — `resultCaptureMode` is set by whoever WRAPS the server, in code; this is set by whoever RUNS it, in the environment.
@@ -266,6 +316,14 @@ None of it blocks the quickstart above.
266
316
  - `resources/templates/list` sends no events.
267
317
  - 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).
268
318
 
319
+ ## What is public
320
+
321
+ The public API is the exports of `@goodtiming/baton-sdk`, its only entry point.
322
+
323
+ These are **experimental** and may change in a minor release: `settings` and `settingsRefreshMs`, `labels` on `Principal` and `Organization`, the events' `labels` and `capture` with the `CaptureObserved` type, `EventSchema`, and `ClientReportEvent` with `ClientReportPayload`. [SPEC §13](https://github.com/good-timing/baton/blob/main/docs/SPEC.md#stability-from-10) lists what is experimental on the wire.
324
+
325
+ The event types are built with zod. `EventSchema` may change with a zod major; the event types may not, so 1.x moves to a new zod major only if they stay the same.
326
+
269
327
  ## Wire compatibility
270
328
 
271
329
  Events from this package must be JSON-identical in shape to the Python SDK's, so a collector never branches on which SDK produced one. Both are checked against [baton-spec](https://github.com/good-timing/baton-spec), a neutral schema repo: every event type is validated against the shared JSON Schema, and this package's emitter is diffed field-by-field against captured Python output for the same scenario.