qyl-mcp-server 0.1.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.
Files changed (77) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -0
  3. package/dist/atomic-json-store.d.ts +37 -0
  4. package/dist/atomic-json-store.js +143 -0
  5. package/dist/atomic-json-store.js.map +1 -0
  6. package/dist/ci.d.ts +51 -0
  7. package/dist/ci.js +158 -0
  8. package/dist/ci.js.map +1 -0
  9. package/dist/collector.d.ts +43 -0
  10. package/dist/collector.js +163 -0
  11. package/dist/collector.js.map +1 -0
  12. package/dist/config.d.ts +14 -0
  13. package/dist/config.js +39 -0
  14. package/dist/config.js.map +1 -0
  15. package/dist/contract-validation.d.ts +146 -0
  16. package/dist/contract-validation.js +350 -0
  17. package/dist/contract-validation.js.map +1 -0
  18. package/dist/data.d.ts +46 -0
  19. package/dist/data.js +138 -0
  20. package/dist/data.js.map +1 -0
  21. package/dist/demo.d.ts +23 -0
  22. package/dist/demo.js +836 -0
  23. package/dist/demo.js.map +1 -0
  24. package/dist/execution-evidence.d.ts +13 -0
  25. package/dist/execution-evidence.js +81 -0
  26. package/dist/execution-evidence.js.map +1 -0
  27. package/dist/execution-result.d.ts +5 -0
  28. package/dist/execution-result.js +17 -0
  29. package/dist/execution-result.js.map +1 -0
  30. package/dist/http-security.d.ts +36 -0
  31. package/dist/http-security.js +101 -0
  32. package/dist/http-security.js.map +1 -0
  33. package/dist/log-body.d.ts +3 -0
  34. package/dist/log-body.js +12 -0
  35. package/dist/log-body.js.map +1 -0
  36. package/dist/main.d.ts +51 -0
  37. package/dist/main.js +215 -0
  38. package/dist/main.js.map +1 -0
  39. package/dist/mcp-app.html +218 -0
  40. package/dist/mcp-dashboard.html +223 -0
  41. package/dist/mcp-errors.d.ts +5 -0
  42. package/dist/mcp-errors.js +15 -0
  43. package/dist/mcp-errors.js.map +1 -0
  44. package/dist/mcp-semconv.d.ts +68 -0
  45. package/dist/mcp-semconv.js +208 -0
  46. package/dist/mcp-semconv.js.map +1 -0
  47. package/dist/native-execution.d.ts +132 -0
  48. package/dist/native-execution.js +508 -0
  49. package/dist/native-execution.js.map +1 -0
  50. package/dist/observability-suppression.d.ts +8 -0
  51. package/dist/observability-suppression.js +15 -0
  52. package/dist/observability-suppression.js.map +1 -0
  53. package/dist/secret-redactor.d.ts +30 -0
  54. package/dist/secret-redactor.js +255 -0
  55. package/dist/secret-redactor.js.map +1 -0
  56. package/dist/server.d.ts +25 -0
  57. package/dist/server.js +207 -0
  58. package/dist/server.js.map +1 -0
  59. package/dist/stats.d.ts +18 -0
  60. package/dist/stats.js +141 -0
  61. package/dist/stats.js.map +1 -0
  62. package/dist/summaries.d.ts +14 -0
  63. package/dist/summaries.js +128 -0
  64. package/dist/summaries.js.map +1 -0
  65. package/dist/telemetry-redaction.d.ts +6 -0
  66. package/dist/telemetry-redaction.js +28 -0
  67. package/dist/telemetry-redaction.js.map +1 -0
  68. package/dist/telemetry.d.ts +72 -0
  69. package/dist/telemetry.js +362 -0
  70. package/dist/telemetry.js.map +1 -0
  71. package/dist/tools.d.ts +17 -0
  72. package/dist/tools.js +111 -0
  73. package/dist/tools.js.map +1 -0
  74. package/dist/wire.d.ts +10 -0
  75. package/dist/wire.js +7 -0
  76. package/dist/wire.js.map +1 -0
  77. package/package.json +91 -0
