@smartbear/mcp 0.41.3 → 0.43.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.
Files changed (63) hide show
  1. package/README.md +5 -0
  2. package/dist/bearq/api.js +16 -0
  3. package/dist/bearq/client.js +9 -1
  4. package/dist/bearq/tool/tasks/stop-task.js +6 -3
  5. package/dist/bearq/tool/workflows/get-workflow-run.js +31 -0
  6. package/dist/bearq/tool/workflows/list-workflows.js +28 -0
  7. package/dist/bearq/tool/workflows/run-workflow.js +57 -0
  8. package/dist/bearq/tool/workflows/stop-workflow-run.js +33 -0
  9. package/dist/bugsnag/client.js +1 -0
  10. package/dist/common/analytics.js +341 -0
  11. package/dist/common/initialize.js +1 -0
  12. package/dist/common/jwt.js +83 -0
  13. package/dist/common/register-clients.js +16 -18
  14. package/dist/common/server.js +36 -0
  15. package/dist/common/transport-http.js +48 -7
  16. package/dist/package.json.js +1 -1
  17. package/dist/pactflow/client/admin-api.js +3 -8
  18. package/dist/pactflow/client/ai.js +34 -0
  19. package/dist/pactflow/client/contract-api.js +2 -0
  20. package/dist/pactflow/client/http-client.js +7 -2
  21. package/dist/pactflow/client/pacticipant-api.js +37 -0
  22. package/dist/pactflow/client/pagination.js +1 -1
  23. package/dist/pactflow/client/schemas/admin.js +799 -0
  24. package/dist/pactflow/client/schemas/common.js +201 -0
  25. package/dist/pactflow/client/schemas/contract.js +444 -0
  26. package/dist/pactflow/client/schemas/environment.js +94 -0
  27. package/dist/pactflow/client/schemas/output.js +55 -0
  28. package/dist/pactflow/client/schemas/pacticipant.js +290 -0
  29. package/dist/pactflow/client/schemas/webhook.js +164 -0
  30. package/dist/pactflow/client/tools.js +32 -1
  31. package/dist/pactflow/client/utils.js +1 -1
  32. package/dist/pactflow/client.js +21 -3
  33. package/dist/qmetry/client/ai-agent.js +3 -0
  34. package/dist/qmetry/client/api/error-handler.js +7 -2
  35. package/dist/qmetry/client/auto-resolve.js +5 -0
  36. package/dist/qmetry/client/handlers.js +2 -1
  37. package/dist/qmetry/client/project.js +19 -1
  38. package/dist/qmetry/client/testsuite.js +207 -2
  39. package/dist/qmetry/client/tools/ai-agent-tools.js +13 -0
  40. package/dist/qmetry/client/tools/issue-tools.js +7 -3
  41. package/dist/qmetry/client/tools/project-tools.js +34 -1
  42. package/dist/qmetry/client/tools/testcase-tools.js +43 -296
  43. package/dist/qmetry/client/tools/testsuite-tools.js +49 -19
  44. package/dist/qmetry/client/udf.js +14 -2
  45. package/dist/qmetry/client.js +2 -1
  46. package/dist/qmetry/config/constants.js +1 -0
  47. package/dist/qmetry/config/rest-endpoints.js +2 -1
  48. package/dist/qmetry/types/ai-agent.js +3 -0
  49. package/dist/qmetry/types/common.js +40 -2
  50. package/dist/qmetry/types/udf.js +1 -20
  51. package/dist/qtm4j/client.js +1 -1
  52. package/dist/swagger/client/api.js +5 -1
  53. package/dist/swagger/client/portal-types.js +11 -5
  54. package/dist/swagger/client/registry-types.js +12 -5
  55. package/dist/swagger/client/tools.js +3 -3
  56. package/dist/zephyr/tool/issue-link/get-test-cases.js +1 -1
  57. package/dist/zephyr/tool/issue-link/get-test-cycles.js +1 -1
  58. package/dist/zephyr/tool/issue-link/get-test-executions.js +1 -1
  59. package/dist/zephyr/tool/test-case/update-test-case.js +1 -1
  60. package/dist/zephyr/tool/test-cycle/update-test-cycle.js +1 -1
  61. package/package.json +4 -3
  62. package/plugin/README.md +42 -0
  63. package/dist/pactflow/client/base.js +0 -488
