@goodtiming/baton-sdk 1.0.0 → 1.1.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 +48 -9
- package/dist/index.cjs +541 -271
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -26
- package/dist/index.d.ts +36 -26
- package/dist/index.js +535 -265
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @goodtiming/baton-sdk
|
|
2
2
|
|
|
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/
|
|
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-spec/blob/main/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
|
|
|
@@ -12,7 +12,7 @@ MCP standardizes how agents discover and call your tools. It does not capture *w
|
|
|
12
12
|
npm install @goodtiming/baton-sdk
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
Node 20+. Both major versions of the official MCP TypeScript SDK are supported, and both are **optional** peer dependencies: `@modelcontextprotocol/sdk` **1.
|
|
15
|
+
Node 20+. Both major versions of the official MCP TypeScript SDK are supported, and both are **optional** peer dependencies: `@modelcontextprotocol/sdk` **1.29+** or `@modelcontextprotocol/server` 2.x. You install whichever one your server already uses and nothing else. The 1.x floor is `^1.29.0`; an older 1.x will not satisfy the peer range.
|
|
16
16
|
|
|
17
17
|
## Quickstart
|
|
18
18
|
|
|
@@ -44,6 +44,23 @@ For a hosted server, where the process starts from your own environment, set `BA
|
|
|
44
44
|
|
|
45
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
|
+
## A low-level Server
|
|
48
|
+
|
|
49
|
+
`withBaton` and `createBaton().wrap` also take the official SDK's low-level `Server`, 1.x or 2.x, on which you set the `tools/list` and `tools/call` handlers yourself. Set them before or after `withBaton`.
|
|
50
|
+
|
|
51
|
+
- Baton adds `user_goal` to the tools your `tools/list` handler returns, and the report tool under `reportMode: "on"`. It takes `user_goal` off a call before your handler sees it, and sends the same events as on an `McpServer`.
|
|
52
|
+
- Baton knows your tools from the lists your servers serve; with `createBaton`, what one server served is known to the next. A tool that declares its own `user_goal` keeps it.
|
|
53
|
+
- A tool whose root schema has `$ref`, `oneOf`, `anyOf` or `allOf` gets no `user_goal`. If an agent sends `user_goal` to it anyway, Baton takes it off, unless the schema may take `user_goal` somewhere: as a property or a required name at any depth, or behind a `$ref` to another document. With `createBaton`, once any server has listed a version of the tool that may take it, every server leaves it.
|
|
54
|
+
- A process that has served no list yet does not know your tools, as in a worker that just started. Baton still takes `user_goal` off their calls, because an agent sends it only after Baton listed it, and warns once. A tool that declares its own `user_goal` would lose it there. Pass your tool list as `tools` so every process knows them from its first request:
|
|
55
|
+
|
|
56
|
+
```ts
|
|
57
|
+
withBaton(server, { dsn: process.env.BATON_DSN, tools: TOOLS }); // or tools: () => TOOLS
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Baton reads `tools` once per `withBaton` or `createBaton`, and never calls your `tools/list` handler itself. It also needs `tools` to leave its subagent sentence out of the instructions when a tool declares its own `user_goal`.
|
|
61
|
+
- If your list has a tool with the report tool's name, yours is kept, Baton's report tool is not added, and the instructions stop naming it; the handle's `annotationToolName` still does. Until Baton has seen that list, a call to that name reaches Baton's report tool, so pass `tools` or set `annotationToolName` to another name.
|
|
62
|
+
- Baton has no tool registry to check a call against here, so `failure_kind` is never `unknown_tool`, `invalid_argument` or `output_schema_mismatch`. Such a failure is recorded as an error with no `failure_kind`.
|
|
63
|
+
|
|
47
64
|
## A server per request
|
|
48
65
|
|
|
49
66
|
A stateless HTTP server builds a new `McpServer` for every request. Create one Baton at startup and wrap each server with it:
|
|
@@ -88,6 +105,31 @@ What a stateless server costs, with either function:
|
|
|
88
105
|
Without that header, signals that need several calls in one session, such as a retry loop, do not fire across requests.
|
|
89
106
|
- **The client is named from its `User-Agent`.** A client states its name in the `initialize` handshake, and a per-request server never sees the handshake of the call it is serving. Each event still carries the request's `User-Agent` header in `client_observed`, and your dashboard names the client from that.
|
|
90
107
|
|
|
108
|
+
## Cloudflare Workers
|
|
109
|
+
|
|
110
|
+
Baton runs on Workers with the `nodejs_compat` flag, in a plain `fetch` handler or in a Durable Object such as an `McpAgent` session.
|
|
111
|
+
|
|
112
|
+
- **Call `withBaton` or `createBaton` inside a handler, a Durable Object's constructor or its `init()`, never at module scope.** A Worker refuses timers and random values while its modules load, and Baton needs both.
|
|
113
|
+
- **Baton sends each event as soon as it is written**, with no batching timer, because a Worker may drop a timer its request left behind. In a Durable Object, a send in progress keeps the object alive. In a plain `fetch` handler, hand the send to the runtime so it outlives the response:
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
let baton: Baton | undefined;
|
|
117
|
+
|
|
118
|
+
export default {
|
|
119
|
+
async fetch(request, env, ctx) {
|
|
120
|
+
baton ??= createBaton({ dsn: env.BATON_DSN });
|
|
121
|
+
const server = buildServer();
|
|
122
|
+
baton.wrap(server);
|
|
123
|
+
const response = await handle(server, request);
|
|
124
|
+
ctx.waitUntil(baton.flush());
|
|
125
|
+
return response;
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
- **`settings: "console"` is not supported on Workers yet.** Baton warns once and the capture values in your config apply. The report tool it turns on stays on.
|
|
131
|
+
- **A tool that only computes can show a duration of 0 ms.** A Worker's clock moves only across I/O.
|
|
132
|
+
|
|
91
133
|
## Without MCP: the library API
|
|
92
134
|
|
|
93
135
|
Use `Client` when agents reach you through something other than an MCP server: a REST API, a skill, or a tool loop in your own agent. It sends the same events `withBaton` sends.
|
|
@@ -217,9 +259,7 @@ The SDK reads the settings every 60 seconds, in the background: a read never del
|
|
|
217
259
|
|
|
218
260
|
`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
261
|
|
|
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,
|
|
221
|
-
|
|
222
|
-
These settings, `labels` and `capture` are **experimental** and may change in a minor release.
|
|
262
|
+
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, so the same person always lands in the same group. A caller with no principal is never in a share, even with a company: to target a company, give it a label.
|
|
223
263
|
|
|
224
264
|
## Failures your handler never saw
|
|
225
265
|
|
|
@@ -310,7 +350,6 @@ Checking it worked: `handle.sink` is still an object, so finding one there is no
|
|
|
310
350
|
|
|
311
351
|
None of it blocks the quickstart above.
|
|
312
352
|
|
|
313
|
-
- Only the high-level `McpServer`. The low-level `Server` is not wrapped.
|
|
314
353
|
- **Task-based tools are not wrapped.** 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 advertises `user_goal`, which Baton removes from the call before your handler sees it, wherever it can reach the server's `tools/call` handler. 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`.
|
|
315
354
|
- 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.
|
|
316
355
|
- `resources/templates/list` sends no events.
|
|
@@ -320,7 +359,7 @@ None of it blocks the quickstart above.
|
|
|
320
359
|
|
|
321
360
|
The public API is the exports of `@goodtiming/baton-sdk`, its only entry point.
|
|
322
361
|
|
|
323
|
-
These are **experimental** and may change in a minor release: `
|
|
362
|
+
These are **experimental** and may change in a minor release: `EventSchema`, and `ClientReportEvent` with `ClientReportPayload`. [SPEC §13](https://github.com/good-timing/baton-spec/blob/main/SPEC.md#stability-from-10) lists what is experimental on the wire.
|
|
324
363
|
|
|
325
364
|
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
365
|
|
|
@@ -335,8 +374,8 @@ Keeping that submodule current is load-bearing for contributors: a stale pin mak
|
|
|
335
374
|
| | |
|
|
336
375
|
|---|---|
|
|
337
376
|
| [goodtiming.ai/docs.html#typescript](https://goodtiming.ai/docs.html#typescript) | The docs: configuration, what it captures, the Console |
|
|
338
|
-
| [`
|
|
339
|
-
| [`
|
|
377
|
+
| [`SPEC.md`](https://github.com/good-timing/baton-spec/blob/main/SPEC.md) | The wire protocol, in `baton-spec`. Applies here too |
|
|
378
|
+
| [`baton`'s design rules](https://github.com/good-timing/baton/blob/main/AGENTS.md#design-rules) | Why the SDK is thin. Read before architectural changes |
|
|
340
379
|
| [`CHANGELOG.md`](https://github.com/good-timing/baton-ts/blob/main/CHANGELOG.md) | What has shipped |
|
|
341
380
|
|
|
342
381
|
Apache-2.0.
|