@@ -0,0 +1,5 @@
1
+ import { ErrorCode, type JSONRPCErrorResponse, type RequestId } from "@modelcontextprotocol/sdk/types.js";
2
+ /** Build a protocol error through the MCP SDK's normative runtime schema. */
3
+ export declare function mcpErrorResponse(code: ErrorCode, message: string, id?: RequestId): JSONRPCErrorResponse;
4
+ /** Preserve an ID only when the request itself is a valid SDK-owned envelope. */
5
+ export declare function mcpRequestId(value: unknown): RequestId | undefined;
@@ -0,0 +1,15 @@
1
+ import { JSONRPCErrorResponseSchema, JSONRPCRequestSchema, JSONRPC_VERSION, } from "@modelcontextprotocol/sdk/types.js";
2
+ /** Build a protocol error through the MCP SDK's normative runtime schema. */
3
+ export function mcpErrorResponse(code, message, id) {
4
+ return JSONRPCErrorResponseSchema.parse({
5
+ jsonrpc: JSONRPC_VERSION,
6
+ error: { code, message },
7
+ ...(id === undefined ? {} : { id }),
8
+ });
9
+ }
10
+ /** Preserve an ID only when the request itself is a valid SDK-owned envelope. */
11
+ export function mcpRequestId(value) {
12
+ const parsed = JSONRPCRequestSchema.safeParse(value);
13
+ return parsed.success ? parsed.data.id : undefined;
14
+ }
15
+ //# sourceMappingURL=mcp-errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-errors.js","sourceRoot":"","sources":["../src/mcp-errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,0BAA0B,EAC1B,oBAAoB,EACpB,eAAe,GAGhB,MAAM,oCAAoC,CAAC;AAE5C,6EAA6E;AAC7E,MAAM,UAAU,gBAAgB,CAC9B,IAAe,EACf,OAAe,EACf,EAAc;IAEd,OAAO,0BAA0B,CAAC,KAAK,CAAC;QACtC,OAAO,EAAE,eAAe;QACxB,KAAK,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;QACxB,GAAG,CAAC,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC;KACpC,CAAC,CAAC;AACL,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,YAAY,CAAC,KAAc;IACzC,MAAM,MAAM,GAAG,oBAAoB,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;IACrD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC"}
@@ -0,0 +1,68 @@
1
+ import { SpanKind, type Attributes } from "@opentelemetry/api";
2
+ import { SecretRedactor } from "./secret-redactor.js";
3
+ export declare const MCP_WELL_KNOWN_METHODS: readonly ["initialize", "notifications/initialized", "ping", "notifications/cancelled", "notifications/progress", "resources/list", "resources/templates/list", "resources/read", "resources/subscribe", "resources/unsubscribe", "notifications/resources/list_changed", "notifications/resources/updated", "prompts/list", "prompts/get", "notifications/prompts/list_changed", "tools/list", "tools/call", "notifications/tools/list_changed", "roots/list", "notifications/roots/list_changed", "logging/setLevel", "notifications/message", "sampling/createMessage", "completion/complete", "elicitation/create"];
4
+ export type McpTelemetryRole = "client" | "server";
5
+ export type McpTelemetryTransport = "stdio" | "http" | "streamable_http" | "streamable-http" | "sse" | "inproc" | "builtin";
6
+ /** Propagation-only MCP metadata. Values are never emitted as attributes. */
7
+ export type McpPropagationCarrier = Readonly<Record<string, string>>;
8
+ interface McpNetworkInput {
9
+ role: McpTelemetryRole;
10
+ transport: McpTelemetryTransport;
11
+ networkProtocolName?: string;
12
+ networkProtocolVersion?: string;
13
+ /** Remote server for client signals; remote client for server spans. */
14
+ peerAddress?: string;
15
+ peerPort?: number;
16
+ }
17
+ interface McpProtocolInput extends McpNetworkInput {
18
+ protocolVersion?: string;
19
+ jsonRpcProtocolVersion?: string;
20
+ errorType?: string;
21
+ rpcResponseStatusCode?: string;
22
+ }
23
+ export interface McpOperationInput extends McpProtocolInput {
24
+ method: string;
25
+ toolName?: string;
26
+ promptName?: string;
27
+ resourceUri?: string;
28
+ /** `mcp.resource.uri` is opt-in on operation metrics. */
29
+ recordResourceUriOnMetric?: boolean;
30
+ mcpSessionId?: string;
31
+ jsonRpcRequestId?: string | number;
32
+ serverId?: string;
33
+ executionId?: string;
34
+ evaluationRunId?: string;
35
+ testCaseId?: string;
36
+ startTimeMs: number;
37
+ endTimeMs: number;
38
+ /** Remote propagation extracted from MCP params._meta; never emitted as attributes. */
39
+ remotePropagation?: McpPropagationCarrier;
40
+ }
41
+ export interface McpSessionInput extends McpProtocolInput {
42
+ startTimeMs: number;
43
+ endTimeMs: number;
44
+ }
45
+ export interface McpSpanDescriptor {
46
+ name: string;
47
+ kind: SpanKind.CLIENT | SpanKind.SERVER;
48
+ attributes: Attributes;
49
+ }
50
+ export interface McpMetricDescriptor {
51
+ name: string;
52
+ unit: "s";
53
+ value: number;
54
+ attributes: Attributes;
55
+ }
56
+ export declare const WorkbenchTelemetryAttributes: {
57
+ readonly executionId: "qyl.mcp.execution.id";
58
+ readonly evaluationRunId: "qyl.mcp.evaluation_run.id";
59
+ readonly testCaseId: "qyl.mcp.test_case.id";
60
+ readonly serverId: "qyl.mcp.server.id";
61
+ };
62
+ /** Build only attributes defined for the pinned `mcp.client`/`mcp.server` span. */
63
+ export declare function describeMcpOperationSpan(input: McpOperationInput, redactor?: SecretRedactor): McpSpanDescriptor;
64
+ /** Build only attributes defined for the pinned operation-duration histogram. */
65
+ export declare function describeMcpOperationMetric(input: McpOperationInput, redactor?: SecretRedactor): McpMetricDescriptor;
66
+ /** Build only attributes defined for the pinned session-duration histogram. */
67
+ export declare function describeMcpSessionMetric(input: McpSessionInput, redactor?: SecretRedactor): McpMetricDescriptor;
68
+ export {};
@@ -0,0 +1,208 @@
1
+ import { SpanKind } from "@opentelemetry/api";
2
+ import { ATTR_CLIENT_ADDRESS, ATTR_CLIENT_PORT, ATTR_ERROR_TYPE, ATTR_NETWORK_PROTOCOL_NAME, ATTR_NETWORK_PROTOCOL_VERSION, ATTR_NETWORK_TRANSPORT, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, NETWORK_TRANSPORT_VALUE_PIPE, NETWORK_TRANSPORT_VALUE_TCP, } from "@opentelemetry/semantic-conventions";
3
+ import { ATTR_GEN_AI_OPERATION_NAME, ATTR_GEN_AI_PROMPT_NAME, ATTR_GEN_AI_TOOL_NAME, ATTR_JSONRPC_PROTOCOL_VERSION, ATTR_JSONRPC_REQUEST_ID, ATTR_MCP_METHOD_NAME, ATTR_MCP_PROTOCOL_VERSION, ATTR_MCP_RESOURCE_URI, ATTR_MCP_SESSION_ID, ATTR_RPC_RESPONSE_STATUS_CODE, GEN_AI_OPERATION_NAME_VALUE_EXECUTE_TOOL, METRIC_MCP_CLIENT_OPERATION_DURATION, METRIC_MCP_CLIENT_SESSION_DURATION, METRIC_MCP_SERVER_OPERATION_DURATION, METRIC_MCP_SERVER_SESSION_DURATION, } from "@opentelemetry/semantic-conventions/incubating";
4
+ import { SecretRedactor } from "./secret-redactor.js";
5
+ const ATTRIBUTE_VALUE_LIMIT = 2_000;
6
+ const JSONRPC_DEFAULT_VERSION = "2.0";
7
+ export const MCP_WELL_KNOWN_METHODS = [
8
+ "initialize",
9
+ "notifications/initialized",
10
+ "ping",
11
+ "notifications/cancelled",
12
+ "notifications/progress",
13
+ "resources/list",
14
+ "resources/templates/list",
15
+ "resources/read",
16
+ "resources/subscribe",
17
+ "resources/unsubscribe",
18
+ "notifications/resources/list_changed",
19
+ "notifications/resources/updated",
20
+ "prompts/list",
21
+ "prompts/get",
22
+ "notifications/prompts/list_changed",
23
+ "tools/list",
24
+ "tools/call",
25
+ "notifications/tools/list_changed",
26
+ "roots/list",
27
+ "notifications/roots/list_changed",
28
+ "logging/setLevel",
29
+ "notifications/message",
30
+ "sampling/createMessage",
31
+ "completion/complete",
32
+ "elicitation/create",
33
+ ];
34
+ export const WorkbenchTelemetryAttributes = {
35
+ executionId: "qyl.mcp.execution.id",
36
+ evaluationRunId: "qyl.mcp.evaluation_run.id",
37
+ testCaseId: "qyl.mcp.test_case.id",
38
+ serverId: "qyl.mcp.server.id",
39
+ };
40
+ /** Build only attributes defined for the pinned `mcp.client`/`mcp.server` span. */
41
+ export function describeMcpOperationSpan(input, redactor = new SecretRedactor()) {
42
+ validateTiming(input.startTimeMs, input.endTimeMs);
43
+ const safe = safeText(redactor);
44
+ const method = requireText(input.method, "method", safe);
45
+ const attributes = { [ATTR_MCP_METHOD_NAME]: method };
46
+ addOperationCommon(attributes, input, safe, true);
47
+ if (input.mcpSessionId)
48
+ attributes[ATTR_MCP_SESSION_ID] = safe(input.mcpSessionId);
49
+ if (input.jsonRpcRequestId !== undefined) {
50
+ attributes[ATTR_JSONRPC_REQUEST_ID] = safe(String(input.jsonRpcRequestId));
51
+ }
52
+ if (input.resourceUri && resourceMethodHasUri(input.method)) {
53
+ attributes[ATTR_MCP_RESOURCE_URI] = bounded(redactor.redactUri(input.resourceUri));
54
+ }
55
+ addPeerAttributes(attributes, input, safe, true);
56
+ addWorkbenchSpanAttributes(attributes, input, safe);
57
+ const target = input.method === "tools/call"
58
+ ? input.toolName
59
+ : input.method === "prompts/get" ? input.promptName : undefined;
60
+ return {
61
+ name: target ? `${method} ${safe(target)}` : method,
62
+ kind: input.role === "client" ? SpanKind.CLIENT : SpanKind.SERVER,
63
+ attributes,
64
+ };
65
+ }
66
+ /** Build only attributes defined for the pinned operation-duration histogram. */
67
+ export function describeMcpOperationMetric(input, redactor = new SecretRedactor()) {
68
+ validateTiming(input.startTimeMs, input.endTimeMs);
69
+ const safe = safeText(redactor);
70
+ const attributes = {
71
+ [ATTR_MCP_METHOD_NAME]: requireText(input.method, "method", safe),
72
+ };
73
+ addOperationCommon(attributes, input, safe, false);
74
+ if (input.recordResourceUriOnMetric && input.resourceUri && resourceMethodHasUri(input.method)) {
75
+ attributes[ATTR_MCP_RESOURCE_URI] = bounded(redactor.redactUri(input.resourceUri));
76
+ }
77
+ addPeerAttributes(attributes, input, safe, false);
78
+ return {
79
+ name: input.role === "client"
80
+ ? METRIC_MCP_CLIENT_OPERATION_DURATION
81
+ : METRIC_MCP_SERVER_OPERATION_DURATION,
82
+ unit: "s",
83
+ value: durationSeconds(input.startTimeMs, input.endTimeMs),
84
+ attributes,
85
+ };
86
+ }
87
+ /** Build only attributes defined for the pinned session-duration histogram. */
88
+ export function describeMcpSessionMetric(input, redactor = new SecretRedactor()) {
89
+ validateTiming(input.startTimeMs, input.endTimeMs);
90
+ const safe = safeText(redactor);
91
+ const attributes = {};
92
+ // rpc.response.status_code is defined for MCP operations, not sessions.
93
+ addProtocolAndNetwork(attributes, input, safe, false);
94
+ addPeerAttributes(attributes, input, safe, false);
95
+ return {
96
+ name: input.role === "client"
97
+ ? METRIC_MCP_CLIENT_SESSION_DURATION
98
+ : METRIC_MCP_SERVER_SESSION_DURATION,
99
+ unit: "s",
100
+ value: durationSeconds(input.startTimeMs, input.endTimeMs),
101
+ attributes,
102
+ };
103
+ }
104
+ function addOperationCommon(attributes, input, safe, span) {
105
+ addProtocolAndNetwork(attributes, input, safe);
106
+ if (input.method === "tools/call") {
107
+ attributes[ATTR_GEN_AI_OPERATION_NAME] = GEN_AI_OPERATION_NAME_VALUE_EXECUTE_TOOL;
108
+ }
109
+ if (input.method === "tools/call" && input.toolName) {
110
+ attributes[ATTR_GEN_AI_TOOL_NAME] = safe(input.toolName);
111
+ }
112
+ if (input.method === "prompts/get" && input.promptName) {
113
+ attributes[ATTR_GEN_AI_PROMPT_NAME] = safe(input.promptName);
114
+ }
115
+ // Arguments/results/prompt variables are deliberately not captured: those
116
+ // registry attributes are opt-in and may contain credentials or user data.
117
+ if (!span)
118
+ return;
119
+ }
120
+ function addProtocolAndNetwork(attributes, input, safe, includeRpcResponseStatusCode = true) {
121
+ if (input.errorType)
122
+ attributes[ATTR_ERROR_TYPE] = safe(input.errorType);
123
+ if (input.protocolVersion)
124
+ attributes[ATTR_MCP_PROTOCOL_VERSION] = safe(input.protocolVersion);
125
+ if (input.jsonRpcProtocolVersion && input.jsonRpcProtocolVersion !== JSONRPC_DEFAULT_VERSION) {
126
+ attributes[ATTR_JSONRPC_PROTOCOL_VERSION] = safe(input.jsonRpcProtocolVersion);
127
+ }
128
+ if (includeRpcResponseStatusCode && input.rpcResponseStatusCode) {
129
+ attributes[ATTR_RPC_RESPONSE_STATUS_CODE] = safe(input.rpcResponseStatusCode);
130
+ }
131
+ const transport = networkTransport(input.transport);
132
+ if (transport)
133
+ attributes[ATTR_NETWORK_TRANSPORT] = transport;
134
+ const protocolName = input.networkProtocolName ?? inferredNetworkProtocol(input.transport);
135
+ if (protocolName)
136
+ attributes[ATTR_NETWORK_PROTOCOL_NAME] = safe(protocolName);
137
+ if (input.networkProtocolVersion) {
138
+ attributes[ATTR_NETWORK_PROTOCOL_VERSION] = safe(input.networkProtocolVersion);
139
+ }
140
+ }
141
+ function addPeerAttributes(attributes, input, safe, span) {
142
+ if (input.role === "client") {
143
+ if (input.peerAddress)
144
+ attributes[ATTR_SERVER_ADDRESS] = safe(input.peerAddress);
145
+ if (input.peerAddress && input.peerPort !== undefined)
146
+ attributes[ATTR_SERVER_PORT] = input.peerPort;
147
+ return;
148
+ }
149
+ // Server metrics do not define client.address/client.port; server spans do.
150
+ if (span && input.peerAddress)
151
+ attributes[ATTR_CLIENT_ADDRESS] = safe(input.peerAddress);
152
+ if (span && input.peerAddress && input.peerPort !== undefined)
153
+ attributes[ATTR_CLIENT_PORT] = input.peerPort;
154
+ }
155
+ function addWorkbenchSpanAttributes(attributes, input, safe) {
156
+ if (input.serverId)
157
+ attributes[WorkbenchTelemetryAttributes.serverId] = safe(input.serverId);
158
+ if (input.executionId)
159
+ attributes[WorkbenchTelemetryAttributes.executionId] = safe(input.executionId);
160
+ if (input.evaluationRunId) {
161
+ attributes[WorkbenchTelemetryAttributes.evaluationRunId] = safe(input.evaluationRunId);
162
+ }
163
+ if (input.testCaseId)
164
+ attributes[WorkbenchTelemetryAttributes.testCaseId] = safe(input.testCaseId);
165
+ }
166
+ function resourceMethodHasUri(method) {
167
+ return method === "resources/read"
168
+ || method === "resources/subscribe"
169
+ || method === "resources/unsubscribe"
170
+ || method === "notifications/resources/updated";
171
+ }
172
+ function networkTransport(transport) {
173
+ if (transport === "stdio")
174
+ return NETWORK_TRANSPORT_VALUE_PIPE;
175
+ if (transport === "http" || transport === "streamable_http"
176
+ || transport === "streamable-http" || transport === "sse") {
177
+ return NETWORK_TRANSPORT_VALUE_TCP;
178
+ }
179
+ return undefined;
180
+ }
181
+ function inferredNetworkProtocol(transport) {
182
+ return transport === "http" || transport === "streamable_http"
183
+ || transport === "streamable-http" || transport === "sse"
184
+ ? "http"
185
+ : undefined;
186
+ }
187
+ function safeText(redactor) {
188
+ return (value) => bounded(redactor.redactText(value));
189
+ }
190
+ function requireText(value, name, safe) {
191
+ if (value.trim().length === 0)
192
+ throw new Error(`${name} must not be empty.`);
193
+ return safe(value);
194
+ }
195
+ function bounded(value) {
196
+ return value.length <= ATTRIBUTE_VALUE_LIMIT
197
+ ? value
198
+ : `${value.slice(0, ATTRIBUTE_VALUE_LIMIT - 1)}…`;
199
+ }
200
+ function validateTiming(startTimeMs, endTimeMs) {
201
+ if (!Number.isFinite(startTimeMs) || !Number.isFinite(endTimeMs) || endTimeMs < startTimeMs) {
202
+ throw new Error("MCP telemetry timestamps must be finite and ordered.");
203
+ }
204
+ }
205
+ function durationSeconds(startTimeMs, endTimeMs) {
206
+ return (endTimeMs - startTimeMs) / 1_000;
207
+ }
208
+ //# sourceMappingURL=mcp-semconv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-semconv.js","sourceRoot":"","sources":["../src/mcp-semconv.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAmB,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EACH,mBAAmB,EACnB,gBAAgB,EAChB,eAAe,EACf,0BAA0B,EAC1B,6BAA6B,EAC7B,sBAAsB,EACtB,mBAAmB,EACnB,gBAAgB,EAChB,4BAA4B,EAC5B,2BAA2B,GAC9B,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EACH,0BAA0B,EAC1B,uBAAuB,EACvB,qBAAqB,EACrB,6BAA6B,EAC7B,uBAAuB,EACvB,oBAAoB,EACpB,yBAAyB,EACzB,qBAAqB,EACrB,mBAAmB,EACnB,6BAA6B,EAC7B,wCAAwC,EACxC,oCAAoC,EACpC,kCAAkC,EAClC,oCAAoC,EACpC,kCAAkC,GACrC,MAAM,gDAAgD,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,MAAM,qBAAqB,GAAG,KAAK,CAAC;AACpC,MAAM,uBAAuB,GAAG,KAAK,CAAC;AAEtC,MAAM,CAAC,MAAM,sBAAsB,GAAG;IAClC,YAAY;IACZ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KAAK;QACzD,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,SAAS,CAAC;AACpB,CAAC;AAED,SAAS,QAAQ,CAAC,QAAwB;IACtC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC;AAC1D,CAAC;AAED,SAAS,WAAW,CAAC,KAAa,EAAE,IAAY,EAAE,IAA+B;IAC7E,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,GAAG,IAAI,qBAAqB,CAAC,CAAC;IAC7E,OAAO,IAAI,CAAC,KAAK,CAAC,CAAC;AACvB,CAAC;AAED,SAAS,OAAO,CAAC,KAAa;IAC1B,OAAO,KAAK,CAAC,MAAM,IAAI,qBAAqB;QACxC,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,qBAAqB,GAAG,CAAC,CAAC,GAAG,CAAC;AAC1D,CAAC;AAED,SAAS,cAAc,CAAC,WAAmB,EAAE,SAAiB;IAC1D,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,WAAW,EAAE,CAAC;QAC1F,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;IAC5E,CAAC;AACL,CAAC;AAED,SAAS,eAAe,CAAC,WAAmB,EAAE,SAAiB;IAC3D,OAAO,CAAC,SAAS,GAAG,WAAW,CAAC,GAAG,KAAK,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,132 @@
1
+ import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
3
+ import { type CallToolRequest, type CallToolResult, type ServerNotification, type ServerRequest } from "@modelcontextprotocol/sdk/types.js";
4
+ import { z } from "zod";
5
+ import type { McpTelemetryTransport } from "./mcp-semconv.js";
6
+ import { SecretRedactor } from "./secret-redactor.js";
7
+ import { McpTelemetry } from "./telemetry.js";
8
+ declare const NativeExecutionRecordSchema: z.ZodObject<{
9
+ id: z.ZodString;
10
+ serverId: z.ZodLiteral<"qyl.mcp/native">;
11
+ status: z.ZodEnum<{
12
+ failed: "failed";
13
+ running: "running";
14
+ succeeded: "succeeded";
15
+ }>;
16
+ createdAt: z.ZodString;
17
+ startedAt: z.ZodString;
18
+ completedAt: z.ZodOptional<z.ZodString>;
19
+ durationMs: z.ZodOptional<z.ZodNumber>;
20
+ attemptCount: z.ZodLiteral<1>;
21
+ request: z.ZodObject<{
22
+ requestId: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
23
+ toolName: z.ZodString;
24
+ arguments: z.ZodRecord<z.ZodString, z.ZodUnknown>;
25
+ transport: z.ZodEnum<{
26
+ builtin: "builtin";
27
+ http: "http";
28
+ inproc: "inproc";
29
+ sse: "sse";
30
+ stdio: "stdio";
31
+ "streamable-http": "streamable-http";
32
+ streamable_http: "streamable_http";
33
+ }>;
34
+ sessionId: z.ZodOptional<z.ZodString>;
35
+ meta: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
36
+ }, z.core.$strict>;
37
+ result: z.ZodOptional<z.ZodUnknown>;
38
+ error: z.ZodOptional<z.ZodObject<{
39
+ code: z.ZodString;
40
+ message: z.ZodString;
41
+ }, z.core.$strict>>;
42
+ tokenUsage: z.ZodOptional<z.ZodObject<{
43
+ inputTokens: z.ZodOptional<z.ZodNumber>;
44
+ outputTokens: z.ZodOptional<z.ZodNumber>;
45
+ totalTokens: z.ZodOptional<z.ZodNumber>;
46
+ estimated: z.ZodBoolean;
47
+ }, z.core.$strict>>;
48
+ cost: z.ZodOptional<z.ZodObject<{
49
+ amountUsd: z.ZodNumber;
50
+ estimated: z.ZodBoolean;
51
+ source: z.ZodOptional<z.ZodString>;
52
+ }, z.core.$strict>>;
53
+ protocolEvents: z.ZodArray<z.ZodObject<{
54
+ sequence: z.ZodNumber;
55
+ timestamp: z.ZodString;
56
+ direction: z.ZodEnum<{
57
+ inbound: "inbound";
58
+ outbound: "outbound";
59
+ }>;
60
+ messageKind: z.ZodEnum<{
61
+ error: "error";
62
+ request: "request";
63
+ result: "result";
64
+ }>;
65
+ jsonrpc: z.ZodLiteral<"2.0">;
66
+ requestId: z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>;
67
+ method: z.ZodLiteral<"tools/call">;
68
+ payload: z.ZodUnknown;
69
+ }, z.core.$strict>>;
70
+ telemetryCorrelation: z.ZodObject<{
71
+ executionId: z.ZodString;
72
+ traceIds: z.ZodArray<z.ZodString>;
73
+ spanIds: z.ZodArray<z.ZodString>;
74
+ }, z.core.$strict>;
75
+ }, z.core.$strict>;
76
+ export type NativeExecutionRecord = z.infer<typeof NativeExecutionRecordSchema>;
77
+ export interface NativeExecutionRepository {
78
+ save(record: NativeExecutionRecord): Promise<void>;
79
+ }
80
+ export interface FileNativeExecutionRepositoryOptions {
81
+ filePath?: string;
82
+ maxExecutions?: number;
83
+ now?: () => number;
84
+ redactor?: SecretRedactor;
85
+ environment?: Readonly<Record<string, string | undefined>>;
86
+ }
87
+ /** Durable, redacted native-server evidence kept separately from workbench state. */
88
+ export declare class FileNativeExecutionRepository implements NativeExecutionRepository {
89
+ private readonly store;
90
+ private readonly maxExecutions;
91
+ private readonly now;
92
+ private initialization;
93
+ constructor(options?: FileNativeExecutionRepositoryOptions);
94
+ save(record: NativeExecutionRecord): Promise<void>;
95
+ list(): Promise<NativeExecutionRecord[]>;
96
+ private initialize;
97
+ private initializeCore;
98
+ }
99
+ export interface NativeExecutionTelemetry {
100
+ startOperation: McpTelemetry["startOperation"];
101
+ close?(): Promise<void>;
102
+ }
103
+ export interface NativeExecutionRuntimeOptions {
104
+ telemetry?: NativeExecutionTelemetry;
105
+ redactor?: SecretRedactor;
106
+ now?: () => number;
107
+ id?: () => string;
108
+ }
109
+ export interface NativeToolCallInput {
110
+ request: CallToolRequest;
111
+ extra: RequestHandlerExtra<ServerRequest, ServerNotification>;
112
+ transport: McpTelemetryTransport;
113
+ }
114
+ /** Owns the automatic inbound tools/call lifecycle and evidence transaction. */
115
+ export declare class NativeExecutionRuntime {
116
+ private readonly repository;
117
+ private readonly telemetry?;
118
+ private readonly redactor;
119
+ private readonly now;
120
+ private readonly id;
121
+ constructor(repository: NativeExecutionRepository, options?: NativeExecutionRuntimeOptions);
122
+ execute(input: NativeToolCallInput, invoke: () => unknown | Promise<unknown>): Promise<CallToolResult>;
123
+ close(): Promise<void>;
124
+ get telemetryEnabled(): boolean;
125
+ private startTelemetry;
126
+ }
127
+ /** Wrap the SDK's single tools/call dispatcher, covering all current and future tools. */
128
+ export declare function installNativeExecutionRecording(server: McpServer, runtime: NativeExecutionRuntime, transport: McpTelemetryTransport): void;
129
+ export declare function hasNativeExecutionTelemetry(server: unknown): boolean;
130
+ export declare function defaultNativeExecutionRuntime(environment?: Readonly<Record<string, string | undefined>>): NativeExecutionRuntime;
131
+ export declare function closeDefaultNativeExecutionRuntime(): Promise<void>;
132
+ export {};