@@ -1,19 +1,17 @@
1
- import { BearQClient } from "../bearq/client.js";
2
- import { BugsnagClient } from "../bugsnag/client.js";
3
- import { CollaboratorClient } from "../collaborator/client.js";
4
- import { PactflowClient } from "../pactflow/client.js";
5
- import { QmetryClient } from "../qmetry/client.js";
6
- import { Qtm4jClient } from "../qtm4j/client.js";
7
- import { ReflectClient } from "../reflect/client.js";
8
- import { SwaggerClient } from "../swagger/client.js";
9
- import { ZephyrClient } from "../zephyr/client.js";
10
1
  import { clientRegistry } from "./client-registry.js";
11
- clientRegistry.register(new BearQClient());
12
- clientRegistry.register(new ReflectClient());
13
- clientRegistry.register(new BugsnagClient());
14
- clientRegistry.register(new SwaggerClient());
15
- clientRegistry.register(new PactflowClient());
16
- clientRegistry.register(new QmetryClient());
17
- clientRegistry.register(new ZephyrClient());
18
- clientRegistry.register(new Qtm4jClient());
19
- clientRegistry.register(new CollaboratorClient());
2
+ const clientLoaders = {
3
+ BearQ: async () => new (await import("../bearq/client.js")).BearQClient(),
4
+ Reflect: async () => new (await import("../reflect/client.js")).ReflectClient(),
5
+ BugSnag: async () => new (await import("../bugsnag/client.js")).BugsnagClient(),
6
+ Swagger: async () => new (await import("../swagger/client.js")).SwaggerClient(),
7
+ "Contract Testing": async () => new (await import("../pactflow/client.js")).PactflowClient(),
8
+ QMetry: async () => new (await import("../qmetry/client.js")).QmetryClient(),
9
+ Zephyr: async () => new (await import("../zephyr/client.js")).ZephyrClient(),
10
+ QTM4J: async () => new (await import("../qtm4j/client.js")).Qtm4jClient(),
11
+ Collaborator: async () => new (await import("../collaborator/client.js")).CollaboratorClient()
12
+ };
13
+ for (const [name, loadClient] of Object.entries(clientLoaders)) {
14
+ if (clientRegistry.isClientEnabled(name)) {
15
+ clientRegistry.register(await loadClient());
16
+ }
17
+ }
@@ -1,6 +1,7 @@
1
1
  import { McpServer, ResourceTemplate } from "@modelcontextprotocol/server";
2
2
  import { z, ZodObject } from "zod";
3
3
  import Bugsnag from "./bugsnag.js";
4
+ import { errorTypeOf, trackToolCalled } from "./analytics.js";
4
5
  import { isCachingEnabled, CacheService, getConfiguredCacheTtlSeconds } from "./cache.js";
5
6
  import { toClientIdentity, getCurrentClientIdentity } from "./client-identity.js";
6
7
  import { MCP_SERVER_VERSION, MCP_SERVER_NAME } from "./info.js";
