@qase/mcp-server 2.7.5 → 3.0.1
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 +52 -0
- package/README.md +17 -11
- 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.js +2 -0
- 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 +5 -6
- package/build/operations-v2/read/project-context.js.map +1 -1
- package/build/operations-v2/write/attachments.js +16 -21
- 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 +9 -8
- 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 +9 -17
- package/build/transports/body-limit.d.ts.map +1 -1
- package/build/transports/body-limit.js +18 -2
- package/build/transports/body-limit.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.js +1 -1
- package/build/transports/sse.js.map +1 -1
- package/build/transports/streamableHttp.d.ts.map +1 -1
- package/build/transports/streamableHttp.js +83 -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/errors.js +3 -3
- package/build/utils/errors.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/connect.md +23 -7
- package/docs/migration.md +182 -10
- package/docs/self-run.md +50 -7
- package/docs/tools.md +54 -60
- package/docs/troubleshooting.md +43 -16
- package/package.json +11 -12
- package/server.json +2 -2
|
@@ -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;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ve 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;IACp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U,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAMjC;;;;OAIG;IACH,KAAK,IAAI,IAAI;CAId;AAED;;;GAGG;AACH,eAAO,MAAM,YAAY,cAAqB,CAAC;AAE/C;;;GAGG;AACH,eAAO,MAAM,cAAc,EAAE,eAK5B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,eAK9B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,eAK9B,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,eAK9B,CAAC"}
|
package/build/utils/registry.js
CHANGED
|
@@ -1,8 +1,37 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { z } from 'zod';
|
|
2
2
|
/**
|
|
3
3
|
* Tool definition for registration
|
|
4
4
|
* Contains all information needed to register a tool with the MCP server
|
|
5
5
|
*/
|
|
6
|
+
/**
|
|
7
|
+
* `Number.MAX_SAFE_INTEGER`, which zod emits as the bound of every integer.
|
|
8
|
+
*
|
|
9
|
+
* It is true — a JSON number above it loses precision in JavaScript — but it
|
|
10
|
+
* is true of every integer everywhere, so repeating it on all 55 integer
|
|
11
|
+
* fields spends bytes in every tool list to tell the model something that
|
|
12
|
+
* never changes and that no caller of ours is anywhere near. Our integers are
|
|
13
|
+
* record IDs and page sizes.
|
|
14
|
+
*/
|
|
15
|
+
const SAFE_INTEGER_BOUND = 9007199254740991;
|
|
16
|
+
/** Drop that bound wherever zod attached it, in place. */
|
|
17
|
+
function stripSafeIntegerBounds(node) {
|
|
18
|
+
if (Array.isArray(node)) {
|
|
19
|
+
for (const item of node)
|
|
20
|
+
stripSafeIntegerBounds(item);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
if (node === null || typeof node !== 'object')
|
|
24
|
+
return;
|
|
25
|
+
const record = node;
|
|
26
|
+
if (record.type === 'integer') {
|
|
27
|
+
if (record.maximum === SAFE_INTEGER_BOUND)
|
|
28
|
+
delete record.maximum;
|
|
29
|
+
if (record.minimum === -SAFE_INTEGER_BOUND)
|
|
30
|
+
delete record.minimum;
|
|
31
|
+
}
|
|
32
|
+
for (const value of Object.values(record))
|
|
33
|
+
stripSafeIntegerBounds(value);
|
|
34
|
+
}
|
|
6
35
|
/**
|
|
7
36
|
* Sort by `name`, comparing code units rather than by locale: ListTools and
|
|
8
37
|
* ListPrompts must come back in the same order on every host.
|
|
@@ -12,6 +41,35 @@ function byName(a, b) {
|
|
|
12
41
|
return -1;
|
|
13
42
|
return a.name > b.name ? 1 : 0;
|
|
14
43
|
}
|
|
44
|
+
/**
|
|
45
|
+
* Annotation hints as the MCP spec defaults them when a tool says nothing.
|
|
46
|
+
* A hint equal to its default carries no information, so the wire projection
|
|
47
|
+
* leaves it out — the client reads exactly the same meaning either way.
|
|
48
|
+
*/
|
|
49
|
+
const SPEC_DEFAULT_HINTS = {
|
|
50
|
+
readOnlyHint: false,
|
|
51
|
+
destructiveHint: true,
|
|
52
|
+
idempotentHint: false,
|
|
53
|
+
openWorldHint: true,
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* The shape a tool takes on the wire, as opposed to the one the registry
|
|
57
|
+
* stores. Every byte of `tools/list` is sent to the model on every request:
|
|
58
|
+
*
|
|
59
|
+
* - hints equal to the spec defaults are dropped (see SPEC_DEFAULT_HINTS);
|
|
60
|
+
* - `outputSchema` is dropped: no client validates results against it, and
|
|
61
|
+
* its one job here — deciding whether to attach `structuredContent` — is
|
|
62
|
+
* now done for every object result (see server.ts).
|
|
63
|
+
*
|
|
64
|
+
* The stored definition keeps both, because handlers and tests read it.
|
|
65
|
+
*/
|
|
66
|
+
function toWire(tool) {
|
|
67
|
+
const { outputSchema: _omitted, annotations, ...rest } = tool;
|
|
68
|
+
if (!annotations)
|
|
69
|
+
return rest;
|
|
70
|
+
const kept = Object.fromEntries(Object.entries(annotations).filter(([k, v]) => SPEC_DEFAULT_HINTS[k] !== v));
|
|
71
|
+
return Object.keys(kept).length ? { ...rest, annotations: kept } : rest;
|
|
72
|
+
}
|
|
15
73
|
/**
|
|
16
74
|
* Tool Registry Class
|
|
17
75
|
* Manages the lifecycle of MCP tools with support for dynamic discovery
|
|
@@ -19,22 +77,11 @@ function byName(a, b) {
|
|
|
19
77
|
export class ToolRegistry {
|
|
20
78
|
tools = new Map();
|
|
21
79
|
handlers = new Map();
|
|
22
|
-
|
|
23
|
-
toolVisibility = new Map();
|
|
24
|
-
/**
|
|
25
|
-
* Listeners invoked when the active tool set changes (each wired to one
|
|
26
|
-
* Server's sendToolListChanged).
|
|
27
|
-
*
|
|
28
|
-
* A set rather than a single slot because the registry is a process-wide
|
|
29
|
-
* singleton while every HTTP session gets its own Server: with one slot each
|
|
30
|
-
* new session overwrote the previous one's callback, so only the newest
|
|
31
|
-
* session ever heard that discovery had activated a tool.
|
|
32
|
-
*/
|
|
33
|
-
toolsChangedListeners = new Set();
|
|
80
|
+
help = new Map();
|
|
34
81
|
/**
|
|
35
82
|
* Register a new tool with the registry
|
|
36
83
|
*
|
|
37
|
-
* @param definition - Tool definition including name, description, schema
|
|
84
|
+
* @param definition - Tool definition including name, description, schema and handler
|
|
38
85
|
*
|
|
39
86
|
* @example
|
|
40
87
|
* ```typescript
|
|
@@ -44,41 +91,34 @@ export class ToolRegistry {
|
|
|
44
91
|
* description: 'Get all projects',
|
|
45
92
|
* schema: z.object({ limit: z.number().optional() }),
|
|
46
93
|
* handler: async (args) => { ... },
|
|
47
|
-
* visibility: 'discoverable', // hidden until discovered
|
|
48
94
|
* });
|
|
49
95
|
* ```
|
|
50
96
|
*/
|
|
51
97
|
register(definition) {
|
|
52
|
-
const { name, title, description, schema, handler, annotations, outputSchema } = definition;
|
|
53
|
-
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
//
|
|
57
|
-
//
|
|
98
|
+
const { name, title, description, schema, handler, annotations, outputSchema, help } = definition;
|
|
99
|
+
// Convert the Zod schema to JSON Schema for the MCP protocol.
|
|
100
|
+
//
|
|
101
|
+
// `io: 'input'` is what the client is being described: a field with a
|
|
102
|
+
// default is optional on the way in, and a `z.preprocess` is advertised by
|
|
103
|
+
// what it accepts rather than by what it produces.
|
|
104
|
+
//
|
|
105
|
+
// zod emits `$defs` + `$ref` for a schema that refers to itself (the test
|
|
106
|
+
// step tree). That is the only way to express recursion in JSON Schema at
|
|
107
|
+
// all, and the pointers are same-document, which every JSON Schema
|
|
108
|
+
// implementation resolves.
|
|
109
|
+
//
|
|
110
|
+
// Cast through `unknown`: the conversion is value-level, and letting
|
|
111
|
+
// TypeScript infer it across our deepest schemas trips "excessively deep".
|
|
58
112
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
-
const
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const definitionKey = Object.keys(jsonSchema.definitions)[0];
|
|
69
|
-
inputSchema = jsonSchema.definitions[definitionKey];
|
|
70
|
-
}
|
|
71
|
-
else if (jsonSchema.type === 'object') {
|
|
72
|
-
// Use directly
|
|
73
|
-
inputSchema = jsonSchema;
|
|
74
|
-
}
|
|
75
|
-
else {
|
|
76
|
-
// Fallback: create minimal object schema
|
|
77
|
-
inputSchema = {
|
|
78
|
-
type: 'object',
|
|
79
|
-
properties: {},
|
|
80
|
-
};
|
|
81
|
-
}
|
|
113
|
+
const converted = z.toJSONSchema(schema, { io: 'input' });
|
|
114
|
+
// `$schema` says which dialect the document is written in. The tool list
|
|
115
|
+
// repeats it in all 42 schemas and no client reads it, so it is dropped —
|
|
116
|
+
// the MCP spec already fixes the dialect for `inputSchema`.
|
|
117
|
+
const { $schema: _dialect, ...body } = converted;
|
|
118
|
+
stripSafeIntegerBounds(body);
|
|
119
|
+
const inputSchema = body.type === 'object'
|
|
120
|
+
? body
|
|
121
|
+
: { type: 'object', properties: {} };
|
|
82
122
|
// Store tool definition
|
|
83
123
|
this.tools.set(name, {
|
|
84
124
|
name,
|
|
@@ -90,28 +130,36 @@ export class ToolRegistry {
|
|
|
90
130
|
});
|
|
91
131
|
// Store handler function
|
|
92
132
|
this.handlers.set(name, handler);
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
if (visibility === 'core') {
|
|
96
|
-
this.activeTools.add(name);
|
|
97
|
-
}
|
|
133
|
+
if (help)
|
|
134
|
+
this.help.set(name, help);
|
|
98
135
|
// Log registration for debugging (to stderr)
|
|
99
|
-
console.error(`[Registry] Registered tool: ${name}
|
|
136
|
+
console.error(`[Registry] Registered tool: ${name}`);
|
|
100
137
|
}
|
|
101
138
|
/**
|
|
102
|
-
*
|
|
103
|
-
*
|
|
139
|
+
* Every tool, in the shape it takes on the wire. Nothing is hidden: the
|
|
140
|
+
* full list is what a client needs to call any of them, and a client cannot
|
|
141
|
+
* be told about a list that changed on a stateless connection anyway.
|
|
104
142
|
*/
|
|
105
143
|
getTools() {
|
|
106
|
-
return
|
|
107
|
-
|
|
108
|
-
|
|
144
|
+
return this.getDefinitions().map(toWire);
|
|
145
|
+
}
|
|
146
|
+
/** The long documentation of a tool, or undefined when it has none. */
|
|
147
|
+
getHelp(name) {
|
|
148
|
+
return this.help.get(name);
|
|
109
149
|
}
|
|
110
150
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
151
|
+
* Every tool as it was registered, with nothing projected away.
|
|
152
|
+
*
|
|
153
|
+
* This is what code INSIDE the server reads — search, the category filter,
|
|
154
|
+
* the help index. `getTools()` is for the wire and drops annotation hints
|
|
155
|
+
* that match the spec's own defaults, and one of those defaults is
|
|
156
|
+
* `destructiveHint: true`. Reading the wire shape internally therefore said
|
|
157
|
+
* no tool was destructive: `qase_discover_tools` answered `category:
|
|
158
|
+
* "delete"` with nothing and reported `destructive: false` for every
|
|
159
|
+
* deletion it listed. The two shapes are kept apart by name so that cannot
|
|
160
|
+
* be reintroduced by reaching for whichever accessor is nearest.
|
|
113
161
|
*/
|
|
114
|
-
|
|
162
|
+
getDefinitions() {
|
|
115
163
|
return Array.from(this.tools.values()).sort(byName);
|
|
116
164
|
}
|
|
117
165
|
/**
|
|
@@ -126,49 +174,11 @@ export class ToolRegistry {
|
|
|
126
174
|
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
127
175
|
if (words.length === 0)
|
|
128
176
|
return [];
|
|
129
|
-
return this.
|
|
177
|
+
return this.getDefinitions().filter((t) => {
|
|
130
178
|
const haystack = `${t.name} ${t.description ?? ''}`.toLowerCase();
|
|
131
179
|
return words.every((word) => haystack.includes(word));
|
|
132
180
|
});
|
|
133
181
|
}
|
|
134
|
-
/**
|
|
135
|
-
* Subscribe to active-tool-set changes. Returns an unsubscribe function the
|
|
136
|
-
* caller must invoke when its session ends, or the listener — and the Server
|
|
137
|
-
* it closes over — outlives the connection.
|
|
138
|
-
*/
|
|
139
|
-
subscribeToolsChanged(listener) {
|
|
140
|
-
this.toolsChangedListeners.add(listener);
|
|
141
|
-
return () => {
|
|
142
|
-
this.toolsChangedListeners.delete(listener);
|
|
143
|
-
};
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Activate tools by name, making them visible in getTools().
|
|
147
|
-
* Returns the list of newly activated tool names.
|
|
148
|
-
* Notifies every subscriber if any tools were activated.
|
|
149
|
-
*/
|
|
150
|
-
activateTools(names) {
|
|
151
|
-
const newlyActivated = [];
|
|
152
|
-
for (const name of names) {
|
|
153
|
-
if (this.tools.has(name) && !this.activeTools.has(name)) {
|
|
154
|
-
this.activeTools.add(name);
|
|
155
|
-
newlyActivated.push(name);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
if (newlyActivated.length > 0) {
|
|
159
|
-
for (const listener of this.toolsChangedListeners) {
|
|
160
|
-
// One dead session's transport must not swallow the notification for
|
|
161
|
-
// every session subscribed after it.
|
|
162
|
-
try {
|
|
163
|
-
listener();
|
|
164
|
-
}
|
|
165
|
-
catch (err) {
|
|
166
|
-
console.error('[Registry] Tool-list-changed listener failed:', err);
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
return newlyActivated;
|
|
171
|
-
}
|
|
172
182
|
/**
|
|
173
183
|
* Get handler function for a specific tool
|
|
174
184
|
*
|
|
@@ -209,8 +219,6 @@ export class ToolRegistry {
|
|
|
209
219
|
unregister(name) {
|
|
210
220
|
const hadTool = this.tools.delete(name);
|
|
211
221
|
this.handlers.delete(name);
|
|
212
|
-
this.activeTools.delete(name);
|
|
213
|
-
this.toolVisibility.delete(name);
|
|
214
222
|
return hadTool;
|
|
215
223
|
}
|
|
216
224
|
/**
|
|
@@ -221,9 +229,6 @@ export class ToolRegistry {
|
|
|
221
229
|
clear() {
|
|
222
230
|
this.tools.clear();
|
|
223
231
|
this.handlers.clear();
|
|
224
|
-
this.activeTools.clear();
|
|
225
|
-
this.toolVisibility.clear();
|
|
226
|
-
this.toolsChangedListeners.clear();
|
|
227
232
|
}
|
|
228
233
|
}
|
|
229
234
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/utils/registry.ts"],"names":[],"mappings":"AAWA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AASxB;;;GAGG;AACH;;;;;;;;GAQG;AACH,MAAM,kBAAkB,GAAG,gBAAgB,CAAC;AAE5C,0DAA0D;AAC1D,SAAS,sBAAsB,CAAC,IAAa;IAC3C,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,KAAK,MAAM,IAAI,IAAI,IAAI;YAAE,sBAAsB,CAAC,IAAI,CAAC,CAAC;QACtD,OAAO;IACT,CAAC;IACD,IAAI,IAAI,KAAK,IAAI,IAAI,OAAO,IAAI,KAAK,QAAQ;QAAE,OAAO;IAEtD,MAAM,MAAM,GAAG,IAA+B,CAAC;IAC/C,IAAI,MAAM,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;QAC9B,IAAI,MAAM,CAAC,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