@cyanheads/mcp-ts-core 0.1.4 → 0.1.8
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/CLAUDE.md +5 -1
- package/README.md +1 -1
- package/dist/core/app.d.ts +2 -0
- package/dist/core/app.d.ts.map +1 -1
- package/dist/core/app.js +19 -4
- package/dist/core/app.js.map +1 -1
- package/dist/core/context.d.ts +2 -2
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/context.js +9 -5
- package/dist/core/context.js.map +1 -1
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts.map +1 -1
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.js +4 -2
- package/dist/mcp-server/resources/utils/resourceHandlerFactory.js.map +1 -1
- package/dist/mcp-server/server.d.ts +6 -0
- package/dist/mcp-server/server.d.ts.map +1 -1
- package/dist/mcp-server/server.js +2 -11
- package/dist/mcp-server/server.js.map +1 -1
- package/dist/mcp-server/tasks/core/taskManager.js +1 -1
- package/dist/mcp-server/tasks/core/taskManager.js.map +1 -1
- package/dist/mcp-server/tools/tool-registration.d.ts.map +1 -1
- package/dist/mcp-server/tools/tool-registration.js +28 -12
- package/dist/mcp-server/tools/tool-registration.js.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -1
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js +12 -2
- package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -1
- package/dist/mcp-server/transports/auth/authMiddleware.js +1 -1
- package/dist/mcp-server/transports/auth/authMiddleware.js.map +1 -1
- package/dist/mcp-server/transports/auth/lib/authUtils.d.ts.map +1 -1
- package/dist/mcp-server/transports/auth/lib/authUtils.js +3 -2
- package/dist/mcp-server/transports/auth/lib/authUtils.js.map +1 -1
- package/dist/mcp-server/transports/auth/lib/checkScopes.d.ts.map +1 -1
- package/dist/mcp-server/transports/auth/lib/checkScopes.js +4 -4
- package/dist/mcp-server/transports/auth/lib/checkScopes.js.map +1 -1
- package/dist/mcp-server/transports/http/httpTransport.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/httpTransport.js +28 -18
- package/dist/mcp-server/transports/http/httpTransport.js.map +1 -1
- package/dist/mcp-server/transports/http/sessionStore.d.ts.map +1 -1
- package/dist/mcp-server/transports/http/sessionStore.js +23 -13
- package/dist/mcp-server/transports/http/sessionStore.js.map +1 -1
- package/dist/services/graph/core/GraphService.js +2 -2
- package/dist/services/graph/core/GraphService.js.map +1 -1
- package/dist/services/llm/providers/openrouter.provider.js +1 -1
- package/dist/services/llm/providers/openrouter.provider.js.map +1 -1
- package/dist/services/speech/core/speechMetrics.js +1 -1
- package/dist/services/speech/core/speechMetrics.js.map +1 -1
- package/dist/services/speech/providers/elevenlabs.provider.js +1 -1
- package/dist/services/speech/providers/elevenlabs.provider.js.map +1 -1
- package/dist/services/speech/providers/whisper.provider.js +1 -1
- package/dist/services/speech/providers/whisper.provider.js.map +1 -1
- package/dist/storage/core/StorageService.js +2 -2
- package/dist/storage/core/StorageService.js.map +1 -1
- package/dist/storage/core/storageValidation.d.ts.map +1 -1
- package/dist/storage/core/storageValidation.js +0 -13
- package/dist/storage/core/storageValidation.js.map +1 -1
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +3 -3
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/internal/error-handler/errorHandler.js +1 -1
- package/dist/utils/internal/error-handler/errorHandler.js.map +1 -1
- package/dist/utils/internal/performance.d.ts +10 -19
- package/dist/utils/internal/performance.d.ts.map +1 -1
- package/dist/utils/internal/performance.js +35 -118
- package/dist/utils/internal/performance.js.map +1 -1
- package/dist/utils/internal/requestContext.d.ts.map +1 -1
- package/dist/utils/internal/requestContext.js +13 -10
- package/dist/utils/internal/requestContext.js.map +1 -1
- package/dist/utils/telemetry/{semconv.d.ts → attributes.d.ts} +14 -129
- package/dist/utils/telemetry/attributes.d.ts.map +1 -0
- package/dist/utils/telemetry/{semconv.js → attributes.js} +27 -148
- package/dist/utils/telemetry/attributes.js.map +1 -0
- package/dist/utils/telemetry/index.d.ts +3 -3
- package/dist/utils/telemetry/index.d.ts.map +1 -1
- package/dist/utils/telemetry/index.js +3 -3
- package/dist/utils/telemetry/index.js.map +1 -1
- package/dist/utils/telemetry/instrumentation.d.ts.map +1 -1
- package/dist/utils/telemetry/instrumentation.js +23 -19
- package/dist/utils/telemetry/instrumentation.js.map +1 -1
- package/dist/utils/telemetry/metrics.d.ts +0 -64
- package/dist/utils/telemetry/metrics.d.ts.map +1 -1
- package/dist/utils/telemetry/metrics.js +0 -78
- package/dist/utils/telemetry/metrics.js.map +1 -1
- package/package.json +14 -14
- package/skills/add-test/SKILL.md +216 -0
- package/skills/api-utils/SKILL.md +5 -7
- package/skills/design-mcp-server/SKILL.md +153 -9
- package/skills/polish-docs-meta/SKILL.md +137 -0
- package/skills/polish-docs-meta/references/agent-protocol.md +78 -0
- package/skills/polish-docs-meta/references/package-meta.md +63 -0
- package/skills/polish-docs-meta/references/readme.md +183 -0
- package/skills/polish-docs-meta/references/server-json.md +142 -0
- package/skills/release/SKILL.md +102 -30
- package/skills/setup/SKILL.md +3 -2
- package/templates/.env.example +6 -1
- package/templates/AGENTS.md +3 -1
- package/templates/CLAUDE.md +3 -1
- package/templates/Dockerfile +84 -0
- package/templates/_.gitignore +6 -0
- package/templates/package.json +3 -0
- package/templates/src/mcp-server/tools/definitions/echo.tool.ts +2 -0
- package/dist/utils/telemetry/semconv.d.ts.map +0 -1
- package/dist/utils/telemetry/semconv.js.map +0 -1
|
@@ -35,29 +35,36 @@ function canUseNodeSDK() {
|
|
|
35
35
|
* @returns Record of cloud-related resource attributes
|
|
36
36
|
*/
|
|
37
37
|
function detectCloudResource() {
|
|
38
|
+
// Import constants inline — this function runs once at startup, not on the hot path.
|
|
39
|
+
// Cloud/deployment attrs use stable SEMRESATTRS_* names; deployment.environment.name
|
|
40
|
+
// is only in /incubating so we keep the string literal for that one attribute.
|
|
41
|
+
const CLOUD_PROVIDER = 'cloud.provider';
|
|
42
|
+
const CLOUD_PLATFORM = 'cloud.platform';
|
|
43
|
+
const CLOUD_REGION = 'cloud.region';
|
|
44
|
+
const DEPLOYMENT_ENV_NAME = 'deployment.environment.name';
|
|
38
45
|
const attrs = {};
|
|
39
46
|
// Cloudflare Workers
|
|
40
47
|
if (runtimeCaps.isWorkerLike) {
|
|
41
|
-
attrs[
|
|
42
|
-
attrs[
|
|
48
|
+
attrs[CLOUD_PROVIDER] = 'cloudflare';
|
|
49
|
+
attrs[CLOUD_PLATFORM] = 'cloudflare_workers';
|
|
43
50
|
}
|
|
44
51
|
// AWS Lambda
|
|
45
52
|
if (typeof process !== 'undefined' && process.env?.AWS_LAMBDA_FUNCTION_NAME) {
|
|
46
|
-
attrs[
|
|
47
|
-
attrs[
|
|
53
|
+
attrs[CLOUD_PROVIDER] = 'aws';
|
|
54
|
+
attrs[CLOUD_PLATFORM] = 'aws_lambda';
|
|
48
55
|
if (process.env.AWS_REGION) {
|
|
49
|
-
attrs[
|
|
56
|
+
attrs[CLOUD_REGION] = process.env.AWS_REGION;
|
|
50
57
|
}
|
|
51
58
|
}
|
|
52
59
|
// GCP Cloud Functions/Cloud Run
|
|
53
60
|
if (typeof process !== 'undefined' && (process.env?.FUNCTION_TARGET || process.env?.K_SERVICE)) {
|
|
54
|
-
attrs[
|
|
55
|
-
attrs[
|
|
61
|
+
attrs[CLOUD_PROVIDER] = 'gcp';
|
|
62
|
+
attrs[CLOUD_PLATFORM] = process.env.FUNCTION_TARGET ? 'gcp_cloud_functions' : 'gcp_cloud_run';
|
|
56
63
|
if (process.env.GCP_REGION) {
|
|
57
|
-
attrs[
|
|
64
|
+
attrs[CLOUD_REGION] = process.env.GCP_REGION;
|
|
58
65
|
}
|
|
59
66
|
}
|
|
60
|
-
attrs[
|
|
67
|
+
attrs[DEPLOYMENT_ENV_NAME] = config.environment;
|
|
61
68
|
return attrs;
|
|
62
69
|
}
|
|
63
70
|
/**
|
|
@@ -109,8 +116,8 @@ export async function initializeOpenTelemetry() {
|
|
|
109
116
|
}
|
|
110
117
|
try {
|
|
111
118
|
// Lazy-load Node-specific modules
|
|
112
|
-
const [{
|
|
113
|
-
import('@opentelemetry/
|
|
119
|
+
const [{ HttpInstrumentation }, { OTLPMetricExporter }, { OTLPTraceExporter }, { PinoInstrumentation }, { resourceFromAttributes }, { PeriodicExportingMetricReader }, { NodeSDK }, { BatchSpanProcessor, TraceIdRatioBasedSampler }, { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION },] = await Promise.all([
|
|
120
|
+
import('@opentelemetry/instrumentation-http'),
|
|
114
121
|
import('@opentelemetry/exporter-metrics-otlp-http'),
|
|
115
122
|
import('@opentelemetry/exporter-trace-otlp-http'),
|
|
116
123
|
import('@opentelemetry/instrumentation-pino'),
|
|
@@ -118,7 +125,7 @@ export async function initializeOpenTelemetry() {
|
|
|
118
125
|
import('@opentelemetry/sdk-metrics'),
|
|
119
126
|
import('@opentelemetry/sdk-node'),
|
|
120
127
|
import('@opentelemetry/sdk-trace-node'),
|
|
121
|
-
import('@opentelemetry/semantic-conventions
|
|
128
|
+
import('@opentelemetry/semantic-conventions'),
|
|
122
129
|
]);
|
|
123
130
|
const otelLogLevelString = config.openTelemetry.logLevel.toUpperCase();
|
|
124
131
|
const otelLogLevel = DiagLogLevel[otelLogLevelString] ?? DiagLogLevel.INFO;
|
|
@@ -154,12 +161,8 @@ export async function initializeOpenTelemetry() {
|
|
|
154
161
|
...(metricReader && { metricReader }),
|
|
155
162
|
sampler: new TraceIdRatioBasedSampler(config.openTelemetry.samplingRatio),
|
|
156
163
|
instrumentations: [
|
|
157
|
-
|
|
158
|
-
'
|
|
159
|
-
enabled: true,
|
|
160
|
-
ignoreIncomingRequestHook: (req) => req.url === '/healthz',
|
|
161
|
-
},
|
|
162
|
-
'@opentelemetry/instrumentation-fs': { enabled: false },
|
|
164
|
+
new HttpInstrumentation({
|
|
165
|
+
ignoreIncomingRequestHook: (req) => req.url === '/healthz',
|
|
163
166
|
}),
|
|
164
167
|
new PinoInstrumentation({
|
|
165
168
|
logHook: (_span, record) => {
|
|
@@ -208,8 +211,9 @@ export async function shutdownOpenTelemetry(timeoutMs = 5000) {
|
|
|
208
211
|
try {
|
|
209
212
|
const shutdownPromise = sdk.shutdown();
|
|
210
213
|
const { promise: timeoutPromise, reject } = Promise.withResolvers();
|
|
211
|
-
setTimeout(() => reject(new Error('OpenTelemetry SDK shutdown timeout')), timeoutMs);
|
|
214
|
+
const timer = setTimeout(() => reject(new Error('OpenTelemetry SDK shutdown timeout')), timeoutMs);
|
|
212
215
|
await Promise.race([shutdownPromise, timeoutPromise]);
|
|
216
|
+
clearTimeout(timer);
|
|
213
217
|
diag.info('OpenTelemetry SDK terminated successfully.');
|
|
214
218
|
}
|
|
215
219
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrumentation.js","sourceRoot":"","sources":["../../../src/utils/telemetry/instrumentation.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,iBAAiB,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AAE3E,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE1D;;;;;GAKG;AACH,MAAM,CAAC,IAAI,GAAG,GAAmB,IAAI,CAAC;AAEtC,kCAAkC;AAClC,IAAI,iBAAiB,GAAG,KAAK,CAAC;AAC9B,IAAI,qBAAqB,GAAyB,IAAI,CAAC;AAEvD;;;;;GAKG;AACH,SAAS,aAAa;IACpB,OAAO,CACL,WAAW,CAAC,MAAM;QAClB,OAAO,OAAO,EAAE,QAAQ,EAAE,IAAI,KAAK,QAAQ;QAC3C,OAAO,OAAO,CAAC,GAAG,KAAK,QAAQ,CAChC,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,SAAS,mBAAmB;IAC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E,CAAC,MAAM,CAAC,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC,EAC7D,SAAS,CACV,CAAC;QAEF,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC,eAAe,EAAE,cAAc,CAAC,CAAC,CAAC;QACtD,YAAY,CAAC,KAAK,CAAC,CAAC;QACpB,IAAI,CAAC,IAAI,CAAC,4CAA4C,CAAC,CAAC;IAC1D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,CAAC,KAAK,CAAC,qCAAqC,EAAE,KAAK,CAAC,CAAC;QACzD,MAAM,KAAK,CAAC,CAAC,gCAAgC;IAC/C,CAAC;YAAS,CAAC;QACT,GAAG,GAAG,IAAI,CAAC;QACX,iBAAiB,GAAG,KAAK,CAAC;QAC1B,qBAAqB,GAAG,IAAI,CAAC;IAC/B,CAAC;AACH,CAAC"}
|
|
@@ -95,76 +95,12 @@ export declare function createHistogram(name: string, description: string, unit?
|
|
|
95
95
|
/**
|
|
96
96
|
* Creates an observable gauge for async/callback-based measurements.
|
|
97
97
|
* Gauges are polled periodically by the metrics SDK and report current values.
|
|
98
|
-
* Use for measuring things like memory usage, queue depth, temperature, etc.
|
|
99
98
|
*
|
|
100
99
|
* @param name - Metric name (should use dot notation)
|
|
101
100
|
* @param description - Human-readable description
|
|
102
101
|
* @param callback - Async function returning the current metric value
|
|
103
102
|
* @param unit - Optional unit of measurement
|
|
104
103
|
* @returns ObservableGauge instance
|
|
105
|
-
*
|
|
106
|
-
* @example
|
|
107
|
-
* ```typescript
|
|
108
|
-
* // Monitor heap memory usage
|
|
109
|
-
* createObservableGauge(
|
|
110
|
-
* 'process.memory.heap_used',
|
|
111
|
-
* 'Current heap memory usage',
|
|
112
|
-
* () => {
|
|
113
|
-
* if (typeof process !== 'undefined') {
|
|
114
|
-
* return process.memoryUsage().heapUsed;
|
|
115
|
-
* }
|
|
116
|
-
* return 0;
|
|
117
|
-
* },
|
|
118
|
-
* 'bytes'
|
|
119
|
-
* );
|
|
120
|
-
* ```
|
|
121
104
|
*/
|
|
122
105
|
export declare function createObservableGauge(name: string, description: string, callback: () => Promise<number> | number, unit?: string): ObservableGauge;
|
|
123
|
-
/**
|
|
124
|
-
* Creates an observable counter for async/callback-based cumulative measurements.
|
|
125
|
-
* Similar to ObservableGauge but for monotonically increasing values.
|
|
126
|
-
* The callback is registered via `addCallback` and polled by the metrics SDK on each collection cycle.
|
|
127
|
-
*
|
|
128
|
-
* @param name - Metric name (should use dot notation, e.g., 'jobs.processed')
|
|
129
|
-
* @param description - Human-readable description
|
|
130
|
-
* @param callback - Async function returning the current cumulative count
|
|
131
|
-
* @param unit - Optional unit of measurement (default: '1')
|
|
132
|
-
* @returns ObservableCounter instance
|
|
133
|
-
*
|
|
134
|
-
* @example
|
|
135
|
-
* ```typescript
|
|
136
|
-
* let totalProcessed = 0;
|
|
137
|
-
*
|
|
138
|
-
* createObservableCounter(
|
|
139
|
-
* 'jobs.processed',
|
|
140
|
-
* 'Total jobs processed since startup',
|
|
141
|
-
* () => totalProcessed,
|
|
142
|
-
* '{jobs}'
|
|
143
|
-
* );
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
|
-
export declare function createObservableCounter(name: string, description: string, callback: () => Promise<number> | number, unit?: string): import("@opentelemetry/api").ObservableCounter<import("@opentelemetry/api").Attributes>;
|
|
147
|
-
/**
|
|
148
|
-
* Creates an observable up-down counter for async/callback-based measurements
|
|
149
|
-
* that can increase or decrease.
|
|
150
|
-
* The callback is registered via `addCallback` and polled by the metrics SDK on each collection cycle.
|
|
151
|
-
*
|
|
152
|
-
* @param name - Metric name (should use dot notation, e.g., 'queue.size')
|
|
153
|
-
* @param description - Human-readable description of what the metric measures
|
|
154
|
-
* @param callback - Async function returning the current value (can be positive or negative)
|
|
155
|
-
* @param unit - Optional unit of measurement (default: '1')
|
|
156
|
-
* @returns ObservableUpDownCounter instance
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* ```typescript
|
|
160
|
-
* // Track current queue size
|
|
161
|
-
* createObservableUpDownCounter(
|
|
162
|
-
* 'queue.size',
|
|
163
|
-
* 'Current number of items in queue',
|
|
164
|
-
* async () => await getQueueSize(),
|
|
165
|
-
* '{items}'
|
|
166
|
-
* );
|
|
167
|
-
* ```
|
|
168
|
-
*/
|
|
169
|
-
export declare function createObservableUpDownCounter(name: string, description: string, callback: () => Promise<number> | number, unit?: string): import("@opentelemetry/api").ObservableUpDownCounter<import("@opentelemetry/api").Attributes>;
|
|
170
106
|
//# sourceMappingURL=metrics.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/utils/telemetry/metrics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,KAAK,EAEV,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAI5B;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAK7C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,OAAO,CAGpF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,SAAM,uFAGhF;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAI3F;AAED
|
|
1
|
+
{"version":3,"file":"metrics.d.ts","sourceRoot":"","sources":["../../../src/utils/telemetry/metrics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,SAAS,EACd,KAAK,KAAK,EAEV,KAAK,eAAe,EACrB,MAAM,oBAAoB,CAAC;AAI5B;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,KAAK,CAK7C;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,SAAM,GAAG,OAAO,CAGpF;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,SAAM,uFAGhF;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAI3F;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CACnC,IAAI,EAAE,MAAM,EACZ,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,OAAO,CAAC,MAAM,CAAC,GAAG,MAAM,EACxC,IAAI,CAAC,EAAE,MAAM,GACZ,eAAe,CAQjB"}
|
|
@@ -108,29 +108,12 @@ export function createHistogram(name, description, unit) {
|
|
|
108
108
|
/**
|
|
109
109
|
* Creates an observable gauge for async/callback-based measurements.
|
|
110
110
|
* Gauges are polled periodically by the metrics SDK and report current values.
|
|
111
|
-
* Use for measuring things like memory usage, queue depth, temperature, etc.
|
|
112
111
|
*
|
|
113
112
|
* @param name - Metric name (should use dot notation)
|
|
114
113
|
* @param description - Human-readable description
|
|
115
114
|
* @param callback - Async function returning the current metric value
|
|
116
115
|
* @param unit - Optional unit of measurement
|
|
117
116
|
* @returns ObservableGauge instance
|
|
118
|
-
*
|
|
119
|
-
* @example
|
|
120
|
-
* ```typescript
|
|
121
|
-
* // Monitor heap memory usage
|
|
122
|
-
* createObservableGauge(
|
|
123
|
-
* 'process.memory.heap_used',
|
|
124
|
-
* 'Current heap memory usage',
|
|
125
|
-
* () => {
|
|
126
|
-
* if (typeof process !== 'undefined') {
|
|
127
|
-
* return process.memoryUsage().heapUsed;
|
|
128
|
-
* }
|
|
129
|
-
* return 0;
|
|
130
|
-
* },
|
|
131
|
-
* 'bytes'
|
|
132
|
-
* );
|
|
133
|
-
* ```
|
|
134
117
|
*/
|
|
135
118
|
export function createObservableGauge(name, description, callback, unit) {
|
|
136
119
|
const meter = getMeter();
|
|
@@ -141,65 +124,4 @@ export function createObservableGauge(name, description, callback, unit) {
|
|
|
141
124
|
});
|
|
142
125
|
return gauge;
|
|
143
126
|
}
|
|
144
|
-
/**
|
|
145
|
-
* Creates an observable counter for async/callback-based cumulative measurements.
|
|
146
|
-
* Similar to ObservableGauge but for monotonically increasing values.
|
|
147
|
-
* The callback is registered via `addCallback` and polled by the metrics SDK on each collection cycle.
|
|
148
|
-
*
|
|
149
|
-
* @param name - Metric name (should use dot notation, e.g., 'jobs.processed')
|
|
150
|
-
* @param description - Human-readable description
|
|
151
|
-
* @param callback - Async function returning the current cumulative count
|
|
152
|
-
* @param unit - Optional unit of measurement (default: '1')
|
|
153
|
-
* @returns ObservableCounter instance
|
|
154
|
-
*
|
|
155
|
-
* @example
|
|
156
|
-
* ```typescript
|
|
157
|
-
* let totalProcessed = 0;
|
|
158
|
-
*
|
|
159
|
-
* createObservableCounter(
|
|
160
|
-
* 'jobs.processed',
|
|
161
|
-
* 'Total jobs processed since startup',
|
|
162
|
-
* () => totalProcessed,
|
|
163
|
-
* '{jobs}'
|
|
164
|
-
* );
|
|
165
|
-
* ```
|
|
166
|
-
*/
|
|
167
|
-
export function createObservableCounter(name, description, callback, unit = '1') {
|
|
168
|
-
const meter = getMeter();
|
|
169
|
-
const counter = meter.createObservableCounter(name, { description, unit });
|
|
170
|
-
counter.addCallback(async (result) => {
|
|
171
|
-
result.observe(await callback());
|
|
172
|
-
});
|
|
173
|
-
return counter;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Creates an observable up-down counter for async/callback-based measurements
|
|
177
|
-
* that can increase or decrease.
|
|
178
|
-
* The callback is registered via `addCallback` and polled by the metrics SDK on each collection cycle.
|
|
179
|
-
*
|
|
180
|
-
* @param name - Metric name (should use dot notation, e.g., 'queue.size')
|
|
181
|
-
* @param description - Human-readable description of what the metric measures
|
|
182
|
-
* @param callback - Async function returning the current value (can be positive or negative)
|
|
183
|
-
* @param unit - Optional unit of measurement (default: '1')
|
|
184
|
-
* @returns ObservableUpDownCounter instance
|
|
185
|
-
*
|
|
186
|
-
* @example
|
|
187
|
-
* ```typescript
|
|
188
|
-
* // Track current queue size
|
|
189
|
-
* createObservableUpDownCounter(
|
|
190
|
-
* 'queue.size',
|
|
191
|
-
* 'Current number of items in queue',
|
|
192
|
-
* async () => await getQueueSize(),
|
|
193
|
-
* '{items}'
|
|
194
|
-
* );
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
|
-
export function createObservableUpDownCounter(name, description, callback, unit = '1') {
|
|
198
|
-
const meter = getMeter();
|
|
199
|
-
const counter = meter.createObservableUpDownCounter(name, { description, unit });
|
|
200
|
-
counter.addCallback(async (result) => {
|
|
201
|
-
result.observe(await callback());
|
|
202
|
-
});
|
|
203
|
-
return counter;
|
|
204
|
-
}
|
|
205
127
|
//# sourceMappingURL=metrics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"metrics.js","sourceRoot":"","sources":["../../../src/utils/telemetry/metrics.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAIL,OAAO,GAER,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,QAAQ,CAAC,IAAa;IACpC,OAAO,OAAO,CAAC,QAAQ,CACrB,IAAI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EAAE,WAAW,EAAE,CAAC;IAC/D,MAAM,KAAK,GAAG,KAAK,CAAC,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;IACzD,KAAK,CAAC,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE;QACjC,MAAM,CAAC,OAAO,CAAC,MAAM,QAAQ,EAAE,CAAC,CAAC;IACnC,CAAC,CAAC,CAAC;IACH,OAAO,KAAK,CAAC;AACf,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cyanheads/mcp-ts-core",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"mcpName": "io.github.cyanheads/mcp-ts-core",
|
|
5
5
|
"description": "TypeScript framework for building Model Context Protocol (MCP) servers. Declarative tool/resource/prompt definitions, pluggable auth, multi-backend storage, OpenTelemetry observability, and support for both local (stdio/HTTP) and edge (Cloudflare Workers) runtimes.",
|
|
6
6
|
"main": "dist/core/app.js",
|
|
@@ -149,10 +149,10 @@
|
|
|
149
149
|
"rollup": "4.59.0"
|
|
150
150
|
},
|
|
151
151
|
"devDependencies": {
|
|
152
|
-
"@biomejs/biome": "2.4.
|
|
153
|
-
"@cloudflare/workers-types": "^4.
|
|
152
|
+
"@biomejs/biome": "2.4.8",
|
|
153
|
+
"@cloudflare/workers-types": "^4.20260317.1",
|
|
154
154
|
"@hono/otel": "^1.1.1",
|
|
155
|
-
"@opentelemetry/
|
|
155
|
+
"@opentelemetry/instrumentation-http": "^0.213.0",
|
|
156
156
|
"@opentelemetry/exporter-metrics-otlp-http": "^0.213.0",
|
|
157
157
|
"@opentelemetry/exporter-trace-otlp-http": "^0.213.0",
|
|
158
158
|
"@opentelemetry/instrumentation-pino": "^0.59.0",
|
|
@@ -161,8 +161,8 @@
|
|
|
161
161
|
"@opentelemetry/sdk-node": "^0.213.0",
|
|
162
162
|
"@opentelemetry/sdk-trace-node": "^2.6.0",
|
|
163
163
|
"@opentelemetry/semantic-conventions": "^1.40.0",
|
|
164
|
-
"@supabase/supabase-js": "^2.99.
|
|
165
|
-
"@types/bun": "^1.3.
|
|
164
|
+
"@supabase/supabase-js": "^2.99.3",
|
|
165
|
+
"@types/bun": "^1.3.11",
|
|
166
166
|
"@types/diff": "^8.0.0",
|
|
167
167
|
"@types/js-yaml": "^4.0.9",
|
|
168
168
|
"@types/node": "^25.5.0",
|
|
@@ -171,28 +171,28 @@
|
|
|
171
171
|
"@types/validator": "^13.15.10",
|
|
172
172
|
"@vitest/coverage-istanbul": "4.1.0",
|
|
173
173
|
"@vitest/ui": "4.1.0",
|
|
174
|
-
"bun-types": "^1.3.
|
|
174
|
+
"bun-types": "^1.3.11",
|
|
175
175
|
"chrono-node": "^2.9.0",
|
|
176
176
|
"clipboardy": "^5.3.1",
|
|
177
177
|
"depcheck": "^1.4.7",
|
|
178
178
|
"execa": "^9.6.1",
|
|
179
179
|
"fast-check": "^4.6.0",
|
|
180
180
|
"ignore": "^7.0.5",
|
|
181
|
-
"msw": "^2.12.
|
|
181
|
+
"msw": "^2.12.13",
|
|
182
182
|
"node-cron": "^4.2.1",
|
|
183
|
-
"openai": "^6.
|
|
183
|
+
"openai": "^6.32.0",
|
|
184
184
|
"papaparse": "^5.5.3",
|
|
185
185
|
"partial-json": "^0.1.7",
|
|
186
186
|
"pdf-lib": "^1.17.1",
|
|
187
187
|
"pino-pretty": "^13.1.3",
|
|
188
|
-
"sanitize-html": "^2.17.
|
|
188
|
+
"sanitize-html": "^2.17.2",
|
|
189
189
|
"repomix": "^1.12.0",
|
|
190
190
|
"tsc-alias": "^1.8.16",
|
|
191
191
|
"typedoc": "^0.28.17",
|
|
192
192
|
"typescript": "^5.9.3",
|
|
193
193
|
"unpdf": "^1.4.0",
|
|
194
194
|
"validator": "^13.15.26",
|
|
195
|
-
"vite": "8.0.
|
|
195
|
+
"vite": "8.0.1",
|
|
196
196
|
"vitest": "^4.1.0"
|
|
197
197
|
},
|
|
198
198
|
"keywords": [
|
|
@@ -255,13 +255,13 @@
|
|
|
255
255
|
"@opentelemetry/api": "^1.9.0",
|
|
256
256
|
"dotenv": "^17.3.1",
|
|
257
257
|
"hono": "^4.12.8",
|
|
258
|
-
"jose": "^6.2.
|
|
258
|
+
"jose": "^6.2.2",
|
|
259
259
|
"pino": "^10.3.1"
|
|
260
260
|
},
|
|
261
261
|
"peerDependencies": {
|
|
262
262
|
"zod": "^4.3.6",
|
|
263
263
|
"@hono/otel": "",
|
|
264
|
-
"@opentelemetry/
|
|
264
|
+
"@opentelemetry/instrumentation-http": "",
|
|
265
265
|
"@opentelemetry/exporter-metrics-otlp-http": "",
|
|
266
266
|
"@opentelemetry/exporter-trace-otlp-http": "",
|
|
267
267
|
"@opentelemetry/instrumentation-pino": "",
|
|
@@ -288,7 +288,7 @@
|
|
|
288
288
|
"@hono/otel": {
|
|
289
289
|
"optional": true
|
|
290
290
|
},
|
|
291
|
-
"@opentelemetry/
|
|
291
|
+
"@opentelemetry/instrumentation-http": {
|
|
292
292
|
"optional": true
|
|
293
293
|
},
|
|
294
294
|
"@opentelemetry/exporter-metrics-otlp-http": {
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: add-test
|
|
3
|
+
description: >
|
|
4
|
+
Scaffold a test file for an existing tool, resource, or service. Use when the user asks to add tests, improve coverage, or when a definition exists without a colocated test file.
|
|
5
|
+
metadata:
|
|
6
|
+
author: cyanheads
|
|
7
|
+
version: "1.0"
|
|
8
|
+
audience: external
|
|
9
|
+
type: reference
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## Context
|
|
13
|
+
|
|
14
|
+
Tests use Vitest and `createMockContext` from `@cyanheads/mcp-ts-core/testing`. Test files are colocated with their source: `foo.tool.ts` gets `foo.tool.test.ts` in the same directory.
|
|
15
|
+
|
|
16
|
+
For the full `createMockContext` API and testing patterns, read:
|
|
17
|
+
|
|
18
|
+
skills/api-testing/SKILL.md
|
|
19
|
+
|
|
20
|
+
## Steps
|
|
21
|
+
|
|
22
|
+
1. **Identify the target** — which tool, resource, or service needs tests
|
|
23
|
+
2. **Read the source file** — understand the handler's logic, input/output schemas, error paths, and which `ctx` features it uses
|
|
24
|
+
3. **Create the test file** colocated with the source
|
|
25
|
+
4. **Write test cases** covering happy path, error paths, and edge cases
|
|
26
|
+
5. **Run `npm test`** to verify
|
|
27
|
+
6. **Run `bun run devcheck`** to verify types
|
|
28
|
+
|
|
29
|
+
## Determining What to Test
|
|
30
|
+
|
|
31
|
+
Read the handler and identify:
|
|
32
|
+
|
|
33
|
+
| Aspect | Test Strategy |
|
|
34
|
+
|:-------|:-------------|
|
|
35
|
+
| **Happy path** | Valid input → expected output. Always include at least one. |
|
|
36
|
+
| **Input variations** | Optional fields omitted, defaults applied, boundary values |
|
|
37
|
+
| **Error paths** | Invalid state, missing resources, service failures → correct error thrown |
|
|
38
|
+
| **`ctx.state` usage** | Use `createMockContext({ tenantId: 'test' })` to enable storage |
|
|
39
|
+
| **`ctx.elicit` / `ctx.sample`** | Mock with `vi.fn()`, also test the absent case (undefined) |
|
|
40
|
+
| **`ctx.progress`** | Use `createMockContext({ progress: true })` for task tools |
|
|
41
|
+
| **`format` function** | Test separately if defined — it's pure, no ctx needed |
|
|
42
|
+
| **Auth scopes** | Not tested at handler level (framework enforces) — skip |
|
|
43
|
+
|
|
44
|
+
## Templates
|
|
45
|
+
|
|
46
|
+
### Tool test
|
|
47
|
+
|
|
48
|
+
```typescript
|
|
49
|
+
/**
|
|
50
|
+
* @fileoverview Tests for {{TOOL_NAME}} tool.
|
|
51
|
+
* @module mcp-server/tools/definitions/{{TOOL_NAME}}.test
|
|
52
|
+
*/
|
|
53
|
+
|
|
54
|
+
import { describe, expect, it } from 'vitest';
|
|
55
|
+
import { createMockContext } from '@cyanheads/mcp-ts-core/testing';
|
|
56
|
+
import { {{TOOL_EXPORT}} } from './{{tool-name}}.tool.js';
|
|
57
|
+
|
|
58
|
+
describe('{{TOOL_EXPORT}}', () => {
|
|
59
|
+
it('returns expected output for valid input', async () => {
|
|
60
|
+
const ctx = createMockContext();
|
|
61
|
+
const input = {{TOOL_EXPORT}}.input.parse({
|
|
62
|
+
// valid input matching the Zod schema
|
|
63
|
+
});
|
|
64
|
+
const result = await {{TOOL_EXPORT}}.handler(input, ctx);
|
|
65
|
+
expect(result).toMatchObject({
|
|
66
|
+
// expected output shape
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('throws on invalid state', async () => {
|
|
71
|
+
const ctx = createMockContext();
|
|
72
|
+
const input = {{TOOL_EXPORT}}.input.parse({
|
|
73
|
+
// input that triggers an error path
|
|
74
|
+
});
|
|
75
|
+
await expect({{TOOL_EXPORT}}.handler(input, ctx)).rejects.toThrow();
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
it('formats output correctly', () => {
|
|
79
|
+
const output = { /* mock output matching the output schema */ };
|
|
80
|
+
const blocks = {{TOOL_EXPORT}}.format!(output);
|
|
81
|
+
expect(blocks).toHaveLength(1);
|
|
82
|
+
expect(blocks[0].type).toBe('text');
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
### Resource test
|
|
88
|
+
|
|
89
|
+
```typescript
|
|
90
|
+
/**
|
|
91
|
+
* @fileoverview Tests for {{RESOURCE_NAME}} resource.
|
|
92
|
+
* @module mcp-server/resources/definitions/{{RESOURCE_NAME}}.test
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
import { describe, expect, it } from 'vitest';
|
|
96
|
+
import { createMockContext } from '@cyanheads/mcp-ts-core/testing';
|
|
97
|
+
import { {{RESOURCE_EXPORT}} } from './{{resource-name}}.resource.js';
|
|
98
|
+
|
|
99
|
+
describe('{{RESOURCE_EXPORT}}', () => {
|
|
100
|
+
it('returns data for valid params', async () => {
|
|
101
|
+
const ctx = createMockContext({ tenantId: 'test-tenant' });
|
|
102
|
+
const params = {{RESOURCE_EXPORT}}.params.parse({
|
|
103
|
+
// valid params matching the Zod schema
|
|
104
|
+
});
|
|
105
|
+
const result = await {{RESOURCE_EXPORT}}.handler(params, ctx);
|
|
106
|
+
expect(result).toBeDefined();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it('throws when resource not found', async () => {
|
|
110
|
+
const ctx = createMockContext({ tenantId: 'test-tenant' });
|
|
111
|
+
const params = {{RESOURCE_EXPORT}}.params.parse({
|
|
112
|
+
// params for a non-existent resource
|
|
113
|
+
});
|
|
114
|
+
await expect({{RESOURCE_EXPORT}}.handler(params, ctx)).rejects.toThrow();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('lists available resources', async () => {
|
|
118
|
+
const listing = await {{RESOURCE_EXPORT}}.list!();
|
|
119
|
+
expect(listing.resources).toBeInstanceOf(Array);
|
|
120
|
+
expect(listing.resources.length).toBeGreaterThan(0);
|
|
121
|
+
for (const r of listing.resources) {
|
|
122
|
+
expect(r).toHaveProperty('uri');
|
|
123
|
+
expect(r).toHaveProperty('name');
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### Service test
|
|
130
|
+
|
|
131
|
+
```typescript
|
|
132
|
+
/**
|
|
133
|
+
* @fileoverview Tests for {{SERVICE_NAME}} service.
|
|
134
|
+
* @module services/{{domain}}/{{SERVICE_NAME}}.test
|
|
135
|
+
*/
|
|
136
|
+
|
|
137
|
+
import { beforeEach, describe, expect, it } from 'vitest';
|
|
138
|
+
import { createMockContext } from '@cyanheads/mcp-ts-core/testing';
|
|
139
|
+
import { init{{ServiceClass}}, get{{ServiceClass}} } from './{{service-name}}-service.js';
|
|
140
|
+
|
|
141
|
+
describe('{{ServiceClass}}', () => {
|
|
142
|
+
beforeEach(() => {
|
|
143
|
+
// Re-initialize with fresh config/storage per suite
|
|
144
|
+
init{{ServiceClass}}(mockConfig, mockStorage);
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
it('performs the expected operation', async () => {
|
|
148
|
+
const ctx = createMockContext({ tenantId: 'test-tenant' });
|
|
149
|
+
const service = get{{ServiceClass}}();
|
|
150
|
+
const result = await service.doWork('input', ctx);
|
|
151
|
+
expect(result).toBeDefined();
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('throws when not initialized', () => {
|
|
155
|
+
// Reset the singleton — this is the only case where accessing
|
|
156
|
+
// the module internals is acceptable
|
|
157
|
+
expect(() => get{{ServiceClass}}()).toThrow(/not initialized/);
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Task tool test
|
|
163
|
+
|
|
164
|
+
For tools with `task: true`, use `createMockContext({ progress: true })`:
|
|
165
|
+
|
|
166
|
+
```typescript
|
|
167
|
+
it('reports progress during execution', async () => {
|
|
168
|
+
const ctx = createMockContext({ progress: true });
|
|
169
|
+
const input = {{TOOL_EXPORT}}.input.parse({ count: 3, delayMs: 10 });
|
|
170
|
+
await {{TOOL_EXPORT}}.handler(input, ctx);
|
|
171
|
+
|
|
172
|
+
const progress = ctx.progress as ContextProgress & {
|
|
173
|
+
_total: number;
|
|
174
|
+
_completed: number;
|
|
175
|
+
_messages: string[];
|
|
176
|
+
};
|
|
177
|
+
expect(progress._total).toBe(3);
|
|
178
|
+
expect(progress._completed).toBe(3);
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it('respects cancellation', async () => {
|
|
182
|
+
const controller = new AbortController();
|
|
183
|
+
const ctx = createMockContext({ progress: true, signal: controller.signal });
|
|
184
|
+
const input = {{TOOL_EXPORT}}.input.parse({ count: 100, delayMs: 10 });
|
|
185
|
+
|
|
186
|
+
// Abort after a short delay
|
|
187
|
+
setTimeout(() => controller.abort(), 50);
|
|
188
|
+
const result = await {{TOOL_EXPORT}}.handler(input, ctx);
|
|
189
|
+
|
|
190
|
+
// Should have stopped early
|
|
191
|
+
expect(result.finalCount).toBeGreaterThan(0);
|
|
192
|
+
});
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
## Generating Tests from Schemas
|
|
196
|
+
|
|
197
|
+
When scaffolding tests for an existing handler, use the Zod schemas to generate meaningful test cases:
|
|
198
|
+
|
|
199
|
+
1. **Read `input` schema** — identify required fields, optional fields with defaults, constrained types (enums, min/max, patterns)
|
|
200
|
+
2. **Read `output` schema** — know what shape to assert against
|
|
201
|
+
3. **Happy path** — construct the simplest valid input, assert output matches schema
|
|
202
|
+
4. **Defaults** — omit optional fields, verify defaults are applied in the output
|
|
203
|
+
5. **Boundaries** — if the schema has `.min()`, `.max()`, `.length()`, test at the boundaries
|
|
204
|
+
6. **Error paths** — trace the handler logic for throw conditions, construct inputs that trigger each
|
|
205
|
+
|
|
206
|
+
## Checklist
|
|
207
|
+
|
|
208
|
+
- [ ] Test file created at `src/.../{{name}}.test.ts` (colocated with source)
|
|
209
|
+
- [ ] JSDoc `@fileoverview` and `@module` header present
|
|
210
|
+
- [ ] Happy path tested with valid input → expected output
|
|
211
|
+
- [ ] Error paths tested (at least one `.rejects.toThrow()`)
|
|
212
|
+
- [ ] `format` function tested if defined
|
|
213
|
+
- [ ] `createMockContext` options match handler's ctx usage (`tenantId`, `progress`, `elicit`, `sample`)
|
|
214
|
+
- [ ] Service re-initialized in `beforeEach` if handler depends on a service singleton
|
|
215
|
+
- [ ] `npm test` passes
|
|
216
|
+
- [ ] `bun run devcheck` passes
|
|
@@ -137,7 +137,7 @@ Both functions throw `McpError(InternalError)` only on unexpected heuristic fail
|
|
|
137
137
|
|
|
138
138
|
| Export | Signature | Notes |
|
|
139
139
|
|:-------|:----------|:------|
|
|
140
|
-
| `initializeOpenTelemetry` | `() -> Promise<void>` | Idempotent. Initializes `NodeSDK` with OTLP trace + metrics exporters, `TraceIdRatioBasedSampler`,
|
|
140
|
+
| `initializeOpenTelemetry` | `() -> Promise<void>` | Idempotent. Initializes `NodeSDK` with OTLP trace + metrics exporters, `TraceIdRatioBasedSampler`, HTTP instrumentation, and Pino log injection. No-ops when `OTEL_ENABLED=false` or in Worker/Edge runtimes where `NodeSDK` is unavailable. Safe to call multiple times. |
|
|
141
141
|
| `shutdownOpenTelemetry` | `(timeoutMs?: number) -> Promise<void>` | Gracefully flushes and shuts down the SDK. `timeoutMs` defaults to `5000`. Resets internal state so the next `initializeOpenTelemetry()` call can reinitialize. No-op when SDK was never started. |
|
|
142
142
|
| `sdk` | `NodeSDK \| null` | The live SDK instance, or `null` when telemetry is disabled, in a Worker runtime, or after shutdown. |
|
|
143
143
|
|
|
@@ -149,9 +149,7 @@ Both functions throw `McpError(InternalError)` only on unexpected heuristic fail
|
|
|
149
149
|
| `createCounter` | `(name: string, description: string, unit?: string) -> Counter` | Monotonically increasing counter. `unit` defaults to `'1'`. |
|
|
150
150
|
| `createUpDownCounter` | `(name: string, description: string, unit?: string) -> UpDownCounter` | Bidirectional counter (active connections, queue depth, etc.). `unit` defaults to `'1'`. |
|
|
151
151
|
| `createHistogram` | `(name: string, description: string, unit?: string) -> Histogram` | Distribution recording (latency, sizes). `unit` optional. |
|
|
152
|
-
| `createObservableGauge` | `(name: string, description: string, callback: () => Promise<number> \| number, unit?: string) -> ObservableGauge` | Polled gauge. `callback` is registered via `addCallback`; invoked on each SDK collection cycle. `unit` optional. |
|
|
153
|
-
| `createObservableCounter` | `(name: string, description: string, callback: () => Promise<number> \| number, unit?: string) -> ObservableCounter` | Polled cumulative counter. `unit` defaults to `'1'`. |
|
|
154
|
-
| `createObservableUpDownCounter` | `(name: string, description: string, callback: () => Promise<number> \| number, unit?: string) -> ObservableUpDownCounter` | Polled bidirectional counter. `unit` defaults to `'1'`. |
|
|
152
|
+
| `createObservableGauge` | `(name: string, description: string, callback: () => Promise<number> \| number, unit?: string) -> ObservableGauge` | Polled gauge. `callback` is registered via `addCallback`; invoked on each SDK collection cycle. `unit` optional. For other observable instrument types, use `getMeter()` directly. |
|
|
155
153
|
|
|
156
154
|
### `telemetry/trace`
|
|
157
155
|
|
|
@@ -164,8 +162,8 @@ Both functions throw `McpError(InternalError)` only on unexpected heuristic fail
|
|
|
164
162
|
| `createContextWithParentTrace` | `(parentHeaders: Headers \| Record<string, string \| undefined>, operation: string) -> RequestContext` | Extracts `traceparent` from headers and creates a child `RequestContext` inheriting `traceId`/`parentSpanId`. |
|
|
165
163
|
| `injectCurrentContextInto` | `<T extends Record<string, unknown>>(carrier: T) -> T` | Injects the active OTel context (traceparent, tracestate, etc.) into `carrier` via `propagation.inject`. Returns the same object. |
|
|
166
164
|
|
|
167
|
-
### `telemetry/
|
|
165
|
+
### `telemetry/attributes`
|
|
168
166
|
|
|
169
|
-
|
|
167
|
+
MCP-specific `ATTR_*` constant exports for span and metric attributes. Covers: code execution (`code.function.name`, `code.namespace`), MCP tool execution (name, input/output bytes, duration, success, error code), MCP resource (URI, MIME type, size, duration, success, error code), MCP request context (tenant ID, client ID), MCP session events, MCP storage, GenAI semantic conventions, speech, graph, auth, task, and error classification attributes.
|
|
170
168
|
|
|
171
|
-
|
|
169
|
+
Standard OTel semantic conventions (HTTP, cloud, service, network, etc.) are NOT re-exported — import those directly from `@opentelemetry/semantic-conventions` if needed.
|