@goodtiming/baton-sdk 1.0.1 → 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 +43 -2
- package/dist/index.cjs +539 -268
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +29 -10
- package/dist/index.d.ts +29 -10
- package/dist/index.js +533 -262
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -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.
|
|
@@ -308,7 +350,6 @@ Checking it worked: `handle.sink` is still an object, so finding one there is no
|
|
|
308
350
|
|
|
309
351
|
None of it blocks the quickstart above.
|
|
310
352
|
|
|
311
|
-
- Only the high-level `McpServer`. The low-level `Server` is not wrapped.
|
|
312
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`.
|
|
313
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.
|
|
314
355
|
- `resources/templates/list` sends no events.
|