
Within shows companies that ship MCP tools how AI agents actually use them. I work on both ends: the SDK vendors install, and the data pipeline behind it.
## cut vendor integration from ~58 lines to 6
Integrating tool-call analytics used to take a vendor around 58 lines of wiring. I redesigned the SDK's API around a client + instrument pattern so it comes down to a single call, then built and published it.
1- const queue: ToolEvent[] = [];2-3- function track(tool, args, run) {4- const t0 = Date.now();5- return run().then(6- (res) => record(tool, res, t0),7- (err) => record(tool, err, t0, true),8- );9- }10-11- function record(tool, out, t0, failed) {⋯ 47 more lines: payload shape, redaction, batching, retry/backoff, flush on exit, wrapping every handler…
1+ import { Within } from "…";2+3+ const within = new Within({ apiKey });4+ const server = new McpServer(config);5+6+ within.instrument(server);
simplified sketch of the integration shape, not the published API
## asking agents why they called a tool
Knowing that an agent called a tool is useful; knowing why is better. The SDK injects a required reasonfield into each tool's Zod schema at runtime, captures it as a first-class analytics signal, and strips it before the vendor's code ever sees the call.
- agent calls toolschema now requires `reason`
- SDK interceptsZod schema injected at runtime
- reason → DynamoDBstaged as an analytics signal
- vendor handlerreceives original args, no `reason`
## also
- -Built a vendor-side CRM sync where identifiers are SHA-256 hashed before they ever leave the vendor's infrastructure, landing in S3 as Parquet for the ML training pipeline.
- -Found free-text context fields slipping past PII redaction; closed the gap with inline regex scrubbing and 19 unit tests, then verified it end-to-end against production storage.


