@armature-tech/mcp-analytics 0.6.37 → 0.6.38
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 +27 -8
- package/SKILL.md +1 -1
- package/dist/cjs/doctor.js +8 -4
- package/dist/cjs/fastmcp.js +1 -1
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +2 -1
- package/dist/cjs/mastra.js +5 -3
- package/dist/cjs/redact-secrets.js +5 -0
- package/dist/cjs/request-capability.d.ts +1 -1
- package/dist/cjs/request-capability.js +1 -1
- package/dist/cjs/schema.d.ts +20 -13
- package/dist/cjs/schema.js +156 -41
- package/dist/cjs/server.js +60 -4
- package/dist/cjs/types.d.ts +4 -0
- package/dist/cjs/v2.js +1 -1
- package/dist/esm/doctor.js +8 -4
- package/dist/esm/fastmcp.js +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/mastra.js +5 -3
- package/dist/esm/redact-secrets.js +5 -0
- package/dist/esm/request-capability.d.ts +1 -1
- package/dist/esm/request-capability.js +1 -1
- package/dist/esm/schema.d.ts +20 -13
- package/dist/esm/schema.js +154 -40
- package/dist/esm/server.js +62 -6
- package/dist/esm/types.d.ts +4 -0
- package/dist/esm/v2.js +1 -1
- package/package.json +1 -1
package/dist/esm/server.js
CHANGED
|
@@ -2,12 +2,26 @@ import { AsyncLocalStorage } from "node:async_hooks";
|
|
|
2
2
|
import { randomUUID } from "node:crypto";
|
|
3
3
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
4
|
import { createAnalyticsRecorder } from "./recorder.js";
|
|
5
|
-
import { planToolTelemetry } from "./schema.js";
|
|
5
|
+
import { appendTelemetryHint, planToolTelemetry, withoutRequestCapabilityHint, } from "./schema.js";
|
|
6
6
|
import { defaultMcpAnalyticsConfig } from "./emit.js";
|
|
7
7
|
import { deriveToolResultError, isRecord } from "./utils.js";
|
|
8
|
-
import { isRequestCapabilityEnabled, isRequestCapabilityExplicit } from "./request-capability.js";
|
|
8
|
+
import { isRequestCapabilityEnabled, isRequestCapabilityExplicit, REQUEST_CAPABILITY_TOOL_NAME, } from "./request-capability.js";
|
|
9
9
|
const withAnalyticsStorage = new AsyncLocalStorage();
|
|
10
10
|
let prototypePatchInstalled = false;
|
|
11
|
+
// Servers a tool named request_capability was registered on: the SDK-owned
|
|
12
|
+
// one the recorder attaches, or a customer's own. Only the fallback for an
|
|
13
|
+
// SDK build without the tool registry below.
|
|
14
|
+
const serversListingRequestCapability = new WeakSet();
|
|
15
|
+
// Whether tools/list on `server` currently carries request_capability. Reads
|
|
16
|
+
// the SDK's registry (the same map and `enabled` filter tools/list uses), so
|
|
17
|
+
// a tool removed or disabled after registration no longer counts.
|
|
18
|
+
const listsRequestCapability = (server) => {
|
|
19
|
+
const registry = server._registeredTools;
|
|
20
|
+
if (registry !== null && typeof registry === "object") {
|
|
21
|
+
return registry[REQUEST_CAPABILITY_TOOL_NAME]?.enabled === true;
|
|
22
|
+
}
|
|
23
|
+
return serversListingRequestCapability.has(server);
|
|
24
|
+
};
|
|
11
25
|
// Mirrors the SDK's `isZodTypeLike`/`isZodRawShapeCompat` checks closely enough
|
|
12
26
|
// to disambiguate the overloads of `server.tool(...)`: a raw shape is a plain
|
|
13
27
|
// object whose values include at least one Zod schema, while a Zod schema
|
|
@@ -114,11 +128,16 @@ const installPrototypePatchOnce = () => {
|
|
|
114
128
|
prototype.registerTool = function patchedRegisterTool(name, toolConfig, cb) {
|
|
115
129
|
const ctx = withAnalyticsStorage.getStore();
|
|
116
130
|
if (!ctx) {
|
|
117
|
-
|
|
131
|
+
const registered = originalRegisterTool.call(this, name, toolConfig, cb);
|
|
132
|
+
if (name === REQUEST_CAPABILITY_TOOL_NAME)
|
|
133
|
+
serversListingRequestCapability.add(this);
|
|
134
|
+
return registered;
|
|
118
135
|
}
|
|
119
136
|
const { config } = ctx;
|
|
120
137
|
const originalHasInputSchema = toolConfig.inputSchema !== undefined;
|
|
121
|
-
const plan = planToolTelemetry(name, toolConfig.inputSchema, config
|
|
138
|
+
const plan = planToolTelemetry(name, toolConfig.inputSchema, config, ctx.resolved
|
|
139
|
+
? { requestCapability: listsRequestCapability(this) }
|
|
140
|
+
: {});
|
|
122
141
|
const registeredHasInputSchema = plan.inputSchema !== undefined;
|
|
123
142
|
const description = plan.applyDescription(toolConfig.description);
|
|
124
143
|
const instrumentedConfig = {
|
|
@@ -127,7 +146,21 @@ const installPrototypePatchOnce = () => {
|
|
|
127
146
|
...(registeredHasInputSchema ? { inputSchema: plan.inputSchema } : {}),
|
|
128
147
|
};
|
|
129
148
|
const wrappedCallback = wrapCallbackWithAnalytics(name, cb, originalHasInputSchema, registeredHasInputSchema, plan.mode, ctx);
|
|
130
|
-
|
|
149
|
+
const registered = originalRegisterTool.call(this, name, instrumentedConfig, wrappedCallback);
|
|
150
|
+
if (name === REQUEST_CAPABILITY_TOOL_NAME)
|
|
151
|
+
serversListingRequestCapability.add(this);
|
|
152
|
+
if (!ctx.resolved && plan.mode === "injected" && isRequestCapabilityEnabled(config)) {
|
|
153
|
+
ctx.requestCapabilityHints.push({
|
|
154
|
+
server: this,
|
|
155
|
+
tool: registered,
|
|
156
|
+
toolName: name,
|
|
157
|
+
hintedDescription: description,
|
|
158
|
+
fallbackDescription: appendTelemetryHint(toolConfig.description, {
|
|
159
|
+
toolName: name,
|
|
160
|
+
}),
|
|
161
|
+
});
|
|
162
|
+
}
|
|
163
|
+
return registered;
|
|
131
164
|
};
|
|
132
165
|
// PRIA and other older codebases still use the deprecated `server.tool(...)`
|
|
133
166
|
// overloads. Patch them too — we normalise into our patched `registerTool`
|
|
@@ -151,7 +184,13 @@ const installPrototypePatchOnce = () => {
|
|
|
151
184
|
export const withMcpAnalytics = (config, createServer) => {
|
|
152
185
|
const recorder = createAnalyticsRecorder(config);
|
|
153
186
|
installPrototypePatchOnce();
|
|
154
|
-
const
|
|
187
|
+
const ctx = {
|
|
188
|
+
config,
|
|
189
|
+
recorder,
|
|
190
|
+
resolved: false,
|
|
191
|
+
requestCapabilityHints: [],
|
|
192
|
+
};
|
|
193
|
+
const result = withAnalyticsStorage.run(ctx, createServer);
|
|
155
194
|
// Customer tools registered inside the factory are handled by the
|
|
156
195
|
// prototype patch above. The opt-in SDK-owned tool lives in the recorder's
|
|
157
196
|
// private registry, so attach only after leaving AsyncLocalStorage: this
|
|
@@ -180,6 +219,23 @@ export const withMcpAnalytics = (config, createServer) => {
|
|
|
180
219
|
throw error;
|
|
181
220
|
}
|
|
182
221
|
}
|
|
222
|
+
// Tools registered on a server that does not list request_capability (the
|
|
223
|
+
// factory returned something else, or registered on another server) must
|
|
224
|
+
// not point agents at it.
|
|
225
|
+
ctx.resolved = true;
|
|
226
|
+
for (const hint of ctx.requestCapabilityHints) {
|
|
227
|
+
if (!listsRequestCapability(hint.server)
|
|
228
|
+
&& hint.tool !== null
|
|
229
|
+
&& typeof hint.tool === "object") {
|
|
230
|
+
const tool = hint.tool;
|
|
231
|
+
// Keep a description the factory updated after registration; only its
|
|
232
|
+
// hint changes.
|
|
233
|
+
tool.description = tool.description === hint.hintedDescription
|
|
234
|
+
? hint.fallbackDescription
|
|
235
|
+
: withoutRequestCapabilityHint(tool.description, hint.toolName, hint.hintedDescription);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
ctx.requestCapabilityHints.length = 0;
|
|
183
239
|
return { result, recorder };
|
|
184
240
|
};
|
|
185
241
|
export const createMcpAnalyticsServer = (createServer, config = defaultMcpAnalyticsConfig) => {
|
package/dist/esm/types.d.ts
CHANGED
|
@@ -57,6 +57,8 @@ export type TelemetryFieldMap = {
|
|
|
57
57
|
/** @deprecated `user_turn` is no longer collected; this mapping is ignored. */
|
|
58
58
|
user_turn?: string;
|
|
59
59
|
user_intent?: string;
|
|
60
|
+
call_purpose?: string;
|
|
61
|
+
/** @deprecated Accepted for compatibility. Prefer call_purpose. */
|
|
60
62
|
agent_thinking?: string;
|
|
61
63
|
user_frustration?: string;
|
|
62
64
|
};
|
|
@@ -97,6 +99,8 @@ export type TelemetryArgs = {
|
|
|
97
99
|
/** @deprecated `user_turn` is accepted from cached clients but ignored. */
|
|
98
100
|
user_turn?: number;
|
|
99
101
|
user_intent?: string;
|
|
102
|
+
call_purpose?: string;
|
|
103
|
+
/** @deprecated Accepted for compatibility. Prefer call_purpose. */
|
|
100
104
|
agent_thinking?: string;
|
|
101
105
|
user_frustration?: "low" | "medium" | "high";
|
|
102
106
|
/** @deprecated Pre-V1 spelling of `user_intent`; still accepted. */
|
package/dist/esm/v2.js
CHANGED
|
@@ -413,7 +413,7 @@ const instrumentRegisteredTool = (state, server, name, tool, defaults, options)
|
|
|
413
413
|
? {
|
|
414
414
|
paramsSchema: decoratedSchema,
|
|
415
415
|
// Same idempotent description nudge as v1 (ARM-24).
|
|
416
|
-
description: appendTelemetryHint(registered.description),
|
|
416
|
+
description: appendTelemetryHint(registered.description, { toolName: name }),
|
|
417
417
|
}
|
|
418
418
|
: {}),
|
|
419
419
|
callback: wrapToolCallback(state, name, originalHasInputSchema, registeredHasInputSchema, handler, defaults, options),
|