@@ -28,6 +29,7 @@ class SmartBearMcpServer extends McpServer {
28
29
  clients = [];
29
30
  enabledToolsets;
30
31
  mcpClientIdentity;
32
+ analyticsSession;
31
33
  constructor(enabledToolsets, era = "legacy") {
32
34
  super(
33
35
  {
@@ -105,6 +107,21 @@ class SmartBearMcpServer extends McpServer {
105
107
  getClients() {
106
108
  return this.clients;
107
109
  }
110
+ /** Toolsets enabled for this instance (normalised), or `undefined` for all. */
111
+ getEnabledToolsets() {
112
+ return this.enabledToolsets;
113
+ }
114
+ /**
115
+ * Attach the usage-analytics state for the HTTP session this instance
116
+ * serves. Set by the HTTP transport once a session id exists; never set for
117
+ * stdio or for modern-era (sessionless) requests.
118
+ */
119
+ setAnalyticsSession(session) {
120
+ this.analyticsSession = session;
121
+ }
122
+ getAnalyticsSession() {
123
+ return this.analyticsSession;
124
+ }
108
125
  /**
109
126
  * Record the MCP client identity reported in the `initialize` handshake.
110
127
  * Captured once per session by the transport layer.
@@ -173,6 +190,9 @@ class SmartBearMcpServer extends McpServer {
173
190
  annotations: this.getAnnotations(toolTitle, params)
174
191
  },
175
192
  async (args, ctx) => {
193
+ const startedAt = Date.now();
194
+ let success = true;
195
+ let errorType = null;
176
196
  try {
177
197
  if (!client.isConfigured()) {
178
198
  throw new ToolError(
@@ -186,12 +206,18 @@ class SmartBearMcpServer extends McpServer {
186
206
  if (result) {
187
207
  this.validateCallbackResult(result, params);
188
208
  this.addStructuredContentAsText(result);
209
+ if (result.isError) {
210
+ success = false;
211
+ errorType = "ToolResultError";
212
+ }
189
213
  }
190
214
  return result;
191
215
  } catch (e) {
192
216
  if (e instanceof InputRequiredSignal) {
193
217
  return e.result;
194
218
  }
219
+ success = false;
220
+ errorType = errorTypeOf(e);
195
221
  if (e instanceof ToolError) {
196
222
  return {
197
223
  isError: true,
@@ -210,6 +236,16 @@ class SmartBearMcpServer extends McpServer {
210
236
  });
211
237
  }
212
238
  throw e;
239
+ } finally {
240
+ trackToolCalled({
241
+ client,
242
+ toolName,
243
+ success,
244
+ errorType,
245
+ durationMs: Date.now() - startedAt,
246
+ mcpClient: this.getMcpClientIdentity(),
247
+ session: this.analyticsSession
248
+ });
213
249
  }
214
250
  }
215
251
  );
@@ -5,11 +5,13 @@ import querystring from "node:querystring";
5
5
  import { toNodeHandler, toWebRequest, NodeStreamableHTTPServerTransport } from "@modelcontextprotocol/node";
6
6
  import { createMcpHandler, isLegacyRequest, isInitializeRequest } from "@modelcontextprotocol/server";
7
7
  import { SSEServerTransport } from "@modelcontextprotocol/server-legacy/sse";
8
+ import { initAnalytics, isToolsListRequest, trackToolsListed, createAnalyticsSession, flushAnalytics } from "./analytics.js";
8
9
  import { clientRegistry } from "./client-registry.js";
9
- import { handleInitializeMessage, extractModernClientMeta } from "./initialize.js";
10
+ import { MCP_SERVER_VERSION } from "./info.js";
11
+ import { extractModernClientMeta, handleInitializeMessage } from "./initialize.js";
10
12
  import { withRequestHeaders, withRequestContext, setRequestMcpClient, setModernRequestClient } from "./request-context.js";
11
13
  import { SmartBearMcpServer } from "./server.js";
12
- import { isDraining, registerShutdownHandler } from "./shutdown.js";
14
+ import { registerShutdownHandler, isDraining } from "./shutdown.js";
13
15
  import { getEnvVarName } from "./transport-stdio.js";
14
16
  import { isOptionalType, getTypeDescription } from "./zod-utils.js";
15
17
  const PROBE_HEADERS = {
@@ -19,7 +21,13 @@ const PROBE_HEADERS = {
19
21
  function handleHealthRequest(res) {
20
22
  res.writeHead(200, PROBE_HEADERS);
21
23
  res.end(
22
- JSON.stringify({ status: "ok", timestamp: (/* @__PURE__ */ new Date()).toISOString() })
24
+ JSON.stringify({
25
+ status: "ok",
26
+ timestamp: (/* @__PURE__ */ new Date()).toISOString(),
27
+ version: MCP_SERVER_VERSION,
28
+ // No regional deployments exist yet; hardcoded until that lands.
29
+ region: null
30
+ })
23
31
  );
24
32
  }
