@himanshusinghs/mcp-metrics 1.11.0-prerelease.3
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/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -0
- package/dist/metricDefinitions.d.ts +15 -0
- package/dist/metricDefinitions.d.ts.map +1 -0
- package/dist/metricDefinitions.js +32 -0
- package/dist/metricDefinitions.js.map +1 -0
- package/dist/prometheusMetrics.d.ts +10 -0
- package/dist/prometheusMetrics.d.ts.map +1 -0
- package/dist/prometheusMetrics.js +21 -0
- package/dist/prometheusMetrics.js.map +1 -0
- package/dist/types.d.ts +28 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +38 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { PrometheusMetrics } from "./prometheusMetrics.js";
|
|
2
|
+
export { createDefaultMetrics } from "./metricDefinitions.js";
|
|
3
|
+
export type { DefaultMetrics } from "./metricDefinitions.js";
|
|
4
|
+
export type { Metrics, MetricDefinitions, PrometheusMetricsOptions } from "./types.js";
|
|
5
|
+
export { Registry, Gauge, Histogram, Counter } from "prom-client";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAC7D,YAAY,EAAE,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACvF,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Counter, Histogram } from "prom-client";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new set of default metrics for an MCP server.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: `registers: []` prevents prom-client from auto-registering these into
|
|
6
|
+
* the global registry; `PrometheusMetrics` registers them into its own
|
|
7
|
+
* isolated `Registry` instead.
|
|
8
|
+
*/
|
|
9
|
+
export declare function createDefaultMetrics(): {
|
|
10
|
+
readonly toolExecutionDuration: Histogram<"tool_name" | "category" | "status" | "operation_type" | "error_type">;
|
|
11
|
+
readonly sessionCreated: Counter<string>;
|
|
12
|
+
readonly sessionClosed: Counter<"reason">;
|
|
13
|
+
};
|
|
14
|
+
export type DefaultMetrics = ReturnType<typeof createDefaultMetrics>;
|
|
15
|
+
//# sourceMappingURL=metricDefinitions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metricDefinitions.d.ts","sourceRoot":"","sources":["../src/metricDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;GAMG;AAEH,wBAAgB,oBAAoB;;;;EAqBnC;AAED,MAAM,MAAM,cAAc,GAAG,UAAU,CAAC,OAAO,oBAAoB,CAAC,CAAC"}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Counter, Histogram } from "prom-client";
|
|
2
|
+
/**
|
|
3
|
+
* Creates a new set of default metrics for an MCP server.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: `registers: []` prevents prom-client from auto-registering these into
|
|
6
|
+
* the global registry; `PrometheusMetrics` registers them into its own
|
|
7
|
+
* isolated `Registry` instead.
|
|
8
|
+
*/
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/explicit-function-return-type
|
|
10
|
+
export function createDefaultMetrics() {
|
|
11
|
+
return {
|
|
12
|
+
toolExecutionDuration: new Histogram({
|
|
13
|
+
name: "mcp_tool_execution_duration_seconds",
|
|
14
|
+
help: "Duration of tool executions in seconds",
|
|
15
|
+
labelNames: ["tool_name", "category", "status", "operation_type", "error_type"],
|
|
16
|
+
buckets: [0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1, 2.5, 5, 10],
|
|
17
|
+
registers: [],
|
|
18
|
+
}),
|
|
19
|
+
sessionCreated: new Counter({
|
|
20
|
+
name: "mcp_session_created",
|
|
21
|
+
help: "Number of created sessions in a pod's lifetime",
|
|
22
|
+
registers: [],
|
|
23
|
+
}),
|
|
24
|
+
sessionClosed: new Counter({
|
|
25
|
+
name: "mcp_session_closed",
|
|
26
|
+
help: "Number of closed sessions in a pod's lifetime",
|
|
27
|
+
labelNames: ["reason"],
|
|
28
|
+
registers: [],
|
|
29
|
+
}),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
//# sourceMappingURL=metricDefinitions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metricDefinitions.js","sourceRoot":"","sources":["../src/metricDefinitions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAEjD;;;;;;GAMG;AACH,4EAA4E;AAC5E,MAAM,UAAU,oBAAoB;IAChC,OAAO;QACH,qBAAqB,EAAE,IAAI,SAAS,CAAC;YACjC,IAAI,EAAE,qCAAqC;YAC3C,IAAI,EAAE,wCAAwC;YAC9C,UAAU,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,QAAQ,EAAE,gBAAgB,EAAE,YAAY,CAAU;YACxF,OAAO,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC;YAC5D,SAAS,EAAE,EAAE;SAChB,CAAC;QACF,cAAc,EAAE,IAAI,OAAO,CAAC;YACxB,IAAI,EAAE,qBAAqB;YAC3B,IAAI,EAAE,gDAAgD;YACtD,SAAS,EAAE,EAAE;SAChB,CAAC;QACF,aAAa,EAAE,IAAI,OAAO,CAAC;YACvB,IAAI,EAAE,oBAAoB;YAC1B,IAAI,EAAE,+CAA+C;YACrD,UAAU,EAAE,CAAC,QAAQ,CAAU;YAC/B,SAAS,EAAE,EAAE;SAChB,CAAC;KACI,CAAC;AACf,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Registry } from "prom-client";
|
|
2
|
+
import type { Metrics, MetricDefinitions, PrometheusMetricsOptions } from "./types.js";
|
|
3
|
+
export declare class PrometheusMetrics<TMetrics extends MetricDefinitions> implements Metrics<TMetrics> {
|
|
4
|
+
readonly registry: Registry;
|
|
5
|
+
private readonly definitions;
|
|
6
|
+
constructor({ definitions, registry, collectProcessMetrics }: PrometheusMetricsOptions<TMetrics>);
|
|
7
|
+
get<K extends keyof TMetrics>(key: K): TMetrics[K];
|
|
8
|
+
getMetrics(): Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=prometheusMetrics.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prometheusMetrics.d.ts","sourceRoot":"","sources":["../src/prometheusMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAsC,MAAM,aAAa,CAAC;AAC3E,OAAO,KAAK,EAAE,OAAO,EAAE,iBAAiB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AAEvF,qBAAa,iBAAiB,CAAC,QAAQ,SAAS,iBAAiB,CAAE,YAAW,OAAO,CAAC,QAAQ,CAAC;IAC3F,SAAgB,QAAQ,EAAE,QAAQ,CAAC;IACnC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAW;gBAE3B,EAAE,WAAW,EAAE,QAAQ,EAAE,qBAA6B,EAAE,EAAE,wBAAwB,CAAC,QAAQ,CAAC;IAaxG,GAAG,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC;IAI5C,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;CAGtC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Registry, collectDefaultMetrics } from "prom-client";
|
|
2
|
+
export class PrometheusMetrics {
|
|
3
|
+
constructor({ definitions, registry, collectProcessMetrics = false }) {
|
|
4
|
+
this.registry = registry ?? new Registry();
|
|
5
|
+
if (collectProcessMetrics) {
|
|
6
|
+
collectDefaultMetrics({ register: this.registry });
|
|
7
|
+
}
|
|
8
|
+
this.definitions = definitions;
|
|
9
|
+
for (const key in this.definitions) {
|
|
10
|
+
const metric = this.definitions[key];
|
|
11
|
+
this.registry.registerMetric(metric);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
get(key) {
|
|
15
|
+
return this.definitions[key];
|
|
16
|
+
}
|
|
17
|
+
async getMetrics() {
|
|
18
|
+
return this.registry.metrics();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=prometheusMetrics.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prometheusMetrics.js","sourceRoot":"","sources":["../src/prometheusMetrics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAe,qBAAqB,EAAE,MAAM,aAAa,CAAC;AAG3E,MAAM,OAAO,iBAAiB;IAI1B,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,qBAAqB,GAAG,KAAK,EAAsC;QACpG,IAAI,CAAC,QAAQ,GAAG,QAAQ,IAAI,IAAI,QAAQ,EAAE,CAAC;QAC3C,IAAI,qBAAqB,EAAE,CAAC;YACxB,qBAAqB,CAAC,EAAE,QAAQ,EAAE,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC;QACvD,CAAC;QACD,IAAI,CAAC,WAAW,GAAG,WAAW,CAAC;QAE/B,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,WAAW,EAAE,CAAC;YACjC,MAAM,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YACrC,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAgB,CAAC,CAAC;QACnD,CAAC;IACL,CAAC;IAED,GAAG,CAA2B,GAAM;QAChC,OAAO,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,KAAK,CAAC,UAAU;QACZ,OAAO,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;IACnC,CAAC;CACJ"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Counter, Histogram, Gauge, Registry } from "prom-client";
|
|
2
|
+
export type MetricDefinitions = {
|
|
3
|
+
[key: string]: Histogram | Counter | Gauge;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
* Options for creating a `PrometheusMetrics` instance.
|
|
7
|
+
*
|
|
8
|
+
* Only `definitions` is required — the rest have sensible defaults.
|
|
9
|
+
*/
|
|
10
|
+
export interface PrometheusMetricsOptions<TMetrics extends MetricDefinitions> {
|
|
11
|
+
/** Metric instances (Counter / Histogram / Gauge) keyed by logical name. */
|
|
12
|
+
definitions: TMetrics;
|
|
13
|
+
/** Whether to collect Node.js and process metrics. */
|
|
14
|
+
collectProcessMetrics?: boolean;
|
|
15
|
+
/** Optional pre-existing registry; a fresh one is created when omitted. */
|
|
16
|
+
registry?: Registry;
|
|
17
|
+
}
|
|
18
|
+
export interface Metrics<TMetrics extends MetricDefinitions = MetricDefinitions> {
|
|
19
|
+
/**
|
|
20
|
+
* Get a metric instance by key.
|
|
21
|
+
*/
|
|
22
|
+
get<K extends keyof TMetrics>(key: K): TMetrics[K];
|
|
23
|
+
/**
|
|
24
|
+
* Get metrics in a format suitable for export (e.g., Prometheus text format).
|
|
25
|
+
*/
|
|
26
|
+
getMetrics(): Promise<string>;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAEvE,MAAM,MAAM,iBAAiB,GAAG;IAC5B,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,KAAK,CAAC;CAC9C,CAAC;AAEF;;;;GAIG;AACH,MAAM,WAAW,wBAAwB,CAAC,QAAQ,SAAS,iBAAiB;IACxE,4EAA4E;IAC5E,WAAW,EAAE,QAAQ,CAAC;IACtB,sDAAsD;IACtD,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACvB;AAED,MAAM,WAAW,OAAO,CAAC,QAAQ,SAAS,iBAAiB,GAAG,iBAAiB;IAC3E;;OAEG;IACH,GAAG,CAAC,CAAC,SAAS,MAAM,QAAQ,EAAE,GAAG,EAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEnD;;OAEG;IACH,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACjC"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
|
package/package.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@himanshusinghs/mcp-metrics",
|
|
3
|
+
"description": "Prometheus metrics helpers for MongoDB MCP servers",
|
|
4
|
+
"version": "1.11.0-prerelease.3",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"author": "MongoDB <info@mongodb.com>",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/mongodb-js/mongodb-mcp-server.git",
|
|
10
|
+
"directory": "packages/metrics"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"types": "./dist/index.d.ts",
|
|
18
|
+
"default": "./dist/index.js"
|
|
19
|
+
}
|
|
20
|
+
},
|
|
21
|
+
"main": "./dist/index.js",
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"files": [
|
|
24
|
+
"dist"
|
|
25
|
+
],
|
|
26
|
+
"scripts": {
|
|
27
|
+
"compile": "tsc --project tsconfig.json",
|
|
28
|
+
"test": "vitest --run"
|
|
29
|
+
},
|
|
30
|
+
"dependencies": {
|
|
31
|
+
"prom-client": "^15.1.3"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"@types/node": "^25.6.0",
|
|
35
|
+
"typescript": "^5.9.2",
|
|
36
|
+
"vitest": "^4.1.5"
|
|
37
|
+
}
|
|
38
|
+
}
|