@goodtiming/baton-sdk 0.1.0 → 0.3.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 +20 -2
- package/dist/index.cjs +10 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -4
- package/dist/index.d.ts +20 -4
- package/dist/index.js +10 -8
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
*The TypeScript counterpart to [`baton-sdk`](https://github.com/good-timing/baton) (Python) — structured signal capture for agent-mediated tool use over MCP.*
|
|
4
4
|
|
|
5
|
-
**Status:
|
|
5
|
+
**Status: published — [`@goodtiming/baton-sdk@0.1.0`](https://www.npmjs.com/package/@goodtiming/baton-sdk) on npm.** `withBaton` instruments a high-level `McpServer` — **either** official SDK major, 1.x (`@modelcontextprotocol/sdk`) or v2 (`@modelcontextprotocol/server`): wraps every tool call, injects server `instructions`, registers the `<vendor>_annotate` tool (SPEC §5.1.1–§5.1.2), injects `user_goal`/`expected_result`/`overall_task` intent params on every wrapped tool's schema, captures a `surface_snapshot` of the vendor-true surface, and PII-scrubs every payload with the same default ruleset the Python SDK ships. What's still not here: intent-param injection for **non-zod** schemas on v2, MRTR (Python's `_is_mrtr_pause`/`_is_mrtr_continuation`), and the low-level `Server` adapter — see [What's deferred](#whats-deferred).
|
|
6
6
|
|
|
7
7
|
## Why this exists
|
|
8
8
|
|
|
@@ -32,19 +32,37 @@ The low-level `Server` adapter (only the high-level `McpServer` is supported) is
|
|
|
32
32
|
|
|
33
33
|
## Usage
|
|
34
34
|
|
|
35
|
+
```bash
|
|
36
|
+
npm install @goodtiming/baton-sdk
|
|
37
|
+
```
|
|
38
|
+
|
|
35
39
|
```typescript
|
|
36
40
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
37
41
|
import { withBaton, StdoutSink } from "@goodtiming/baton-sdk";
|
|
38
42
|
|
|
39
43
|
const server = new McpServer({ name: "your-vendor-mcp", version: "1.0.0" });
|
|
40
44
|
const handle = withBaton(server, {
|
|
41
|
-
vendorId: "your-vendor",
|
|
45
|
+
vendorId: "your-vendor", // the SERVER
|
|
46
|
+
tenantId: "ten_7cd4c8cf", // the ACCOUNT — not the same thing
|
|
42
47
|
vendorDisplayName: "Your Vendor",
|
|
43
48
|
consentToken: process.env.BATON_CONSENT_TOKEN!,
|
|
44
49
|
sink: new StdoutSink(), // swap in HttpSink(...) to ship to a collector
|
|
45
50
|
});
|
|
46
51
|
// handle.annotationToolName === "your-vendor_annotate"
|
|
47
52
|
|
|
53
|
+
// `tenantId` names the ACCOUNT the collector authenticates; `vendorId` names
|
|
54
|
+
// the server whose surface is captured. One account wraps many servers, so
|
|
55
|
+
// sending the account id in both slots collapses them into one. Resolved
|
|
56
|
+
// explicit → `BATON_TENANT_ID` → `vendorId`; that last fallback is a
|
|
57
|
+
// migration shim, not a supported configuration.
|
|
58
|
+
//
|
|
59
|
+
// Stated on its own line on purpose — it is the diff your reviewer reads. If
|
|
60
|
+
// you would rather keep it out of source, leave `tenantId` off entirely and
|
|
61
|
+
// set `BATON_TENANT_ID` in the environment; the SDK reads it. Do NOT write
|
|
62
|
+
// `process.env.BATON_TENANT_ID!` — `tenantId` is optional, so the `!` buys no
|
|
63
|
+
// check and an unset variable silently falls back to `vendorId`, which is the
|
|
64
|
+
// collapse described above wearing the look of a configured account.
|
|
65
|
+
|
|
48
66
|
// register tools before or after withBaton — both are captured
|
|
49
67
|
server.registerTool("lookup", { inputSchema: { name: z.string() } }, async ({ name }) => {
|
|
50
68
|
/* ... */
|
package/dist/index.cjs
CHANGED
|
@@ -55,7 +55,7 @@ __export(index_exports, {
|
|
|
55
55
|
module.exports = __toCommonJS(index_exports);
|
|
56
56
|
|
|
57
57
|
// src/version.ts
|
|
58
|
-
var SDK_VERSION = "ts-0.
|
|
58
|
+
var SDK_VERSION = "ts-0.3.0";
|
|
59
59
|
|
|
60
60
|
// src/events.ts
|
|
61
61
|
var import_zod = require("zod");
|
|
@@ -513,11 +513,6 @@ function extraMeta(extra) {
|
|
|
513
513
|
// src/integrations/mcp/runtimeAdapter.ts
|
|
514
514
|
function detectAgentRuntime(meta) {
|
|
515
515
|
if (!meta) return null;
|
|
516
|
-
const batonMeta = meta["baton"];
|
|
517
|
-
if (batonMeta && typeof batonMeta === "object") {
|
|
518
|
-
const runtime = batonMeta["agent_runtime"];
|
|
519
|
-
if (typeof runtime === "string" && runtime) return runtime;
|
|
520
|
-
}
|
|
521
516
|
for (const key of Object.keys(meta)) {
|
|
522
517
|
if (key.startsWith("claudecode/")) return "claude-code";
|
|
523
518
|
}
|
|
@@ -625,6 +620,12 @@ function registerAnnotationTool(server, options) {
|
|
|
625
620
|
// src/integrations/mcp/config.ts
|
|
626
621
|
var VENDOR_ID_PATTERN = /^[a-zA-Z0-9_-]{1,48}$/;
|
|
627
622
|
var INTENT_PARAM_MODES = /* @__PURE__ */ new Set(["optional", "required", "off"]);
|
|
623
|
+
function resolveTenantId(explicit, vendorId) {
|
|
624
|
+
if (explicit) return explicit;
|
|
625
|
+
const fromEnv = typeof process !== "undefined" ? process.env?.BATON_TENANT_ID : void 0;
|
|
626
|
+
if (fromEnv) return fromEnv;
|
|
627
|
+
return vendorId;
|
|
628
|
+
}
|
|
628
629
|
function validateBatonConfig(config) {
|
|
629
630
|
if (!VENDOR_ID_PATTERN.test(config.vendorId)) {
|
|
630
631
|
throw new Error(
|
|
@@ -1170,12 +1171,13 @@ function withBaton(server, config) {
|
|
|
1170
1171
|
const intentParamMode = config.intentParamMode ?? "optional";
|
|
1171
1172
|
const counter = new SessionCounter();
|
|
1172
1173
|
const fallbackSessionId = `sdk-${(0, import_uuid2.v7)()}`;
|
|
1174
|
+
const tenantId = resolveTenantId(config.tenantId, config.vendorId);
|
|
1173
1175
|
const scrubber = config.scrubber ?? new Scrubber().scrub;
|
|
1174
1176
|
const serverMeta = buildServerMeta(server.server);
|
|
1175
1177
|
const surfaceState = new SurfaceState(serverMeta);
|
|
1176
1178
|
const emitSurface = async (sessionId, digest, snapshot) => {
|
|
1177
1179
|
const event = SurfaceSnapshotEventSchema.parse({
|
|
1178
|
-
tenant_id:
|
|
1180
|
+
tenant_id: tenantId,
|
|
1179
1181
|
vendor_id: config.vendorId,
|
|
1180
1182
|
session_id: sessionId,
|
|
1181
1183
|
consent_token: config.consentToken,
|
|
@@ -1223,7 +1225,7 @@ function withBaton(server, config) {
|
|
|
1223
1225
|
const ctx = {
|
|
1224
1226
|
sink,
|
|
1225
1227
|
counter,
|
|
1226
|
-
tenantId
|
|
1228
|
+
tenantId,
|
|
1227
1229
|
vendorId: config.vendorId,
|
|
1228
1230
|
consentToken: config.consentToken,
|
|
1229
1231
|
fallbackSessionId,
|