25
33
  function handleReadyRequest(res, draining = isDraining) {
@@ -62,6 +70,10 @@ async function runHttpMode() {
62
70
  "http://localhost:3000"
63
71
  ];
64
72
  const transports = /* @__PURE__ */ new Map();
73
+ if (initAnalytics()) {
74
+ console.log("[MCP HTTP Server] Usage analytics enabled");
75
+ registerShutdownHandler("analytics", flushAnalytics);
76
+ }
65
77
  const modernHandler = createModernHandler();
66
78
  const modernNodeHandler = toNodeHandler(modernHandler, {
67
79
  onerror: (error) => {
@@ -236,19 +248,40 @@ async function createNewTransport(req, res, transports) {
236
248
  onsessioninitialized: (newSessionId) => {
237
249
  console.log(`[MCP] New session initialized: ${newSessionId}`);
238
250
  transports.set(newSessionId, { server, transport });
251
+ attachSessionAnalytics(server, newSessionId, "streamable-http");
239
252
  }
240
253
  });
241
- transport.onmessage = (message) => handleInitializeMessage(server, message);
254
+ transport.onmessage = (message) => handleSessionMessage(server, message);
242
255
  transport.onclose = () => {
243
256
  if (transport.sessionId) {
244
257
  console.log(`[MCP] Session closed: ${transport.sessionId}`);
245
258
  transports.delete(transport.sessionId);
259
+ endSessionAnalytics(server);
246
260
  server.cleanupSession(transport.sessionId);
247
261
  }
248
262
  };
249
263
  await server.connect(transport);
250
264
  return transport;
251
265
  }
266
+ function handleSessionMessage(server, message) {
267
+ handleInitializeMessage(server, message);
268
+ if (isToolsListRequest(message)) {
269
+ trackToolsListed(server);
270
+ }
271
+ }
272
+ function attachSessionAnalytics(server, sessionId, transport) {
273
+ server.setAnalyticsSession(
274
+ createAnalyticsSession({
275
+ sessionId,
276
+ transport,
277
+ server,
278
+ integrations: clientRegistry.getAll().map((client) => client.capabilityPrefix)
279
+ })
280
+ );
281
+ }
282
+ function endSessionAnalytics(server) {
283
+ server.getAnalyticsSession()?.end(isDraining() ? "server_shutdown" : "client_disconnected");
284
+ }
252
285
  const modernServerStorage = new AsyncLocalStorage();
253
286
  function createModernHandler() {
254
287
  return createMcpHandler(
@@ -290,11 +323,14 @@ async function handleMcpEndpoint(req, res, transports, modern) {
290
323
  const clientMeta = extractModernClientMetaFromBody(parsedBody);
291
324
  await modernServerStorage.run(
292
325
  server,
293
- () => withRequestHeaders(headers, () => {
326
+ () => withRequestHeaders(headers, async () => {
294
327
  if (clientMeta) {
295
328
  setModernRequestClient(clientMeta);
296
329
  }
297
- return modern(req, res, parsedBody);
330
+ await modern(req, res, parsedBody);
331
+ if (res.statusCode < 400 && isToolsListRequest(parsedBody)) {
332
+ trackToolsListed(server);
333
+ }
298
334
  })
299
335
  );
300
336
  }
@@ -375,10 +411,12 @@ async function handleLegacySseRequest(req, res, transports) {
375
411
  return;
376
412
  }
377
413
  const transport = new SSEServerTransport("/message", res);
378
- transport.onmessage = (message) => handleInitializeMessage(server, message);
414
+ transport.onmessage = (message) => handleSessionMessage(server, message);
379
415
  transports.set(transport.sessionId, { server, transport });
416
+ attachSessionAnalytics(server, transport.sessionId, "sse");
380
417
  res.on("close", () => {
381
418
  transports.delete(transport.sessionId);
419
+ endSessionAnalytics(server);
382
420
  server.cleanupSession(transport.sessionId);
383
421
  });
384
422
  await server.connect(transport);
@@ -554,13 +592,16 @@ function getHttpHeadersHelp() {
554
592
  return messages;
555
593
  }
556
594
  export {
595
+ attachSessionAnalytics,
557
596
  drainHttpTransport,
597
+ endSessionAnalytics,
558
598
  getBaseUrl,
559
599
  getBaseUrlFromHeaders,
560
600
  getHeaderName,
561
601
  getQueryStringName,
562
602
  handleHealthRequest,
563
603
  handleReadyRequest,
604
+ handleSessionMessage,
564
605
  handleStreamableHttpRequest,
565
606
  newServer,
566
607
  newServerFromWebRequest,
@@ -1,4 +1,4 @@
1
- const version = "0.41.3";
1
+ const version = "0.43.0";
2
2
  const config = { "mcpServerName": "SmartBear MCP Server" };
3
3
  const packageJson = {
4
4
  version,
@@ -205,10 +205,7 @@ class AdminApi {
205
205
  /**
206
206
  * Fully replaces the roles assigned to a user (admin).
207
207
  */
208
- async setUserRoles({
209
- userId,
210
- roles
211
- }) {
208
+ async setUserRoles({ userId, roles }) {
212
209
  return await this.http.fetch(
213
210
  `${this.http.baseUrl}/admin/users/${encodeURIComponent(userId)}/roles`,
214
211
  { method: "PUT", body: { roles }, errorContext: "Set User Roles" }
@@ -217,10 +214,7 @@ class AdminApi {
217
214
  /**
218
215
  * Grants a single additional role to a user without affecting their existing roles (admin).
219
216
  */
220
- async addRoleToUser({
221
- userId,
222
- roleId
223
- }) {
217
+ async addRoleToUser({ userId, roleId }) {
224
218
  return await this.http.fetch(
225
219
  `${this.http.baseUrl}/admin/users/${encodeURIComponent(userId)}/roles/${encodeURIComponent(roleId)}`,
226
220
  { method: "PUT", body: {}, errorContext: "Add Role to User" }
@@ -337,6 +331,7 @@ class AdminApi {
337
331
  {
338
332
  method: "PATCH",
339
333
  body: operations,
334
+ headers: { "Content-Type": "application/json-patch+json" },
340
335
  errorContext: "Patch Team Users"
341
336
  }
342
337
  );
@@ -132,17 +132,51 @@ z.object({
132
132
  ),
133
133
  aiEnabled: z.boolean()
134
134
  }).describe("Entitlements information.");
135
+ const GenerationOutputSchema = z.looseObject({
136
+ id: z.string().nullish(),
137
+ code: z.string().optional(),
138
+ language: z.string().optional(),
139
+ requiresPromptExecution: z.literal(true).optional(),
140
+ prompt: z.string().optional(),
141
+ instructions: z.string().optional()
142
+ });
143
+ const RefineOutputSchema = z.looseObject({
144
+ recommendations: z.array(
145
+ z.looseObject({
146
+ recommendation: z.string(),
147
+ diff: z.string().nullish(),
148
+ confidence: z.number().nullish()
149
+ })
150
+ ).optional(),
151
+ requiresPromptExecution: z.literal(true).optional(),
152
+ prompt: z.string().optional(),
153
+ instructions: z.string().optional()
154
+ });
155
+ const EntitlementsOutputSchema = z.looseObject({
156
+ aiEnabled: z.boolean().optional(),
157
+ organizationEntitlements: z.looseObject({}).optional(),
158
+ userEntitlements: z.looseObject({}).optional()
159
+ });
160
+ const AI_OUTPUT_SCHEMAS = {
161
+ generate: GenerationOutputSchema,
162
+ review: RefineOutputSchema,
163
+ checkAIEntitlements: EntitlementsOutputSchema
164
+ };
135
165
  export {
166
+ AI_OUTPUT_SCHEMAS,
136
167
  AiCreditsSchema,
137
168
  EndpointMatcherSchema,
169
+ EntitlementsOutputSchema,
138
170
  FileInputSchema,
139
171
  GenerationInputSchema,
140
172
  GenerationLanguages,
173
+ GenerationOutputSchema,
141
174
  HttpMethods,
142
175
  OpenAPISchema,
143
176
  OpenAPIWithMatcherSchema,
144
177
  OrganizationEntitlementsSchema,
145
178
  RefineInputSchema,
179
+ RefineOutputSchema,
146
180
  RemoteOpenAPIDocumentSchema,
147
181
  RequestResponsePairSchema,
148
182
  UserEntitlementsSchema
@@ -279,6 +279,7 @@ class ContractApi {
279
279
  `${this.http.baseUrl}/integrations`,
280
280
  {
281
281
  method: "GET",
282
+ headers: { Accept: "application/hal+json" },
282
283
  errorContext: "List Integrations"
283
284
  }
284
285
  );
@@ -304,6 +305,7 @@ class ContractApi {
304
305
  `${this.http.baseUrl}/integrations/team/${encodeURIComponent(teamId)}`,
305
306
  {
306
307
  method: "GET",
308
+ headers: { Accept: "application/hal+json" },
307
309
  errorContext: "Get Integrations by Team"
308
310
  }
309
311
  );
@@ -5,11 +5,16 @@ class HttpClient {
5
5
  this.getHeaders = getHeaders;
6
6
  }
7
7
  async fetch(url, options) {
8
- const { method = "GET", body, errorContext = "Request" } = options ?? {};
8
+ const {
9
+ method = "GET",
10
+ body,
11
+ headers,
12
+ errorContext = "Request"
13
+ } = options ?? {};
9
14
  try {
10
15
  const response = await fetch(url, {
11
16
  method,
12
- headers: this.getHeaders(),
17
+ headers: { ...this.getHeaders(), ...headers },
13
18
  ...body !== void 0 ? { body: JSON.stringify(body) } : {}
14
19
  });
15
20
  if (!response.ok) {
@@ -63,6 +63,41 @@ class PacticipantApi {
63
63
  { method: "GET", errorContext: "List Versions" }
64
64
  );
65
65
  }
66
+ /**
67
+ * Retrieves all versions of a pacticipant that have ever been deployed or released, with optional pagination.
68
+ */
69
+ async listDeployedOrReleasedVersions({
70
+ pacticipantName,
71
+ pageNumber,
72
+ pageSize
73
+ }) {
74
+ const queryParams = new URLSearchParams();
75
+ if (pageNumber) queryParams.set("page", String(pageNumber));
76
+ if (pageSize) queryParams.set("size", String(pageSize));
77
+ const qs = queryParams.toString();
78
+ return await this.http.fetch(
79
+ `${this.http.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/deployed-or-released/versions${qs ? `?${qs}` : ""}`,
80
+ { method: "GET", errorContext: "List Deployed or Released Versions" }
81
+ );
82
+ }
83
+ /**
84
+ * Retrieves the versions of a pacticipant associated with an environment, with optional pagination.
85
+ */
86
+ async listEnvironmentVersions({
87
+ pacticipantName,
88
+ environmentId,
89
+ pageNumber,
90
+ pageSize
91
+ }) {
92
+ const queryParams = new URLSearchParams();
93
+ if (pageNumber) queryParams.set("page", String(pageNumber));
94
+ if (pageSize) queryParams.set("size", String(pageSize));
95
+ const qs = queryParams.toString();
96
+ return await this.http.fetch(
97
+ `${this.http.baseUrl}/pacticipants/${encodeURIComponent(pacticipantName)}/environments/${encodeURIComponent(environmentId)}/versions${qs ? `?${qs}` : ""}`,
98
+ { method: "GET", errorContext: "List Environment Versions" }
99
+ );
100
+ }
66
101
  /**
67
102
  * Retrieves metadata for a specific version of a pacticipant.
68
103
  */
@@ -265,6 +300,8 @@ class PacticipantApi {
265
300
  getPacticipant: this.getPacticipant.bind(this),
266
301
  listBranches: this.listBranches.bind(this),
267
302
  listVersions: this.listVersions.bind(this),
303
+ listDeployedOrReleasedVersions: this.listDeployedOrReleasedVersions.bind(this),
304
+ listEnvironmentVersions: this.listEnvironmentVersions.bind(this),
268
305
  getVersion: this.getVersion.bind(this),
269
306
  getLatestVersion: this.getLatestVersion.bind(this),
270
307
  updatePacticipant: this.updatePacticipant.bind(this),
@@ -1,4 +1,4 @@
1
- import { randomBytes, scryptSync, createHmac } from "node:crypto";
1
+ import { scryptSync, createHmac, randomBytes } from "node:crypto";
2
2
  const PAGINATION_CACHE_TTL_SECONDS = 30;
3
3
  const CACHE_KEY_SECRET = randomBytes(32);
4
4
  function stableStringify(value) {