@goodtiming/baton-sdk 0.5.7 → 0.6.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 +15 -4
- package/dist/index.cjs +332 -181
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +289 -23
- package/dist/index.d.ts +289 -23
- package/dist/index.js +331 -181
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -25,7 +25,6 @@ const server = new McpServer({ name: "your-vendor-mcp", version: "1.0.0" });
|
|
|
25
25
|
const handle = withBaton(server, {
|
|
26
26
|
dsn: "https://baton_pk_...@baton.goodtiming.ai/ten_.../your-vendor",
|
|
27
27
|
});
|
|
28
|
-
// handle.annotationToolName === "your-vendor-mcp_annotate", from the server's own name
|
|
29
28
|
|
|
30
29
|
// register tools before or after withBaton; both are captured
|
|
31
30
|
server.registerTool("lookup", { inputSchema: { name: z.string() } }, async ({ name }) => {
|
|
@@ -35,6 +34,10 @@ server.registerTool("lookup", { inputSchema: { name: z.string() } }, async ({ na
|
|
|
35
34
|
|
|
36
35
|
Copy the DSN from **/account**. It packs four values: the collector to send to, your workspace, this server, and the key that binds them. The SDK unpacks them and builds the sink itself.
|
|
37
36
|
|
|
37
|
+
**Installing changes what your server advertises.** Each tool handler is wrapped, one sentence is added below your server's own `instructions`, and a `user_goal` parameter is added to every tool's schema and stripped again before your handler sees it. With `reportMode: "on"`, an annotation tool is also registered, named from your server's own name (slugged, `<server-name>_annotate`, so `your-vendor-mcp_annotate` here), and the added text tells the agent when to report a problem with it. [What gets injected](https://goodtiming.ai/docs.html#injected-tools).
|
|
38
|
+
|
|
39
|
+
With no DSN and no sink, events go to `StdoutSink`, which writes to stderr, so a stdio server's stdout stays clean and nothing goes over the network.
|
|
40
|
+
|
|
38
41
|
**If you distribute your server, put the DSN in your source.** A stdio server runs on your user's machine, spawned by their MCP client. The official client SDKs pass it a fixed six-variable allowlist (`HOME`, `LOGNAME`, `PATH`, `SHELL`, `TERM`, `USER`), plus whatever that user wrote in their own client config. Nothing from your `.env` is in either list, so a server configured that way captures nothing while appearing to work.
|
|
39
42
|
|
|
40
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.
|
|
@@ -109,7 +112,7 @@ app.use((req, res, next) =>
|
|
|
109
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`.
|
|
110
113
|
- **`annotate(...)`** and `trace.annotate(...)` send a report your code relays from the agent.
|
|
111
114
|
|
|
112
|
-
`INTENT_PARAMS` holds the
|
|
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()`.
|
|
113
116
|
|
|
114
117
|
Capture never throws into your code. Only the constructor throws, on a bad config. Call `await baton.aclose()` at shutdown.
|
|
115
118
|
|
|
@@ -123,7 +126,7 @@ Capture never throws into your code. Only the constructor throws, on a bad confi
|
|
|
123
126
|
|
|
124
127
|
## Who is calling
|
|
125
128
|
|
|
126
|
-
**Nothing is captured about the person behind a call unless you say how to find them.** Pass `resolvePrincipal`: it receives the request's headers, `_meta`, tool name, arguments and validated `authInfo`, and returns a `Principal` or `null`. Two ready-made hooks cover OAuth:
|
|
129
|
+
**Nothing is captured about the person behind a call unless you say how to find them.** Pass `resolvePrincipal`: it receives the request's headers, `_meta`, tool name, arguments and validated `authInfo`, and returns a `Principal`, an `Organization` or `null`. Two ready-made hooks cover OAuth:
|
|
127
130
|
|
|
128
131
|
```typescript
|
|
129
132
|
import { withBaton, principalFromOAuthEmail } from "@goodtiming/baton-sdk";
|
|
@@ -142,6 +145,14 @@ The hook runs on every tool call, every `tools/list` request and every resource
|
|
|
142
145
|
|
|
143
146
|
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.
|
|
144
147
|
|
|
148
|
+
If your users belong to your customers' companies, return the company too, so you can filter by it:
|
|
149
|
+
|
|
150
|
+
```ts
|
|
151
|
+
{ principalId: "u_123", organization: { organizationId: "org_acme", displayName: "Acme" } }
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
If you know only the company, for example from an org-wide API key, return `{ organizationId: ... }` alone. A company is never counted as a person. It has its own `form`, so you can hash one id and not the other. The library API takes the same values in `client.session({ principal })`. If you pass only a company there, also pass your own `sessionId`: without a person, Baton cannot join that block's calls to the next one.
|
|
155
|
+
|
|
145
156
|
## Not capturing responses at all
|
|
146
157
|
|
|
147
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.
|
|
@@ -244,7 +255,7 @@ None of it blocks the quickstart above.
|
|
|
244
255
|
|
|
245
256
|
- Only `StdoutSink` and `HttpSink`. `FileSink` and `MultiSink` are deferred; the Python package has all four.
|
|
246
257
|
- Only the high-level `McpServer`. The low-level `Server` is not wrapped.
|
|
247
|
-
- **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
|
|
258
|
+
- **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`.
|
|
248
259
|
- 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.
|
|
249
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).
|
|
250
261
|
|