@goodtiming/baton-sdk 0.4.1 → 0.5.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/README.md CHANGED
@@ -47,9 +47,108 @@ Sending to your own collector instead, or trying the package before you have a k
47
47
 
48
48
  **It is pattern matching, not a guarantee.** `{"name": "Jane Doe"}` passes through untouched. Decide what your server puts in tool params and results on that basis. [What it does and does not catch](https://goodtiming.ai/docs.html#pii).
49
49
 
50
- ## Turning capture off
50
+ **The scrubber is not the only lever.** If some tool results cannot be recorded at all, `resultCaptureMode` below withholds them outright rather than transforming them.
51
51
 
52
- `BATON_DISABLED=1` in the environment of the process running the server, and the SDK installs nothing at all. The switch belongs to whoever RUNS the server. [The long version](https://goodtiming.ai/docs.html#off-switch).
52
+ ## Who is calling
53
+
54
+ **Nothing is captured about the person behind a call unless you say how to find them.** Pass `resolvePrincipal`: it receives the call's headers, `_meta`, tool name, arguments and validated `authInfo`, and returns a `Principal` or `null`. Two ready-made hooks cover OAuth:
55
+
56
+ ```typescript
57
+ import { withBaton, principalFromOAuthEmail } from "@goodtiming/baton-sdk";
58
+
59
+ withBaton(server, {
60
+ dsn: "https://baton_pk_...@baton.goodtiming.ai/ten_.../your-vendor",
61
+ resolvePrincipal: principalFromOAuthEmail, // or principalFromOAuthSub
62
+ });
63
+ ```
64
+
65
+ `principalFromOAuthEmail` keys on the token's `email` claim (the whole address); `principalFromOAuthSub` on its subject and issuer. Each returns `null` when the claim is missing, so they compose: `(ctx) => principalFromOAuthEmail(ctx) ?? principalFromOAuthSub(ctx)`. Set `displayName` on the returned `Principal` to choose what your dashboard shows for a person; it is sent as-is, even when ids are hashed. The email hook sets it to the part before `@`.
66
+
67
+ ⚠ **They read the claims from `authInfo.extra`.** The MCP SDK's `AuthInfo` has no `claims` field, so these hooks expect your token verifier to put the decoded JWT claims (`sub`, `iss`, `email`) at the top level of `extra`. If yours keeps them elsewhere, write the three-line hook that reads them from there. A token exists only on HTTP with auth configured; on stdio, write a hook that names the user from whatever you authenticated them with.
68
+
69
+ The value is HMAC-hashed in your process before it is sent, keyed with `BATON_PRINCIPAL_ID_HMAC_KEY`; without a key, nothing is attached.
70
+
71
+ ## Not capturing responses at all
72
+
73
+ `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.
74
+
75
+ ```ts
76
+ withBaton(server, { dsn, resultCaptureMode: "off" });
77
+ ```
78
+
79
+ 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.
80
+
81
+ **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.
82
+
83
+ **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.
84
+
85
+ ## Failures your handler never saw
86
+
87
+ A wrapper around your tool executor only sees calls that reach it. Three kinds
88
+ never do — the MCP SDK rejects them above your handler — and a fourth used to be
89
+ recorded as a success:
90
+
91
+ | what happened | what you get |
92
+ |---|---|
93
+ | no tool by that name | `tool_call_error`, `failure_kind: "unknown_tool"` |
94
+ | the tool exists and you disabled it | `tool_call_error`, `failure_kind: "tool_disabled"` |
95
+ | the arguments failed your schema | `tool_call_error`, `failure_kind: "invalid_argument"` |
96
+ | your output schema rejected what the tool returned | `tool_call_error`, `failure_kind: "output_schema_mismatch"` |
97
+
98
+ The first three emitted **nothing at all** before `0.5.0`, and the fourth emitted
99
+ `tool_call_end` — a success, for a call your caller saw fail. `failure_kind` names
100
+ which one it was, so nothing downstream has to pattern-match the message.
101
+
102
+ ⚠ **A tool declaring `execution.taskSupport` gets a `tool_call_error` with NO
103
+ `failure_kind`, and the failures it can hit are not in that table.** On 1.x a
104
+ tool declaring `"required"` or `"optional"` is rejected before argument
105
+ validation if it was not registered as a task tool, and a `"required"` one is
106
+ rejected when called without task augmentation; an `"optional"` task tool called
107
+ without one goes to automatic polling instead, which is not a failure at all.
108
+ This package omits the member for either declared value rather than guessing,
109
+ because it cannot distinguish those rejections from a rejected argument without
110
+ mislabelling every ordinary tool on that peer — 1.x stamps `taskSupport` on all
111
+ of them. The event still carries the SDK's own message. A consumer reading
112
+ `failure_kind` must handle its absence, which SPEC §11.4.3 requires anyway.
113
+
114
+ **Why a separate field and not `error_type`.** `error_type` reports the SHAPE the
115
+ SDK handed us, and the two MCP majors disagree about it for the same failure: 1.x
116
+ converts an unknown tool into a returned error flag (`"tool_error"`), v2 throws
117
+ (`"ProtocolError"`). Both are accurate about what happened at the protocol level,
118
+ and neither tells you a tool was missing. `failure_kind` is the same on both.
119
+
120
+ **`failure_kind` survives `resultCaptureMode: "off"`.** It is this package's
121
+ judgement about the shape of a failure, not anything derived from what your tool
122
+ returned — so for the first three the SDK's own message is kept too, and for the
123
+ fourth the message is withheld and the named kind is the only signal left.
124
+
125
+ ## Resources and prompts
126
+
127
+ `registerResource` and `registerPrompt` are instrumented as well as tools, at the
128
+ request level: `resources/list`, `resources/read`, `prompts/list` and
129
+ `prompts/get` each emit a start and then an end or an error — twelve event types.
130
+
131
+ **No SUCCESSFUL read or get captures a body.** Not a read's content, not a
132
+ prompt's rendered messages. A resource URI and a prompt name ARE captured, and
133
+ both go through the scrubber whole — they are text your caller supplied, so they
134
+ can carry paths, query strings and account identifiers.
135
+
136
+ ⚠ **A FAILING one captures the message your code threw, and
137
+ `resultCaptureMode: "off"` does not withhold it.** These twelve events never
138
+ carry the `result_capture` marker — the rule is that nothing on them is derived
139
+ from a result — so a failing read's `error_body` is kept in both modes and the
140
+ wire says nothing either way. That is the same leak channel as a thrown tool
141
+ error above, with one difference worth your attention: for a tool the marker
142
+ tells a consumer what happened, and here there is no marker. If your read fails
143
+ with `could not parse ${body.slice(0, 200)}`, that content leaves your process
144
+ under a mode you set to stop exactly that. Throw a message that names the
145
+ resource, not its contents.
146
+
147
+ ## Turning capture off entirely
148
+
149
+ 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.
150
+
151
+ `BATON_DISABLED=1` in the environment of the process running the server, and the SDK installs nothing at all. [The long version](https://goodtiming.ai/docs.html#off-switch).
53
152
 
54
153
  Checking it worked: `handle.sink` is still an object, so finding one there is not a sign the switch failed. It is the sink you passed if you passed one, and a `DisabledSink` otherwise. Either way nothing writes to it, because nothing is wrapped.
55
154
 
@@ -59,7 +158,7 @@ None of it blocks the quickstart above.
59
158
 
60
159
  - Only `StdoutSink` and `HttpSink`. `FileSink` and `MultiSink` are deferred; the Python package has all four.
61
160
  - Only the high-level `McpServer`. The low-level `Server` is not wrapped.
62
- - **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`, `expected_result` and `overall_task` can arrive in your own handler's arguments. Tools on the same server registered the ordinary way are unaffected.
161
+ - **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`, `expected_result` and `overall_task` 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`.
63
162
  - 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.
64
163
  - The per-request `createMcpHandler` deployment shape is unscoped.
65
164