@goodtiming/baton-sdk 0.1.0 → 0.2.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 -3
- 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 -3
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
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.2.0";
|
|
59
59
|
|
|
60
60
|
// src/events.ts
|
|
61
61
|
var import_zod = require("zod");
|
|
@@ -625,6 +625,12 @@ function registerAnnotationTool(server, options) {
|
|
|
625
625
|
// src/integrations/mcp/config.ts
|
|
626
626
|
var VENDOR_ID_PATTERN = /^[a-zA-Z0-9_-]{1,48}$/;
|
|
627
627
|
var INTENT_PARAM_MODES = /* @__PURE__ */ new Set(["optional", "required", "off"]);
|
|
628
|
+
function resolveTenantId(explicit, vendorId) {
|
|
629
|
+
if (explicit) return explicit;
|
|
630
|
+
const fromEnv = typeof process !== "undefined" ? process.env?.BATON_TENANT_ID : void 0;
|
|
631
|
+
if (fromEnv) return fromEnv;
|
|
632
|
+
return vendorId;
|
|
633
|
+
}
|
|
628
634
|
function validateBatonConfig(config) {
|
|
629
635
|
if (!VENDOR_ID_PATTERN.test(config.vendorId)) {
|
|
630
636
|
throw new Error(
|
|
@@ -1170,12 +1176,13 @@ function withBaton(server, config) {
|
|
|
1170
1176
|
const intentParamMode = config.intentParamMode ?? "optional";
|
|
1171
1177
|
const counter = new SessionCounter();
|
|
1172
1178
|
const fallbackSessionId = `sdk-${(0, import_uuid2.v7)()}`;
|
|
1179
|
+
const tenantId = resolveTenantId(config.tenantId, config.vendorId);
|
|
1173
1180
|
const scrubber = config.scrubber ?? new Scrubber().scrub;
|
|
1174
1181
|
const serverMeta = buildServerMeta(server.server);
|
|
1175
1182
|
const surfaceState = new SurfaceState(serverMeta);
|
|
1176
1183
|
const emitSurface = async (sessionId, digest, snapshot) => {
|
|
1177
1184
|
const event = SurfaceSnapshotEventSchema.parse({
|
|
1178
|
-
tenant_id:
|
|
1185
|
+
tenant_id: tenantId,
|
|
1179
1186
|
vendor_id: config.vendorId,
|
|
1180
1187
|
session_id: sessionId,
|
|
1181
1188
|
consent_token: config.consentToken,
|
|
@@ -1223,7 +1230,7 @@ function withBaton(server, config) {
|
|
|
1223
1230
|
const ctx = {
|
|
1224
1231
|
sink,
|
|
1225
1232
|
counter,
|
|
1226
|
-
tenantId
|
|
1233
|
+
tenantId,
|
|
1227
1234
|
vendorId: config.vendorId,
|
|
1228
1235
|
consentToken: config.consentToken,
|
|
1229
1236
|
fallbackSessionId,
|