@qase/mcp-server 2.7.4 → 3.0.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.
- package/CHANGELOG.md +58 -0
- package/README.md +4 -4
- package/build/auth/mcp-guard.d.ts.map +1 -1
- package/build/auth/mcp-guard.js +1 -1
- package/build/auth/mcp-guard.js.map +1 -1
- package/build/cache/metrics.d.ts.map +1 -1
- package/build/cache/metrics.js +16 -1
- package/build/cache/metrics.js.map +1 -1
- package/build/index.js +27 -5
- package/build/index.js.map +1 -1
- package/build/operations-v2/composites/ci-report.js +3 -5
- package/build/operations-v2/composites/ci-report.js.map +1 -1
- package/build/operations-v2/composites/regression-run.js +2 -1
- package/build/operations-v2/composites/regression-run.js.map +1 -1
- package/build/operations-v2/composites/triage-defect.js +5 -7
- package/build/operations-v2/composites/triage-defect.js.map +1 -1
- package/build/operations-v2/escape/api.js +11 -4
- package/build/operations-v2/escape/api.js.map +1 -1
- package/build/operations-v2/index.d.ts +1 -0
- package/build/operations-v2/index.d.ts.map +1 -1
- package/build/operations-v2/index.js +1 -0
- package/build/operations-v2/index.js.map +1 -1
- package/build/operations-v2/meta/discover.d.ts +5 -4
- package/build/operations-v2/meta/discover.d.ts.map +1 -1
- package/build/operations-v2/meta/discover.js +13 -32
- package/build/operations-v2/meta/discover.js.map +1 -1
- package/build/operations-v2/meta/tool-help.d.ts +10 -0
- package/build/operations-v2/meta/tool-help.d.ts.map +1 -0
- package/build/operations-v2/meta/tool-help.js +42 -0
- package/build/operations-v2/meta/tool-help.js.map +1 -0
- package/build/operations-v2/qql/index.js +15 -9
- package/build/operations-v2/qql/index.js.map +1 -1
- package/build/operations-v2/read/get.js +2 -1
- package/build/operations-v2/read/get.js.map +1 -1
- package/build/operations-v2/read/project-context.js +9 -7
- package/build/operations-v2/read/project-context.js.map +1 -1
- package/build/operations-v2/write/attachments.js +25 -19
- package/build/operations-v2/write/attachments.js.map +1 -1
- package/build/operations-v2/write/case-fields.d.ts +26 -215
- package/build/operations-v2/write/case-fields.d.ts.map +1 -1
- package/build/operations-v2/write/case-fields.js +28 -24
- package/build/operations-v2/write/case-fields.js.map +1 -1
- package/build/operations-v2/write/cases-bulk.js +2 -1
- package/build/operations-v2/write/cases-bulk.js.map +1 -1
- package/build/operations-v2/write/cases.js +4 -3
- package/build/operations-v2/write/cases.js.map +1 -1
- package/build/operations-v2/write/custom-fields.js +13 -10
- package/build/operations-v2/write/custom-fields.js.map +1 -1
- package/build/operations-v2/write/defects.js +7 -9
- package/build/operations-v2/write/defects.js.map +1 -1
- package/build/operations-v2/write/environments.js +5 -5
- package/build/operations-v2/write/environments.js.map +1 -1
- package/build/operations-v2/write/external-issues.js +2 -2
- package/build/operations-v2/write/external-issues.js.map +1 -1
- package/build/operations-v2/write/milestones.js +6 -6
- package/build/operations-v2/write/milestones.js.map +1 -1
- package/build/operations-v2/write/plans.js +5 -5
- package/build/operations-v2/write/plans.js.map +1 -1
- package/build/operations-v2/write/projects.js +6 -6
- package/build/operations-v2/write/projects.js.map +1 -1
- package/build/operations-v2/write/results.js +7 -12
- package/build/operations-v2/write/results.js.map +1 -1
- package/build/operations-v2/write/reviews.js +18 -18
- package/build/operations-v2/write/reviews.js.map +1 -1
- package/build/operations-v2/write/runs.js +8 -6
- package/build/operations-v2/write/runs.js.map +1 -1
- package/build/operations-v2/write/shared-steps.js +5 -8
- package/build/operations-v2/write/shared-steps.js.map +1 -1
- package/build/operations-v2/write/suites.js +4 -3
- package/build/operations-v2/write/suites.js.map +1 -1
- package/build/server-instructions.d.ts +1 -1
- package/build/server-instructions.d.ts.map +1 -1
- package/build/server-instructions.js +4 -4
- package/build/server.d.ts.map +1 -1
- package/build/server.js +154 -104
- package/build/server.js.map +1 -1
- package/build/transports/body-limit.d.ts +13 -0
- package/build/transports/body-limit.d.ts.map +1 -0
- package/build/transports/body-limit.js +43 -0
- package/build/transports/body-limit.js.map +1 -0
- package/build/transports/json-parse-error.d.ts +10 -6
- package/build/transports/json-parse-error.d.ts.map +1 -1
- package/build/transports/json-parse-error.js +38 -14
- package/build/transports/json-parse-error.js.map +1 -1
- package/build/transports/rate-limit.d.ts +1 -1
- package/build/transports/rate-limit.js +1 -1
- package/build/transports/sse.d.ts.map +1 -1
- package/build/transports/sse.js +3 -2
- package/build/transports/sse.js.map +1 -1
- package/build/transports/streamableHttp.d.ts.map +1 -1
- package/build/transports/streamableHttp.js +84 -171
- package/build/transports/streamableHttp.js.map +1 -1
- package/build/utils/auth-context.d.ts +30 -0
- package/build/utils/auth-context.d.ts.map +1 -1
- package/build/utils/auth-context.js +33 -0
- package/build/utils/auth-context.js.map +1 -1
- package/build/utils/protocol-telemetry.d.ts +62 -0
- package/build/utils/protocol-telemetry.d.ts.map +1 -0
- package/build/utils/protocol-telemetry.js +123 -0
- package/build/utils/protocol-telemetry.js.map +1 -0
- package/build/utils/registry.d.ts +28 -34
- package/build/utils/registry.d.ts.map +1 -1
- package/build/utils/registry.js +107 -102
- package/build/utils/registry.js.map +1 -1
- package/build/utils/request-state.d.ts +71 -0
- package/build/utils/request-state.d.ts.map +1 -0
- package/build/utils/request-state.js +108 -0
- package/build/utils/request-state.js.map +1 -0
- package/build/utils/server-context.d.ts +53 -16
- package/build/utils/server-context.d.ts.map +1 -1
- package/build/utils/server-context.js +147 -39
- package/build/utils/server-context.js.map +1 -1
- package/build/utils/validation.d.ts +12 -25
- package/build/utils/validation.d.ts.map +1 -1
- package/build/utils/validation.js +2 -2
- package/build/utils/validation.js.map +1 -1
- package/build/version.d.ts +1 -1
- package/build/version.js +1 -1
- package/docs/self-run.md +40 -3
- package/docs/tools.md +54 -60
- package/docs/troubleshooting.md +29 -8
- package/package.json +8 -9
- package/server.json +2 -2
|
@@ -13,4 +13,34 @@ export declare const requestTokenStorage: AsyncLocalStorage<string>;
|
|
|
13
13
|
* global cache shard.
|
|
14
14
|
*/
|
|
15
15
|
export declare function getEffectiveToken(): string;
|
|
16
|
+
/** The literal key used when there is no authenticated subject (OAuth off). */
|
|
17
|
+
export declare const LOCAL_SUBJECT = "local";
|
|
18
|
+
/**
|
|
19
|
+
* Derive the caller's identity for per-caller isolation — tool activation
|
|
20
|
+
* (src/server.ts) and the destructive-confirmation caller binding
|
|
21
|
+
* (src/utils/request-state.ts) both call this ONE function, so the two can
|
|
22
|
+
* never drift apart.
|
|
23
|
+
*
|
|
24
|
+
* Precedence:
|
|
25
|
+
* 1. `extra.sub` — set by our JWKS verifier (src/auth/jwks-verifier.ts)
|
|
26
|
+
* when OAuth validated a JWT that actually carries a `sub` claim.
|
|
27
|
+
* 2. A digest of the per-request API token — covers every other
|
|
28
|
+
* reachable state that leaves `sub` unset: OAuth on with an opaque
|
|
29
|
+
* Qase token (src/auth/mcp-guard.ts passes it through without setting
|
|
30
|
+
* `req.auth`), a JWT with no `sub` claim, and the SSE transport, which
|
|
31
|
+
* has no OAuth wiring at all. Both HTTP transports
|
|
32
|
+
* (streamableHttp.ts, sse.ts) open `requestTokenStorage` for every
|
|
33
|
+
* request, so the token is available here without new plumbing.
|
|
34
|
+
* SHA-256 hex digest, never the token itself — the raw token would
|
|
35
|
+
* otherwise end up in a Redis key (tool activation) or a log line.
|
|
36
|
+
* 3. `LOCAL_SUBJECT` — stdio, where there is no per-request token and one
|
|
37
|
+
* process serves one user, so a single shared identity is correct.
|
|
38
|
+
*/
|
|
39
|
+
export declare function subjectFromContext(ctx: {
|
|
40
|
+
http?: {
|
|
41
|
+
authInfo?: {
|
|
42
|
+
extra?: Record<string, unknown>;
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
}): string;
|
|
16
46
|
//# sourceMappingURL=auth-context.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-context.d.ts","sourceRoot":"","sources":["../../src/utils/auth-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-context.d.ts","sourceRoot":"","sources":["../../src/utils/auth-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAGhD;;;;GAIG;AACH,eAAO,MAAM,mBAAmB,2BAAkC,CAAC;AAEnE;;;;;;GAMG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAW1C;AAED,+EAA+E;AAC/E,eAAO,MAAM,aAAa,UAAU,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,kBAAkB,CAAC,GAAG,EAAE;IACtC,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE;YAAE,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;SAAE,CAAA;KAAE,CAAC;CAC3D,GAAG,MAAM,CAQT"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from 'async_hooks';
|
|
2
|
+
import { createHash } from 'node:crypto';
|
|
2
3
|
/**
|
|
3
4
|
* Per-request token storage.
|
|
4
5
|
* Holds the Bearer token extracted from the Authorization header for the current request.
|
|
@@ -23,4 +24,36 @@ export function getEffectiveToken() {
|
|
|
23
24
|
}
|
|
24
25
|
return envToken;
|
|
25
26
|
}
|
|
27
|
+
/** The literal key used when there is no authenticated subject (OAuth off). */
|
|
28
|
+
export const LOCAL_SUBJECT = 'local';
|
|
29
|
+
/**
|
|
30
|
+
* Derive the caller's identity for per-caller isolation — tool activation
|
|
31
|
+
* (src/server.ts) and the destructive-confirmation caller binding
|
|
32
|
+
* (src/utils/request-state.ts) both call this ONE function, so the two can
|
|
33
|
+
* never drift apart.
|
|
34
|
+
*
|
|
35
|
+
* Precedence:
|
|
36
|
+
* 1. `extra.sub` — set by our JWKS verifier (src/auth/jwks-verifier.ts)
|
|
37
|
+
* when OAuth validated a JWT that actually carries a `sub` claim.
|
|
38
|
+
* 2. A digest of the per-request API token — covers every other
|
|
39
|
+
* reachable state that leaves `sub` unset: OAuth on with an opaque
|
|
40
|
+
* Qase token (src/auth/mcp-guard.ts passes it through without setting
|
|
41
|
+
* `req.auth`), a JWT with no `sub` claim, and the SSE transport, which
|
|
42
|
+
* has no OAuth wiring at all. Both HTTP transports
|
|
43
|
+
* (streamableHttp.ts, sse.ts) open `requestTokenStorage` for every
|
|
44
|
+
* request, so the token is available here without new plumbing.
|
|
45
|
+
* SHA-256 hex digest, never the token itself — the raw token would
|
|
46
|
+
* otherwise end up in a Redis key (tool activation) or a log line.
|
|
47
|
+
* 3. `LOCAL_SUBJECT` — stdio, where there is no per-request token and one
|
|
48
|
+
* process serves one user, so a single shared identity is correct.
|
|
49
|
+
*/
|
|
50
|
+
export function subjectFromContext(ctx) {
|
|
51
|
+
const sub = ctx.http?.authInfo?.extra?.sub;
|
|
52
|
+
if (typeof sub === 'string' && sub.length > 0)
|
|
53
|
+
return sub;
|
|
54
|
+
const token = requestTokenStorage.getStore();
|
|
55
|
+
if (token)
|
|
56
|
+
return createHash('sha256').update(token).digest('hex');
|
|
57
|
+
return LOCAL_SUBJECT;
|
|
58
|
+
}
|
|
26
59
|
//# sourceMappingURL=auth-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth-context.js","sourceRoot":"","sources":["../../src/utils/auth-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"auth-context.js","sourceRoot":"","sources":["../../src/utils/auth-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,iBAAiB,EAAU,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,UAAU,iBAAiB;IAC/B,MAAM,YAAY,GAAG,mBAAmB,CAAC,QAAQ,EAAE,CAAC;IACpD,IAAI,YAAY;QAAE,OAAO,YAAY,CAAC;IACtC,MAAM,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC,cAAc,CAAC;IAC5C,IAAI,CAAC,QAAQ,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CACb,kGAAkG;YAChG,6DAA6D,CAChE,CAAC;IACJ,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED,+EAA+E;AAC/E,MAAM,CAAC,MAAM,aAAa,GAAG,OAAO,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,UAAU,kBAAkB,CAAC,GAElC;IACC,MAAM,GAAG,GAAG,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,GAAG,CAAC;IAC3C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IAE1D,MAAM,KAAK,GAAG,mBAAmB,CAAC,QAAQ,EAAE,CAAC;IAC7C,IAAI,KAAK;QAAE,OAAO,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAEnE,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who is talking to us, and on which revision of the protocol.
|
|
3
|
+
*
|
|
4
|
+
* This server serves two protocol eras at once, and the decision to stop
|
|
5
|
+
* serving the older one cannot be made from the code — only from traffic. The
|
|
6
|
+
* counter this module feeds is what turns "should we drop 2025-11-25?" into a
|
|
7
|
+
* question with an answer.
|
|
8
|
+
*
|
|
9
|
+
* On the 2026-07-28 revision every request carries a `_meta` envelope naming
|
|
10
|
+
* the revision and identifying the client, so both labels come from the
|
|
11
|
+
* request itself. A 2025-era request carries no envelope at all; the client's
|
|
12
|
+
* name is then only known where an `initialize` happened (stdio, SSE), and is
|
|
13
|
+
* reported as `unknown` on a stateless HTTP leg — which is itself worth
|
|
14
|
+
* knowing, since that is exactly the traffic a strict modern-only endpoint
|
|
15
|
+
* would refuse.
|
|
16
|
+
*/
|
|
17
|
+
/** Distinct client names this process will ever emit as a label. */
|
|
18
|
+
export declare const CLIENT_LABEL_LIMIT = 20;
|
|
19
|
+
/**
|
|
20
|
+
* Turns a client-supplied name into a bounded metric label.
|
|
21
|
+
*
|
|
22
|
+
* The name arrives from the wire, and every distinct value becomes its own
|
|
23
|
+
* series in an in-process map that nothing evicts. So the value is both
|
|
24
|
+
* normalised (a label is not free-form text) and CAPPED: past the limit every
|
|
25
|
+
* new name collapses into one bucket. Names already seen keep their series, so
|
|
26
|
+
* the clients that actually matter stay legible however much noise arrives
|
|
27
|
+
* after them.
|
|
28
|
+
*/
|
|
29
|
+
export declare class ClientLabeller {
|
|
30
|
+
private readonly limit;
|
|
31
|
+
private readonly seen;
|
|
32
|
+
constructor(limit?: number);
|
|
33
|
+
label(raw: unknown): string;
|
|
34
|
+
}
|
|
35
|
+
/** The handler context this module reads — narrower than the SDK's, on purpose. */
|
|
36
|
+
interface TelemetryContext {
|
|
37
|
+
mcpReq?: {
|
|
38
|
+
envelope?: Record<string, unknown>;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* The two labels for one request. The revision string is passed through as the
|
|
43
|
+
* envelope names it rather than folded into an era, so a revision that does not
|
|
44
|
+
* exist yet shows up as itself on the day a client first sends it.
|
|
45
|
+
*/
|
|
46
|
+
export declare function protocolLabels(ctx: TelemetryContext, labeller: ClientLabeller): {
|
|
47
|
+
protocol: string;
|
|
48
|
+
client: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* Who made this request, for a log line.
|
|
52
|
+
*
|
|
53
|
+
* Unlike the metric labels this is uncapped and keeps the client's version:
|
|
54
|
+
* a log has no cardinality problem, and when a refusal has to be explained
|
|
55
|
+
* the exact client build is the thing worth knowing. Reading a refusal
|
|
56
|
+
* without it leaves "some client declined" and no way to tell whose.
|
|
57
|
+
*/
|
|
58
|
+
export declare function describeCaller(ctx: TelemetryContext): string;
|
|
59
|
+
/** Count one served request under the revision and client it came from. */
|
|
60
|
+
export declare function recordProtocolRequest(ctx: TelemetryContext): void;
|
|
61
|
+
export {};
|
|
62
|
+
//# sourceMappingURL=protocol-telemetry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-telemetry.d.ts","sourceRoot":"","sources":["../../src/utils/protocol-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,oEAAoE;AACpE,eAAO,MAAM,kBAAkB,KAAK,CAAC;AAUrC;;;;;;;;;GASG;AACH,qBAAa,cAAc;IAGb,OAAO,CAAC,QAAQ,CAAC,KAAK;IAFlC,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAqB;gBAEb,KAAK,GAAE,MAA2B;IAE/D,KAAK,CAAC,GAAG,EAAE,OAAO,GAAG,MAAM;CAe5B;AAED,mFAAmF;AACnF,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC;CACjD;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,gBAAgB,EACrB,QAAQ,EAAE,cAAc,GACvB;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAA;CAAE,CAkBtC;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,GAAG,EAAE,gBAAgB,GAAG,MAAM,CAkB5D;AAoBD,2EAA2E;AAC3E,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,gBAAgB,GAAG,IAAI,CAEjE"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Who is talking to us, and on which revision of the protocol.
|
|
3
|
+
*
|
|
4
|
+
* This server serves two protocol eras at once, and the decision to stop
|
|
5
|
+
* serving the older one cannot be made from the code — only from traffic. The
|
|
6
|
+
* counter this module feeds is what turns "should we drop 2025-11-25?" into a
|
|
7
|
+
* question with an answer.
|
|
8
|
+
*
|
|
9
|
+
* On the 2026-07-28 revision every request carries a `_meta` envelope naming
|
|
10
|
+
* the revision and identifying the client, so both labels come from the
|
|
11
|
+
* request itself. A 2025-era request carries no envelope at all; the client's
|
|
12
|
+
* name is then only known where an `initialize` happened (stdio, SSE), and is
|
|
13
|
+
* reported as `unknown` on a stateless HTTP leg — which is itself worth
|
|
14
|
+
* knowing, since that is exactly the traffic a strict modern-only endpoint
|
|
15
|
+
* would refuse.
|
|
16
|
+
*/
|
|
17
|
+
import { PROTOCOL_VERSION_META_KEY, CLIENT_INFO_META_KEY } from '@modelcontextprotocol/server';
|
|
18
|
+
import { getMetrics } from '../cache/index.js';
|
|
19
|
+
import { getServer } from './server-context.js';
|
|
20
|
+
/** Distinct client names this process will ever emit as a label. */
|
|
21
|
+
export const CLIENT_LABEL_LIMIT = 20;
|
|
22
|
+
/** The label for a request whose era carries no version envelope. */
|
|
23
|
+
const LEGACY_PROTOCOL = 'legacy';
|
|
24
|
+
const UNKNOWN_CLIENT = 'unknown';
|
|
25
|
+
/** An envelope that names no revision — shape drift, not an era. */
|
|
26
|
+
const UNKNOWN_PROTOCOL = 'unknown';
|
|
27
|
+
const OVERFLOW_CLIENT = 'other';
|
|
28
|
+
const MAX_CLIENT_LENGTH = 32;
|
|
29
|
+
/**
|
|
30
|
+
* Turns a client-supplied name into a bounded metric label.
|
|
31
|
+
*
|
|
32
|
+
* The name arrives from the wire, and every distinct value becomes its own
|
|
33
|
+
* series in an in-process map that nothing evicts. So the value is both
|
|
34
|
+
* normalised (a label is not free-form text) and CAPPED: past the limit every
|
|
35
|
+
* new name collapses into one bucket. Names already seen keep their series, so
|
|
36
|
+
* the clients that actually matter stay legible however much noise arrives
|
|
37
|
+
* after them.
|
|
38
|
+
*/
|
|
39
|
+
export class ClientLabeller {
|
|
40
|
+
limit;
|
|
41
|
+
seen = new Set();
|
|
42
|
+
constructor(limit = CLIENT_LABEL_LIMIT) {
|
|
43
|
+
this.limit = limit;
|
|
44
|
+
}
|
|
45
|
+
label(raw) {
|
|
46
|
+
if (typeof raw !== 'string')
|
|
47
|
+
return UNKNOWN_CLIENT;
|
|
48
|
+
const cleaned = raw
|
|
49
|
+
.toLowerCase()
|
|
50
|
+
.replace(/[^a-z0-9._-]+/g, '-')
|
|
51
|
+
.replace(/^-+|-+$/g, '')
|
|
52
|
+
.slice(0, MAX_CLIENT_LENGTH);
|
|
53
|
+
if (!cleaned)
|
|
54
|
+
return UNKNOWN_CLIENT;
|
|
55
|
+
if (this.seen.has(cleaned))
|
|
56
|
+
return cleaned;
|
|
57
|
+
if (this.seen.size >= this.limit)
|
|
58
|
+
return OVERFLOW_CLIENT;
|
|
59
|
+
this.seen.add(cleaned);
|
|
60
|
+
return cleaned;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* The two labels for one request. The revision string is passed through as the
|
|
65
|
+
* envelope names it rather than folded into an era, so a revision that does not
|
|
66
|
+
* exist yet shows up as itself on the day a client first sends it.
|
|
67
|
+
*/
|
|
68
|
+
export function protocolLabels(ctx, labeller) {
|
|
69
|
+
const envelope = ctx.mcpReq?.envelope;
|
|
70
|
+
if (!envelope) {
|
|
71
|
+
// 2025-era: the name is known only if an initialize established it.
|
|
72
|
+
return {
|
|
73
|
+
protocol: LEGACY_PROTOCOL,
|
|
74
|
+
client: labeller.label(getServer()?.getClientVersion()?.name),
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
const version = envelope[PROTOCOL_VERSION_META_KEY];
|
|
78
|
+
const clientInfo = envelope[CLIENT_INFO_META_KEY];
|
|
79
|
+
return {
|
|
80
|
+
protocol: typeof version === 'string' && version.length > 0 ? version : UNKNOWN_PROTOCOL,
|
|
81
|
+
client: labeller.label(clientInfo?.name),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Who made this request, for a log line.
|
|
86
|
+
*
|
|
87
|
+
* Unlike the metric labels this is uncapped and keeps the client's version:
|
|
88
|
+
* a log has no cardinality problem, and when a refusal has to be explained
|
|
89
|
+
* the exact client build is the thing worth knowing. Reading a refusal
|
|
90
|
+
* without it leaves "some client declined" and no way to tell whose.
|
|
91
|
+
*/
|
|
92
|
+
export function describeCaller(ctx) {
|
|
93
|
+
const envelope = ctx.mcpReq?.envelope;
|
|
94
|
+
if (!envelope) {
|
|
95
|
+
// 2025-era: the name is whatever `initialize` established on this
|
|
96
|
+
// connection, and a stateless leg never saw one.
|
|
97
|
+
const legacy = getServer()?.getClientVersion();
|
|
98
|
+
return formatCaller(legacy?.name, legacy?.version, LEGACY_PROTOCOL);
|
|
99
|
+
}
|
|
100
|
+
const version = envelope[PROTOCOL_VERSION_META_KEY];
|
|
101
|
+
const info = envelope[CLIENT_INFO_META_KEY];
|
|
102
|
+
return formatCaller(info?.name, info?.version, typeof version === 'string' && version ? version : UNKNOWN_PROTOCOL);
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* `name version @ revision`, leaving out whichever parts the client withheld.
|
|
106
|
+
*
|
|
107
|
+
* Both eras read their three values from different places but write the same
|
|
108
|
+
* line, so the shape lives here once — the two call sites differ in where
|
|
109
|
+
* they look, not in what they produce. Everything arriving here is `unknown`
|
|
110
|
+
* because it came off the wire.
|
|
111
|
+
*/
|
|
112
|
+
function formatCaller(name, version, revision) {
|
|
113
|
+
const who = typeof name === 'string' && name ? name : 'unknown';
|
|
114
|
+
const build = typeof version === 'string' && version ? ' ' + version : '';
|
|
115
|
+
return `${who}${build} @ ${revision}`;
|
|
116
|
+
}
|
|
117
|
+
/** One labeller per process, so the cap bounds the process and not one request. */
|
|
118
|
+
const processLabeller = new ClientLabeller();
|
|
119
|
+
/** Count one served request under the revision and client it came from. */
|
|
120
|
+
export function recordProtocolRequest(ctx) {
|
|
121
|
+
getMetrics().incCounter('qase_mcp_requests_total', protocolLabels(ctx, processLabeller));
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=protocol-telemetry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol-telemetry.js","sourceRoot":"","sources":["../../src/utils/protocol-telemetry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,yBAAyB,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AAC/F,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD,oEAAoE;AACpE,MAAM,CAAC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAErC,qEAAqE;AACrE,MAAM,eAAe,GAAG,QAAQ,CAAC;AACjC,MAAM,cAAc,GAAG,SAAS,CAAC;AACjC,oEAAoE;AACpE,MAAM,gBAAgB,GAAG,SAAS,CAAC;AACnC,MAAM,eAAe,GAAG,OAAO,CAAC;AAChC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;;;;;;;;GASG;AACH,MAAM,OAAO,cAAc;IAGI;IAFZ,IAAI,GAAG,IAAI,GAAG,EAAU,CAAC;IAE1C,YAA6B,QAAgB,kBAAkB;QAAlC,UAAK,GAAL,KAAK,CAA6B;IAAG,CAAC;IAEnE,KAAK,CAAC,GAAY;QAChB,IAAI,OAAO,GAAG,KAAK,QAAQ;YAAE,OAAO,cAAc,CAAC;QAEnD,MAAM,OAAO,GAAG,GAAG;aAChB,WAAW,EAAE;aACb,OAAO,CAAC,gBAAgB,EAAE,GAAG,CAAC;aAC9B,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC;aACvB,KAAK,CAAC,CAAC,EAAE,iBAAiB,CAAC,CAAC;QAC/B,IAAI,CAAC,OAAO;YAAE,OAAO,cAAc,CAAC;QAEpC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC;Y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CAAC;IACtE,CAAC;IAED,MAAM,OAAO,GAAG,QAAQ,CAAC,yBAAyB,CAAC,CAAC;IACpD,MAAM,IAAI,GAAG,QAAQ,CAAC,oBAAoB,CAAsD,CAAC;IAEjG,OAAO,YAAY,CACjB,IAAI,EAAE,IAAI,EACV,IAAI,EAAE,OAAO,EACb,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,gBAAgB,CACpE,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,SAAS,YAAY,CAAC,IAAa,EAAE,OAAgB,EAAE,QAAgB;IACrE,MAAM,GAAG,GAAG,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAChE,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,GAAG,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;IAE1E,OAAO,GAAG,GAAG,GAAG,KAAK,MAAM,QAAQ,EAAE,CAAC;AACxC,CAAC;AAED,mFAAmF;AACnF,MAAM,eAAe,GAAG,IAAI,cAAc,EAAE,CAAC;AAE7C,2EAA2E;AAC3E,MAAM,UAAU,qBAAqB,CAAC,GAAqB;IACzD,UAAU,EAAE,CAAC,UAAU,CAAC,yBAAyB,EAAE,cAAc,CAAC,GAAG,EAAE,eAAe,CAAC,CAAC,CAAC;AAC3F,CAAC"}
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* - Convert Zod schemas to JSON Schema automatically
|
|
7
7
|
* - Store and retrieve tool handlers
|
|
8
8
|
* - Manage tool lifecycle
|
|
9
|
-
* -
|
|
9
|
+
* - Every registered tool is listed; qase_discover_tools is a search over the catalogue
|
|
10
10
|
*/
|
|
11
11
|
import { Tool, ToolAnnotations } from '@modelcontextprotocol/server';
|
|
12
12
|
import { z } from 'zod';
|
|
@@ -32,8 +32,15 @@ export interface ToolDefinition<T extends z.ZodType = z.ZodType> {
|
|
|
32
32
|
annotations?: ToolAnnotations;
|
|
33
33
|
/** JSON Schema describing the tool's output — enables clients to process results programmatically */
|
|
34
34
|
outputSchema?: OutputSchema;
|
|
35
|
-
/**
|
|
36
|
-
|
|
35
|
+
/**
|
|
36
|
+
* The long documentation, read on demand through qase_tool_help.
|
|
37
|
+
*
|
|
38
|
+
* `description` is sent to the model on every request, so it says what the
|
|
39
|
+
* tool is for and what it costs and stops. Everything else an agent needs
|
|
40
|
+
* before its first call — the traps, the limits, the field semantics — goes
|
|
41
|
+
* here, where it costs nothing until it is asked for.
|
|
42
|
+
*/
|
|
43
|
+
help?: string;
|
|
37
44
|
}
|
|
38
45
|
/**
|
|
39
46
|
* Tool Registry Class
|
|
@@ -42,22 +49,11 @@ export interface ToolDefinition<T extends z.ZodType = z.ZodType> {
|
|
|
42
49
|
export declare class ToolRegistry {
|
|
43
50
|
private tools;
|
|
44
51
|
private handlers;
|
|
45
|
-
private
|
|
46
|
-
private toolVisibility;
|
|
47
|
-
/**
|
|
48
|
-
* Listeners invoked when the active tool set changes (each wired to one
|
|
49
|
-
* Server's sendToolListChanged).
|
|
50
|
-
*
|
|
51
|
-
* A set rather than a single slot because the registry is a process-wide
|
|
52
|
-
* singleton while every HTTP session gets its own Server: with one slot each
|
|
53
|
-
* new session overwrote the previous one's callback, so only the newest
|
|
54
|
-
* session ever heard that discovery had activated a tool.
|
|
55
|
-
*/
|
|
56
|
-
private toolsChangedListeners;
|
|
52
|
+
private help;
|
|
57
53
|
/**
|
|
58
54
|
* Register a new tool with the registry
|
|
59
55
|
*
|
|
60
|
-
* @param definition - Tool definition including name, description, schema
|
|
56
|
+
* @param definition - Tool definition including name, description, schema and handler
|
|
61
57
|
*
|
|
62
58
|
* @example
|
|
63
59
|
* ```typescript
|
|
@@ -67,38 +63,36 @@ export declare class ToolRegistry {
|
|
|
67
63
|
* description: 'Get all projects',
|
|
68
64
|
* schema: z.object({ limit: z.number().optional() }),
|
|
69
65
|
* handler: async (args) => { ... },
|
|
70
|
-
* visibility: 'discoverable', // hidden until discovered
|
|
71
66
|
* });
|
|
72
67
|
* ```
|
|
73
68
|
*/
|
|
74
69
|
register<T extends z.ZodType>(definition: ToolDefinition<T>): void;
|
|
75
70
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
71
|
+
* Every tool, in the shape it takes on the wire. Nothing is hidden: the
|
|
72
|
+
* full list is what a client needs to call any of them, and a client cannot
|
|
73
|
+
* be told about a list that changed on a stateless connection anyway.
|
|
78
74
|
*/
|
|
79
75
|
getTools(): Tool[];
|
|
76
|
+
/** The long documentation of a tool, or undefined when it has none. */
|
|
77
|
+
getHelp(name: string): string | undefined;
|
|
80
78
|
/**
|
|
81
|
-
*
|
|
82
|
-
*
|
|
79
|
+
* Every tool as it was registered, with nothing projected away.
|
|
80
|
+
*
|
|
81
|
+
* This is what code INSIDE the server reads — search, the category filter,
|
|
82
|
+
* the help index. `getTools()` is for the wire and drops annotation hints
|
|
83
|
+
* that match the spec's own defaults, and one of those defaults is
|
|
84
|
+
* `destructiveHint: true`. Reading the wire shape internally therefore said
|
|
85
|
+
* no tool was destructive: `qase_discover_tools` answered `category:
|
|
86
|
+
* "delete"` with nothing and reported `destructive: false` for every
|
|
87
|
+
* deletion it listed. The two shapes are kept apart by name so that cannot
|
|
88
|
+
* be reintroduced by reaching for whichever accessor is nearest.
|
|
83
89
|
*/
|
|
84
|
-
|
|
90
|
+
getDefinitions(): Tool[];
|
|
85
91
|
/**
|
|
86
92
|
* Search tools by name or description (case-insensitive substring match).
|
|
87
93
|
* Searches the full catalog including inactive tools.
|
|
88
94
|
*/
|
|
89
95
|
searchTools(query: string): Tool[];
|
|
90
|
-
/**
|
|
91
|
-
* Subscribe to active-tool-set changes. Returns an unsubscribe function the
|
|
92
|
-
* caller must invoke when its session ends, or the listener — and the Server
|
|
93
|
-
* it closes over — outlives the connection.
|
|
94
|
-
*/
|
|
95
|
-
subscribeToolsChanged(listener: () => void): () => void;
|
|
96
|
-
/**
|
|
97
|
-
* Activate tools by name, making them visible in getTools().
|
|
98
|
-
* Returns the list of newly activated tool names.
|
|
99
|
-
* Notifies every subscriber if any tools were activated.
|
|
100
|
-
*/
|
|
101
|
-
activateTools(names: string[]): string[];
|
|
102
96
|
/**
|
|
103
97
|
* Get handler function for a specific tool
|
|
104
98
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,IAAI,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;;GAGG;AAEH,MAAM,MAAM,WAAW,CAAC,CAAC,GAAG,GAAG,EAAE,CAAC,GAAG,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;AA0CpE,+CAA+C;AAC/C,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,QAAQ,CAAC;IACf,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,cAAc,CAAC,CAAC,SAAS,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO;IAC7D,IAAI,EAAE,MAAM,CAAC;IACb,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CA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