@smartbear/mcp 0.43.0 → 0.44.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/dist/bugsnag/client.js +14 -2
- package/dist/common/config-names.js +12 -0
- package/dist/common/info.js +2 -0
- package/dist/common/list-integrations.js +53 -0
- package/dist/common/server.js +64 -2
- package/dist/common/transport-http.js +92 -32
- package/dist/common/transport-stdio.js +1 -6
- package/dist/package.json.js +1 -1
- package/dist/zephyr/tool/test-case/create-web-link.js +17 -2
- package/dist/zephyr/tool/test-cycle/create-web-link.js +18 -2
- package/package.json +3 -1
- package/src/pactflow/drift/README.md +91 -0
package/dist/bugsnag/client.js
CHANGED
|
@@ -2,7 +2,7 @@ import { createHmac } from "node:crypto";
|
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
import { CacheService } from "../common/cache.js";
|
|
4
4
|
import { getUserAgent } from "../common/info.js";
|
|
5
|
-
import { getRequestHeader } from "../common/request-context.js";
|
|
5
|
+
import { getRequestContext, getRequestHeader } from "../common/request-context.js";
|
|
6
6
|
import { ToolError } from "../common/tools.js";
|
|
7
7
|
import { CurrentUserAPI } from "./client/api/CurrentUser.js";
|
|
8
8
|
import { Configuration } from "./client/api/configuration.js";
|
|
@@ -138,9 +138,21 @@ class BugsnagClient {
|
|
|
138
138
|
config.endpoint
|
|
139
139
|
);
|
|
140
140
|
this._projectApiKey = config.project_api_key;
|
|
141
|
-
this._authToken = config.auth_token;
|
|
141
|
+
this._authToken = this.isOperatorToken(config.auth_token) ? config.auth_token : void 0;
|
|
142
142
|
await this.initializeApis(config);
|
|
143
143
|
}
|
|
144
|
+
// A session identifier is not a credential, so a token a caller presented while
|
|
145
|
+
// opening an HTTP session must not outlive that request. Only a process-level
|
|
146
|
+
// token (stdio, or the operator's env var) may serve later requests.
|
|
147
|
+
isOperatorToken(token) {
|
|
148
|
+
if (!token) {
|
|
149
|
+
return false;
|
|
150
|
+
}
|
|
151
|
+
if (!getRequestContext()) {
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
return token === process.env.BUGSNAG_AUTH_TOKEN;
|
|
155
|
+
}
|
|
144
156
|
getProjectApiKey() {
|
|
145
157
|
const contextHeader = getRequestHeader("Bugsnag-Project-Api-Key");
|
|
146
158
|
const requestProjectApiKey = Array.isArray(contextHeader) ? contextHeader[0] : contextHeader;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
function getEnvVarName(clientPrefix, key) {
|
|
2
|
+
return `${clientPrefix.toUpperCase().replace(/-/g, "_")}_${key.toUpperCase()}`;
|
|
3
|
+
}
|
|
4
|
+
function getHeaderName(clientPrefix, key) {
|
|
5
|
+
return `${clientPrefix}-${key.split("_").map(
|
|
6
|
+
(part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()
|
|
7
|
+
).join("-")}`;
|
|
8
|
+
}
|
|
9
|
+
export {
|
|
10
|
+
getEnvVarName,
|
|
11
|
+
getHeaderName
|
|
12
|
+
};
|
package/dist/common/info.js
CHANGED
|
@@ -2,6 +2,7 @@ import packageJson from "../package.json.js";
|
|
|
2
2
|
import { getCurrentClientIdentity } from "./client-identity.js";
|
|
3
3
|
const MCP_SERVER_NAME = packageJson.config.mcpServerName;
|
|
4
4
|
const MCP_SERVER_VERSION = packageJson.version;
|
|
5
|
+
const MCP_SERVER_INSTRUCTIONS = "SmartBear MCP Server: debugging and monitoring (BugSnag), API design and contract testing (Swagger, PactFlow), test management and execution (QMetry, QTM4J, Zephyr, Reflect, BearQ), and code review (Collaborator). Only tools for products with valid, configured credentials are registered. Call smartbear_list_integrations to see what's active and what each unconfigured product needs.";
|
|
5
6
|
const MCP_TRANSPORT = process.env.MCP_TRANSPORT?.toLowerCase().trim() || "stdio";
|
|
6
7
|
const USER_AGENT = `${MCP_SERVER_NAME}/${MCP_SERVER_VERSION} ${MCP_TRANSPORT}`;
|
|
7
8
|
function sanitizeUserAgentToken(value) {
|
|
@@ -22,6 +23,7 @@ function getUserAgent() {
|
|
|
22
23
|
return appendClientIdentity(USER_AGENT);
|
|
23
24
|
}
|
|
24
25
|
export {
|
|
26
|
+
MCP_SERVER_INSTRUCTIONS,
|
|
25
27
|
MCP_SERVER_NAME,
|
|
26
28
|
MCP_SERVER_VERSION,
|
|
27
29
|
MCP_TRANSPORT,
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { clientRegistry } from "./client-registry.js";
|
|
2
|
+
import { getHeaderName, getEnvVarName } from "./config-names.js";
|
|
3
|
+
import { getTypeDescription, isOptionalType } from "./zod-utils.js";
|
|
4
|
+
const LIST_INTEGRATIONS_TOOL_NAME = "smartbear_list_integrations";
|
|
5
|
+
const INTEGRATION_DESCRIPTIONS = {
|
|
6
|
+
BugSnag: "Error monitoring and stability data for your applications.",
|
|
7
|
+
Swagger: "API design, hosting and governance with SwaggerHub.",
|
|
8
|
+
"Contract Testing": "Consumer-driven contract testing and can-i-deploy checks with PactFlow.",
|
|
9
|
+
QMetry: "Test case management and execution with QMetry.",
|
|
10
|
+
QTM4J: "Test case management and execution in Jira with QMetry QTM4J.",
|
|
11
|
+
Zephyr: "Test case management and execution tracking.",
|
|
12
|
+
Reflect: "No-code web test automation and test runs.",
|
|
13
|
+
BearQ: "AI-driven test creation and execution.",
|
|
14
|
+
Collaborator: "Peer code and document review."
|
|
15
|
+
};
|
|
16
|
+
function buildIntegrationsReport(server) {
|
|
17
|
+
const added = server.getClients();
|
|
18
|
+
const integrations = clientRegistry.getAll().map((catalogClient) => {
|
|
19
|
+
const product = catalogClient.name;
|
|
20
|
+
const description = INTEGRATION_DESCRIPTIONS[product] ?? "No description available.";
|
|
21
|
+
const active = added.find((c) => c.name === product);
|
|
22
|
+
if (active?.isConfigured()) {
|
|
23
|
+
const toolsets = server.getToolsetStats(product);
|
|
24
|
+
return {
|
|
25
|
+
product,
|
|
26
|
+
description,
|
|
27
|
+
configured: true,
|
|
28
|
+
toolCount: toolsets.reduce(
|
|
29
|
+
(sum, ts) => sum + (ts.enabled ? ts.toolCount : 0),
|
|
30
|
+
0
|
|
31
|
+
),
|
|
32
|
+
toolsets
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
return {
|
|
36
|
+
product,
|
|
37
|
+
description,
|
|
38
|
+
configured: false,
|
|
39
|
+
setup: Object.entries(catalogClient.config.shape).map(([key, type]) => ({
|
|
40
|
+
envVar: getEnvVarName(catalogClient.configPrefix, key),
|
|
41
|
+
header: getHeaderName(catalogClient.configPrefix, key),
|
|
42
|
+
required: !isOptionalType(type),
|
|
43
|
+
description: getTypeDescription(type) ?? ""
|
|
44
|
+
}))
|
|
45
|
+
};
|
|
46
|
+
});
|
|
47
|
+
return { integrations };
|
|
48
|
+
}
|
|
49
|
+
export {
|
|
50
|
+
INTEGRATION_DESCRIPTIONS,
|
|
51
|
+
LIST_INTEGRATIONS_TOOL_NAME,
|
|
52
|
+
buildIntegrationsReport
|
|
53
|
+
};
|
package/dist/common/server.js
CHANGED
|
@@ -4,7 +4,8 @@ import Bugsnag from "./bugsnag.js";
|
|
|
4
4
|
import { errorTypeOf, trackToolCalled } from "./analytics.js";
|
|
5
5
|
import { isCachingEnabled, CacheService, getConfiguredCacheTtlSeconds } from "./cache.js";
|
|
6
6
|
import { toClientIdentity, getCurrentClientIdentity } from "./client-identity.js";
|
|
7
|
-
import { MCP_SERVER_VERSION, MCP_SERVER_NAME } from "./info.js";
|
|
7
|
+
import { MCP_SERVER_VERSION, MCP_SERVER_NAME, MCP_SERVER_INSTRUCTIONS } from "./info.js";
|
|
8
|
+
import { LIST_INTEGRATIONS_TOOL_NAME, buildIntegrationsReport } from "./list-integrations.js";
|
|
8
9
|
import { runWithElicitationScope, InputRequiredSignal, executeElicitationOrPolyfill, isElicitationPolyfillResult } from "./pollyfills.js";
|
|
9
10
|
import { getRequestEra, getRequestClientMeta } from "./request-context.js";
|
|
10
11
|
import { ToolError } from "./tools.js";
|
|
@@ -30,6 +31,8 @@ class SmartBearMcpServer extends McpServer {
|
|
|
30
31
|
enabledToolsets;
|
|
31
32
|
mcpClientIdentity;
|
|
32
33
|
analyticsSession;
|
|
34
|
+
/** Per client name: every tool the client offered, bucketed by toolset. */
|
|
35
|
+
toolsetStats = /* @__PURE__ */ new Map();
|
|
33
36
|
constructor(enabledToolsets, era = "legacy") {
|
|
34
37
|
super(
|
|
35
38
|
{
|
|
@@ -37,6 +40,8 @@ class SmartBearMcpServer extends McpServer {
|
|
|
37
40
|
version: MCP_SERVER_VERSION
|
|
38
41
|
},
|
|
39
42
|
{
|
|
43
|
+
// Static text, identical for every session, era and transport.
|
|
44
|
+
instructions: MCP_SERVER_INSTRUCTIONS,
|
|
40
45
|
capabilities: era === "modern" ? {
|
|
41
46
|
// resources and prompts are supported by some but not all clients.
|
|
42
47
|
// No `logging`: deprecated by SEP-2577 as of 2026-07-28 (our
|
|
@@ -69,6 +74,48 @@ class SmartBearMcpServer extends McpServer {
|
|
|
69
74
|
if (enabledToolsets) {
|
|
70
75
|
this.enabledToolsets = enabledToolsets.split(",").map((s) => s.trim().toLowerCase());
|
|
71
76
|
}
|
|
77
|
+
this.registerListIntegrationsTool();
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Registered unconditionally (not via addClient) so it exists even when no
|
|
81
|
+
* product is configured. Reads only in-memory metadata, so it never needs
|
|
82
|
+
* credentials and never throws a ToolError for missing configuration.
|
|
83
|
+
*/
|
|
84
|
+
registerListIntegrationsTool() {
|
|
85
|
+
this.registerTool(
|
|
86
|
+
LIST_INTEGRATIONS_TOOL_NAME,
|
|
87
|
+
{
|
|
88
|
+
title: "SmartBear: List Integrations",
|
|
89
|
+
description: "Lists every SmartBear product this server supports, whether it is configured for this connection, and for unconfigured products the environment variable or HTTP header each setting needs. Only products allowed by the server's MCP_CLIENTS setting are listed. Products that accept per-request OAuth tokens (BearQ, Reflect, QMetry) always show as configured. Takes no parameters.",
|
|
90
|
+
inputSchema: z.object({}),
|
|
91
|
+
annotations: {
|
|
92
|
+
title: "SmartBear: List Integrations",
|
|
93
|
+
readOnlyHint: true,
|
|
94
|
+
destructiveHint: false,
|
|
95
|
+
idempotentHint: true,
|
|
96
|
+
openWorldHint: false
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
async () => ({
|
|
100
|
+
content: [
|
|
101
|
+
{
|
|
102
|
+
type: "text",
|
|
103
|
+
text: JSON.stringify(buildIntegrationsReport(this), null, 2)
|
|
104
|
+
}
|
|
105
|
+
]
|
|
106
|
+
})
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Toolset breakdown for a client: the full potential tool count per toolset
|
|
111
|
+
* and whether the toolset is enabled (so hidden tools are visible).
|
|
112
|
+
*/
|
|
113
|
+
getToolsetStats(clientName) {
|
|
114
|
+
return [...this.toolsetStats.get(clientName) ?? []].map(([name, { total, enabled }]) => ({
|
|
115
|
+
name,
|
|
116
|
+
toolCount: total,
|
|
117
|
+
enabled: enabled > 0
|
|
118
|
+
})).sort((a, b) => a.name.localeCompare(b.name));
|
|
72
119
|
}
|
|
73
120
|
getCache() {
|
|
74
121
|
return this.cache;
|
|
@@ -170,7 +217,9 @@ class SmartBearMcpServer extends McpServer {
|
|
|
170
217
|
this.clients.push(client);
|
|
171
218
|
await client.registerTools(
|
|
172
219
|
(params, cb) => {
|
|
173
|
-
|
|
220
|
+
const enabled = this.isToolEnabled(client, params.toolset);
|
|
221
|
+
this.recordToolset(client.name, params.toolset, enabled);
|
|
222
|
+
if (!enabled) {
|
|
174
223
|
return null;
|
|
175
224
|
}
|
|
176
225
|
const toolName = this.getCapabilityName(client, params.title);
|
|
@@ -329,6 +378,19 @@ ${result.instructions}`
|
|
|
329
378
|
}
|
|
330
379
|
this.sortToolsDeterministically();
|
|
331
380
|
}
|
|
381
|
+
recordToolset(clientName, toolset, enabled) {
|
|
382
|
+
let byToolset = this.toolsetStats.get(clientName);
|
|
383
|
+
if (!byToolset) {
|
|
384
|
+
byToolset = /* @__PURE__ */ new Map();
|
|
385
|
+
this.toolsetStats.set(clientName, byToolset);
|
|
386
|
+
}
|
|
387
|
+
const stats = byToolset.get(toolset) ?? { total: 0, enabled: 0 };
|
|
388
|
+
stats.total++;
|
|
389
|
+
if (enabled) {
|
|
390
|
+
stats.enabled++;
|
|
391
|
+
}
|
|
392
|
+
byToolset.set(toolset, stats);
|
|
393
|
+
}
|
|
332
394
|
/**
|
|
333
395
|
* Re-key the SDK's tool registry alphabetically so `tools/list` output is
|
|
334
396
|
* deterministic regardless of client registration order.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
2
|
-
import { randomUUID } from "node:crypto";
|
|
2
|
+
import { randomBytes, randomUUID, createHmac } from "node:crypto";
|
|
3
3
|
import { createServer } from "node:http";
|
|
4
4
|
import querystring from "node:querystring";
|
|
5
5
|
import { toNodeHandler, toWebRequest, NodeStreamableHTTPServerTransport } from "@modelcontextprotocol/node";
|
|
@@ -7,13 +7,64 @@ import { createMcpHandler, isLegacyRequest, isInitializeRequest } from "@modelco
|
|
|
7
7
|
import { SSEServerTransport } from "@modelcontextprotocol/server-legacy/sse";
|
|
8
8
|
import { initAnalytics, isToolsListRequest, trackToolsListed, createAnalyticsSession, flushAnalytics } from "./analytics.js";
|
|
9
9
|
import { clientRegistry } from "./client-registry.js";
|
|
10
|
+
import { getHeaderName, getEnvVarName } from "./config-names.js";
|
|
10
11
|
import { MCP_SERVER_VERSION } from "./info.js";
|
|
11
12
|
import { extractModernClientMeta, handleInitializeMessage } from "./initialize.js";
|
|
12
13
|
import { withRequestHeaders, withRequestContext, setRequestMcpClient, setModernRequestClient } from "./request-context.js";
|
|
13
14
|
import { SmartBearMcpServer } from "./server.js";
|
|
14
15
|
import { registerShutdownHandler, isDraining } from "./shutdown.js";
|
|
15
|
-
import
|
|
16
|
+
import "node:module";
|
|
17
|
+
import "@modelcontextprotocol/server/stdio";
|
|
16
18
|
import { isOptionalType, getTypeDescription } from "./zod-utils.js";
|
|
19
|
+
const IDENTITY_KEY = randomBytes(32);
|
|
20
|
+
function resolveCredentialIdentity(server) {
|
|
21
|
+
const parts = [];
|
|
22
|
+
for (const client of server.getClients()) {
|
|
23
|
+
const token = client.getAuthToken?.();
|
|
24
|
+
if (token) {
|
|
25
|
+
parts.push(
|
|
26
|
+
`${client.capabilityPrefix}:${token.replace(/^Bearer\s+/i, "")}`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (parts.length === 0) {
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
return createHmac("sha256", IDENTITY_KEY).update(parts.join("\0")).digest("hex");
|
|
34
|
+
}
|
|
35
|
+
function requestIdentity(req, server) {
|
|
36
|
+
return withRequestContext(req, () => resolveCredentialIdentity(server));
|
|
37
|
+
}
|
|
38
|
+
function writeSessionNotFound(res) {
|
|
39
|
+
res.writeHead(404, { "Content-Type": "application/json" });
|
|
40
|
+
res.end(
|
|
41
|
+
JSON.stringify({
|
|
42
|
+
jsonrpc: "2.0",
|
|
43
|
+
error: {
|
|
44
|
+
code: -32001,
|
|
45
|
+
message: "Session not found"
|
|
46
|
+
},
|
|
47
|
+
id: null
|
|
48
|
+
})
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
function authorizeSessionRequest(req, res, entry, notFound = writeSessionNotFound) {
|
|
52
|
+
if (!entry.identity) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
const current = requestIdentity(req, entry.server);
|
|
56
|
+
if (current === entry.identity) {
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
req.resume();
|
|
60
|
+
if (current === null) {
|
|
61
|
+
res.writeHead(401, unauthorizedHeaders(req.headers, req.headers.host));
|
|
62
|
+
res.end("Unauthorized: credentials are required on every request");
|
|
63
|
+
} else {
|
|
64
|
+
notFound(res);
|
|
65
|
+
}
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
17
68
|
const PROBE_HEADERS = {
|
|
18
69
|
"Content-Type": "application/json",
|
|
19
70
|
"Cache-Control": "no-store"
|
|
@@ -243,18 +294,23 @@ async function createNewTransport(req, res, transports) {
|
|
|
243
294
|
if (!server) {
|
|
244
295
|
return null;
|
|
245
296
|
}
|
|
297
|
+
const identity = requestIdentity(req, server) ?? void 0;
|
|
246
298
|
const transport = new NodeStreamableHTTPServerTransport({
|
|
247
299
|
sessionIdGenerator: () => randomUUID(),
|
|
248
300
|
onsessioninitialized: (newSessionId) => {
|
|
249
|
-
console.log(
|
|
250
|
-
|
|
301
|
+
console.log(
|
|
302
|
+
`[MCP] New session initialized: ${redactSessionId(newSessionId)}`
|
|
303
|
+
);
|
|
304
|
+
transports.set(newSessionId, { server, transport, identity });
|
|
251
305
|
attachSessionAnalytics(server, newSessionId, "streamable-http");
|
|
252
306
|
}
|
|
253
307
|
});
|
|
254
308
|
transport.onmessage = (message) => handleSessionMessage(server, message);
|
|
255
309
|
transport.onclose = () => {
|
|
256
310
|
if (transport.sessionId) {
|
|
257
|
-
console.log(
|
|
311
|
+
console.log(
|
|
312
|
+
`[MCP] Session closed: ${redactSessionId(transport.sessionId)}`
|
|
313
|
+
);
|
|
258
314
|
transports.delete(transport.sessionId);
|
|
259
315
|
endSessionAnalytics(server);
|
|
260
316
|
server.cleanupSession(transport.sessionId);
|
|
@@ -263,6 +319,9 @@ async function createNewTransport(req, res, transports) {
|
|
|
263
319
|
await server.connect(transport);
|
|
264
320
|
return transport;
|
|
265
321
|
}
|
|
322
|
+
function redactSessionId(sessionId) {
|
|
323
|
+
return `${sessionId.slice(0, 8)}...`;
|
|
324
|
+
}
|
|
266
325
|
function handleSessionMessage(server, message) {
|
|
267
326
|
handleInitializeMessage(server, message);
|
|
268
327
|
if (isToolsListRequest(message)) {
|
|
@@ -349,19 +408,13 @@ function extractModernClientMetaFromBody(parsedBody) {
|
|
|
349
408
|
async function handleStreamableHttpRequest(req, res, transports, preParsed) {
|
|
350
409
|
try {
|
|
351
410
|
const sessionId = req.headers["mcp-session-id"];
|
|
352
|
-
|
|
411
|
+
const sessionEntry = sessionId ? transports.get(sessionId) : void 0;
|
|
412
|
+
if (sessionId && !sessionEntry) {
|
|
353
413
|
req.resume();
|
|
354
|
-
res
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
error: {
|
|
359
|
-
code: -32001,
|
|
360
|
-
message: "Session not found"
|
|
361
|
-
},
|
|
362
|
-
id: null
|
|
363
|
-
})
|
|
364
|
-
);
|
|
414
|
+
writeSessionNotFound(res);
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
if (sessionEntry && !authorizeSessionRequest(req, res, sessionEntry)) {
|
|
365
418
|
return;
|
|
366
419
|
}
|
|
367
420
|
const parsedBody = preParsed ? preParsed.body : await parseRequestBody(req);
|
|
@@ -410,9 +463,10 @@ async function handleLegacySseRequest(req, res, transports) {
|
|
|
410
463
|
if (!server) {
|
|
411
464
|
return;
|
|
412
465
|
}
|
|
466
|
+
const identity = requestIdentity(req, server) ?? void 0;
|
|
413
467
|
const transport = new SSEServerTransport("/message", res);
|
|
414
468
|
transport.onmessage = (message) => handleSessionMessage(server, message);
|
|
415
|
-
transports.set(transport.sessionId, { server, transport });
|
|
469
|
+
transports.set(transport.sessionId, { server, transport, identity });
|
|
416
470
|
attachSessionAnalytics(server, transport.sessionId, "sse");
|
|
417
471
|
res.on("close", () => {
|
|
418
472
|
transports.delete(transport.sessionId);
|
|
@@ -421,6 +475,10 @@ async function handleLegacySseRequest(req, res, transports) {
|
|
|
421
475
|
});
|
|
422
476
|
await server.connect(transport);
|
|
423
477
|
}
|
|
478
|
+
function writeLegacySessionNotFound(res) {
|
|
479
|
+
res.writeHead(404, { "Content-Type": "text/plain" });
|
|
480
|
+
res.end("Session not found");
|
|
481
|
+
}
|
|
424
482
|
async function handleLegacyMessageRequest(req, res, url, transports) {
|
|
425
483
|
const sessionId = url.searchParams.get("sessionId");
|
|
426
484
|
if (!sessionId) {
|
|
@@ -430,8 +488,7 @@ async function handleLegacyMessageRequest(req, res, url, transports) {
|
|
|
430
488
|
}
|
|
431
489
|
const session = transports.get(sessionId);
|
|
432
490
|
if (!session) {
|
|
433
|
-
res
|
|
434
|
-
res.end("Session not found");
|
|
491
|
+
writeLegacySessionNotFound(res);
|
|
435
492
|
return;
|
|
436
493
|
}
|
|
437
494
|
if (!(session.transport instanceof SSEServerTransport)) {
|
|
@@ -439,6 +496,9 @@ async function handleLegacyMessageRequest(req, res, url, transports) {
|
|
|
439
496
|
res.end("Invalid transport for this endpoint");
|
|
440
497
|
return;
|
|
441
498
|
}
|
|
499
|
+
if (!authorizeSessionRequest(req, res, session, writeLegacySessionNotFound)) {
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
442
502
|
let body = "";
|
|
443
503
|
req.on("data", (chunk) => {
|
|
444
504
|
body += chunk.toString();
|
|
@@ -528,18 +588,21 @@ async function buildConfiguredServer(getConfig, headers, host, res, era) {
|
|
|
528
588
|
const headerHelp = getHttpHeadersHelp();
|
|
529
589
|
const errorMessage = headerHelp.length > 0 ? `Configuration error: ${error instanceof Error ? error.message : String(error)}. Please provide valid headers:
|
|
530
590
|
${headerHelp.join("\n")}` : "No clients support HTTP header configuration.";
|
|
531
|
-
|
|
532
|
-
"Content-Type": "text/plain"
|
|
533
|
-
};
|
|
534
|
-
if (process.env.BASE_URL || host) {
|
|
535
|
-
responseHeaders["WWW-Authenticate"] = `OAuth resource_metadata="${getBaseUrlFromHeaders(headers)}/.well-known/oauth-protected-resource"`;
|
|
536
|
-
}
|
|
537
|
-
res.writeHead(401, responseHeaders);
|
|
591
|
+
res.writeHead(401, unauthorizedHeaders(headers, host));
|
|
538
592
|
res.end(errorMessage);
|
|
539
593
|
return null;
|
|
540
594
|
}
|
|
541
595
|
return server;
|
|
542
596
|
}
|
|
597
|
+
function unauthorizedHeaders(headers, host) {
|
|
598
|
+
const responseHeaders = {
|
|
599
|
+
"Content-Type": "text/plain"
|
|
600
|
+
};
|
|
601
|
+
if (process.env.BASE_URL || host) {
|
|
602
|
+
responseHeaders["WWW-Authenticate"] = `OAuth resource_metadata="${getBaseUrlFromHeaders(headers)}/.well-known/oauth-protected-resource"`;
|
|
603
|
+
}
|
|
604
|
+
return responseHeaders;
|
|
605
|
+
}
|
|
543
606
|
async function newServer(req, res) {
|
|
544
607
|
return buildConfiguredServer(
|
|
545
608
|
(clientPrefix, key) => getConfigValue(clientPrefix, key, req),
|
|
@@ -558,11 +621,6 @@ async function newServerFromWebRequest(request, res) {
|
|
|
558
621
|
"modern"
|
|
559
622
|
);
|
|
560
623
|
}
|
|
561
|
-
function getHeaderName(clientPrefix, key) {
|
|
562
|
-
return `${clientPrefix}-${key.split("_").map(
|
|
563
|
-
(part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()
|
|
564
|
-
).join("-")}`;
|
|
565
|
-
}
|
|
566
624
|
function getQueryStringName(clientPrefix, key) {
|
|
567
625
|
return `${clientPrefix.toLowerCase()}${key.split("_").map(
|
|
568
626
|
(part) => part.charAt(0).toUpperCase() + part.slice(1).toLowerCase()
|
|
@@ -593,6 +651,7 @@ function getHttpHeadersHelp() {
|
|
|
593
651
|
}
|
|
594
652
|
export {
|
|
595
653
|
attachSessionAnalytics,
|
|
654
|
+
authorizeSessionRequest,
|
|
596
655
|
drainHttpTransport,
|
|
597
656
|
endSessionAnalytics,
|
|
598
657
|
getBaseUrl,
|
|
@@ -605,5 +664,6 @@ export {
|
|
|
605
664
|
handleStreamableHttpRequest,
|
|
606
665
|
newServer,
|
|
607
666
|
newServerFromWebRequest,
|
|
667
|
+
resolveCredentialIdentity,
|
|
608
668
|
runHttpMode
|
|
609
669
|
};
|
|
@@ -2,6 +2,7 @@ import { enableCompileCache } from "node:module";
|
|
|
2
2
|
import { StdioServerTransport, serveStdio } from "@modelcontextprotocol/server/stdio";
|
|
3
3
|
import { setProcessClientIdentity, toClientIdentity } from "./client-identity.js";
|
|
4
4
|
import { clientRegistry } from "./client-registry.js";
|
|
5
|
+
import { getEnvVarName } from "./config-names.js";
|
|
5
6
|
import { USER_AGENT } from "./info.js";
|
|
6
7
|
import { handleInitializeMessage, extractModernClientMeta } from "./initialize.js";
|
|
7
8
|
import { SmartBearMcpServer } from "./server.js";
|
|
@@ -36,9 +37,6 @@ async function buildStdioServer(era = "legacy") {
|
|
|
36
37
|
message.length > 0 ? `No clients configured. Please provide valid environment variables for at least one client:
|
|
37
38
|
${message.join("\n")}` : "No clients support environment variable configuration."
|
|
38
39
|
);
|
|
39
|
-
for (const entry of clientRegistry.getAll()) {
|
|
40
|
-
await server.addClient(entry);
|
|
41
|
-
}
|
|
42
40
|
}
|
|
43
41
|
return server;
|
|
44
42
|
}
|
|
@@ -119,9 +117,6 @@ async function runStdioMode() {
|
|
|
119
117
|
}
|
|
120
118
|
});
|
|
121
119
|
}
|
|
122
|
-
function getEnvVarName(clientPrefix, key) {
|
|
123
|
-
return `${clientPrefix.toUpperCase().replace(/-/g, "_")}_${key.toUpperCase()}`;
|
|
124
|
-
}
|
|
125
120
|
export {
|
|
126
121
|
buildStdioServer,
|
|
127
122
|
createInitializeCaptureTap,
|
package/dist/package.json.js
CHANGED
|
@@ -8,10 +8,21 @@ class CreateTestCaseWebLink extends Tool {
|
|
|
8
8
|
readOnly: false,
|
|
9
9
|
idempotent: false,
|
|
10
10
|
inputSchema: CreateTestCaseWebLinkBody.extend({
|
|
11
|
-
testCaseKey: CreateTestCaseWebLinkParams.shape.testCaseKey
|
|
11
|
+
testCaseKey: CreateTestCaseWebLinkParams.shape.testCaseKey,
|
|
12
|
+
description: CreateTestCaseWebLinkBody.shape.description.describe(
|
|
13
|
+
"The web link description, shown as the link text in Zephyr. Optional; defaults to the URL."
|
|
14
|
+
)
|
|
12
15
|
}),
|
|
13
16
|
outputSchema: CreateTestCaseWebLink201Response,
|
|
14
17
|
examples: [
|
|
18
|
+
{
|
|
19
|
+
description: "Add a web link 'https://www.atlassian.com' to test case SA-T1 without a description",
|
|
20
|
+
parameters: {
|
|
21
|
+
testCaseKey: "SA-T1",
|
|
22
|
+
url: "https://www.atlassian.com"
|
|
23
|
+
},
|
|
24
|
+
expectedOutput: "The newly created Web Link with its ID and self link; the URL is used as the link text"
|
|
25
|
+
},
|
|
15
26
|
{
|
|
16
27
|
description: "Create a web link for test case SA-T1 pointing to Atlassian's homepage",
|
|
17
28
|
parameters: {
|
|
@@ -37,7 +48,11 @@ class CreateTestCaseWebLink extends Tool {
|
|
|
37
48
|
testCaseKey: CreateTestCaseWebLinkParams.shape.testCaseKey
|
|
38
49
|
});
|
|
39
50
|
const parsed = fullInputSchema.parse(args);
|
|
40
|
-
const { testCaseKey,
|
|
51
|
+
const { testCaseKey, description, url } = parsed;
|
|
52
|
+
const body = {
|
|
53
|
+
url,
|
|
54
|
+
description: description?.trim() ? description : url
|
|
55
|
+
};
|
|
41
56
|
const response = await this.client.getApiClient().post(`/testcases/${testCaseKey}/links/weblinks`, body);
|
|
42
57
|
return {
|
|
43
58
|
structuredContent: response,
|
|
@@ -11,8 +11,20 @@ class CreateTestCycleWebLink extends Tool {
|
|
|
11
11
|
// a plain object instead of `allOf`, which older MCP clients don't understand.
|
|
12
12
|
inputSchema: CreateTestCycleWebLinkParams.extend(
|
|
13
13
|
CreateTestCycleWebLinkBody.partial().shape
|
|
14
|
-
)
|
|
14
|
+
).extend({
|
|
15
|
+
description: CreateTestCycleWebLinkBody.shape.description.describe(
|
|
16
|
+
"The web link description, shown as the link text in Zephyr. Optional; defaults to the URL."
|
|
17
|
+
)
|
|
18
|
+
}),
|
|
15
19
|
examples: [
|
|
20
|
+
{
|
|
21
|
+
description: "Add a web link 'https://www.atlassian.com' to test cycle 'SA-R15' without a description",
|
|
22
|
+
parameters: {
|
|
23
|
+
testCycleIdOrKey: "SA-R15",
|
|
24
|
+
url: "https://www.atlassian.com"
|
|
25
|
+
},
|
|
26
|
+
expectedOutput: "The newly created Web Link with its ID and self link; the URL is used as the link text"
|
|
27
|
+
},
|
|
16
28
|
{
|
|
17
29
|
description: "Create a link between the specified test cycle by Id '100001' and generic URL 'https://www.atlassian.com' with description 'Atlassian homepage'",
|
|
18
30
|
parameters: {
|
|
@@ -46,7 +58,11 @@ class CreateTestCycleWebLink extends Tool {
|
|
|
46
58
|
const parsed = CreateTestCycleWebLinkParams.and(
|
|
47
59
|
CreateTestCycleWebLinkBody
|
|
48
60
|
).parse(args);
|
|
49
|
-
const { testCycleIdOrKey,
|
|
61
|
+
const { testCycleIdOrKey, description, url } = parsed;
|
|
62
|
+
const body = {
|
|
63
|
+
url,
|
|
64
|
+
description: description?.trim() ? description : url
|
|
65
|
+
};
|
|
50
66
|
const response = await this.client.getApiClient().post(`/testcycles/${testCycleIdOrKey}/links/weblinks`, body);
|
|
51
67
|
return {
|
|
52
68
|
structuredContent: response,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smartbear/mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.44.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=22"
|
|
6
6
|
},
|
|
@@ -49,6 +49,8 @@
|
|
|
49
49
|
"test:coverage:ci": "vitest --coverage --reporter=verbose",
|
|
50
50
|
"test:run": "vitest run",
|
|
51
51
|
"test:pact": "vitest run --config vitest.pact.config.ts",
|
|
52
|
+
"test:drift": "node scripts/drift-verify.mjs",
|
|
53
|
+
"drift:generate": "node scripts/drift-generate-definition.mjs && biome format --write src/pactflow/drift",
|
|
52
54
|
"coverage:check": "vitest --coverage --reporter=verbose",
|
|
53
55
|
"bump": "node scripts/bump.js"
|
|
54
56
|
},
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# Drift MCP plugin tests for the PactFlow integration
|
|
2
|
+
|
|
3
|
+
These tests verify the PactFlow tools (and prompt) that this server exposes, using the
|
|
4
|
+
[Drift MCP plugin](https://support.smartbear.com/swagger/contract-testing/docs/en/drift/plugins/mcp-plugin.html).
|
|
5
|
+
They sit alongside the Pact consumer tests (`npm run test:pact`), which cover the
|
|
6
|
+
server's calls to PactFlow APIs; these cover what the server offers to MCP clients.
|
|
7
|
+
|
|
8
|
+
| File | Purpose |
|
|
9
|
+
| --- | --- |
|
|
10
|
+
| `pactflow.mcp.yaml` | The MCP definition (contract) of the PactFlow tools and prompt. **Generated**, do not edit. |
|
|
11
|
+
| `pactflow.testcases.yaml` | Hand-written Drift test cases: the surface check (`drift/all`) and tool calls with content, tool-error and invalid-argument assertions. |
|
|
12
|
+
| `pactflow.tools.testcases.yaml` | **Generated**, do not edit. One call per remaining tool, with arguments built from its input schema, so every PactFlow tool is invoked and its result validated against its `outputSchema`. |
|
|
13
|
+
| `mock-pactflow.mjs` | Minimal mock of the PactFlow API the tools call. |
|
|
14
|
+
| `mock-fixtures.generated.json` | **Generated**, do not edit. Mock response bodies the generated calls assert on. |
|
|
15
|
+
|
|
16
|
+
## Running
|
|
17
|
+
|
|
18
|
+
```sh
|
|
19
|
+
npm install -g @pactflow/drift
|
|
20
|
+
drift component install mcp # the MCP plugin is optional and in beta
|
|
21
|
+
|
|
22
|
+
npm run build
|
|
23
|
+
export PACT_BROKER_BASE_URL=... PACT_BROKER_TOKEN=... # Drift authenticates with PactFlow
|
|
24
|
+
npm run test:drift
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
`scripts/drift-verify.mjs` starts the mock, launches `node dist/index.js` over stdio
|
|
28
|
+
pointed at it, and runs `drift verify` with strict settings: a PactFlow tool or
|
|
29
|
+
description that differs from the definition fails the run.
|
|
30
|
+
|
|
31
|
+
## Publishing to PactFlow
|
|
32
|
+
|
|
33
|
+
CI (`.github/workflows/drift.yml`) publishes the definition and the Drift results as a
|
|
34
|
+
provider contract for `smartbear-mcp` (specification `mcp`) with
|
|
35
|
+
`scripts/ci/drift-publish-provider-contract`, even when the tests fail (the exit code is
|
|
36
|
+
passed through) and then fails the job. Publishing is skipped for forks and Dependabot,
|
|
37
|
+
which have no secrets. To publish by hand:
|
|
38
|
+
|
|
39
|
+
```sh
|
|
40
|
+
npm run test:drift -- --output-dir drift-results --generate-result
|
|
41
|
+
DRIFT_EXIT_CODE=$? GITHUB_SHA=<version> GITHUB_REF_NAME=<branch> \
|
|
42
|
+
scripts/ci/drift-publish-provider-contract # needs PACT_BROKER_BASE_URL / PACT_BROKER_TOKEN
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
PactFlow stores the `mcp` specification as published and does not compare it with consumer
|
|
46
|
+
contracts, so it cannot satisfy a can-i-deploy check; it is available through the API.
|
|
47
|
+
|
|
48
|
+
## When you change a PactFlow tool
|
|
49
|
+
|
|
50
|
+
Rebuild and regenerate the definition and the generated calls, then review the diff:
|
|
51
|
+
|
|
52
|
+
```sh
|
|
53
|
+
npm run build && npm run drift:generate
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Generate it from a clean `npm ci` install: the advertised JSON Schema depends on the installed
|
|
57
|
+
`zod` and MCP SDK versions (a stale `node_modules` once produced a definition that failed in CI).
|
|
58
|
+
|
|
59
|
+
## Adding a test
|
|
60
|
+
|
|
61
|
+
Every tool already gets a generated call that asserts the response content (the mock bodies in `mock-fixtures.generated.json` are built from each tool's `outputSchema`). To assert more about one, add an operation to
|
|
62
|
+
`pactflow.testcases.yaml` (the generator then skips that tool) targeting `pactflow:tool/<tool name>`,
|
|
63
|
+
with inputs under `parameters.arguments`, and add any endpoint it needs to
|
|
64
|
+
`mock-pactflow.mjs` (unknown routes get an empty `200 {}`, so only tools that need
|
|
65
|
+
a specific body or status, such as 204 for deletes, have fixtures). Assert `expected.result.structuredContent` for results or
|
|
66
|
+
`expected.result.isError: true` for tool errors. Drift also validates each result
|
|
67
|
+
against the tool's `outputSchema` automatically.
|
|
68
|
+
|
|
69
|
+
## Notes
|
|
70
|
+
|
|
71
|
+
- Running against a real PactFlow tenant instead of the mock? Drift tags operations for tools
|
|
72
|
+
with `destructiveHint: true` as `destructive`, but does not exclude them for you:
|
|
73
|
+
`npm run test:drift -- --tags '!destructive'`.
|
|
74
|
+
- This definition covers the whole PactFlow surface (every tool is invoked), unlike the
|
|
75
|
+
curated 22-tool definition in Drift's own `Examples/smartbear-mcp`, which governs only the
|
|
76
|
+
capabilities an agent is authorised to use.
|
|
77
|
+
- Drift's MCP plugin compares schemas shallowly (top-level `required`, the property names and
|
|
78
|
+
each property's `type`), so a tightened nested constraint is not caught by the surface check.
|
|
79
|
+
`execution.taskSupport` is not modelled. Results are checked against an `outputSchema` only
|
|
80
|
+
when a test invokes the tool, which is why every tool has a call.
|
|
81
|
+
- Invalid arguments come back as a tool error (`isError: true`); the MCP specification puts
|
|
82
|
+
schema violations in the JSON-RPC error channel (`-32602`). The tests assert the observed
|
|
83
|
+
behaviour and say so.
|
|
84
|
+
|
|
85
|
+
- Drift cannot authenticate to an MCP server, so tests use the stdio transport and give the
|
|
86
|
+
server its settings (pointing at the mock) through its own environment only.
|
|
87
|
+
- Drift itself authenticates with PactFlow on every run: set `PACT_BROKER_BASE_URL` and
|
|
88
|
+
`PACT_BROKER_TOKEN` (CI uses the repository secrets) or run `drift auth login` once.
|
|
89
|
+
Without either it stops with "Could not initialise the authentication config".
|
|
90
|
+
- The PactFlow AI tools are advertised only when PactFlow's AI entitlement check succeeds;
|
|
91
|
+
the mock enables it so the definition covers the full surface.
|