@smartbear/mcp 0.32.0 → 0.34.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.
@@ -3,6 +3,7 @@ import { getUserAgent } from "../common/info.js";
3
3
  import { isSamplingPolyfillResult } from "../common/pollyfills.js";
4
4
  import { getRequestHeader } from "../common/request-context.js";
5
5
  import { ToolError } from "../common/tools.js";
6
+ import { withPagination } from "./client/pagination.js";
6
7
  import { getOADMatcherRecommendations, getUserMatcherSelection } from "./client/prompt-utils.js";
7
8
  import { PROMPTS } from "./client/prompts.js";
8
9
  import { TOOLS } from "./client/tools.js";
@@ -26,6 +27,7 @@ class PactflowClient {
26
27
  baseUrl;
27
28
  _clientType;
28
29
  _server;
30
+ cache;
29
31
  /** Returns the configured MCP server instance. @throws Error if not yet configured. */
30
32
  get server() {
31
33
  if (!this._server) throw new Error("Server not configured");
@@ -53,6 +55,7 @@ class PactflowClient {
53
55
  this.baseUrl = config.base_url;
54
56
  this.aiBaseUrl = `${this.baseUrl}/api/ai`;
55
57
  this._server = server;
58
+ this.cache = server.getCache();
56
59
  }
57
60
  /** Returns true if the client has been configured with a base URL and credentials. */
58
61
  isConfigured() {
@@ -2088,7 +2091,18 @@ class PactflowClient {
2088
2091
  throw new Error(`Handler '${handler}' not found on PactClient`);
2089
2092
  }
2090
2093
  let result;
2091
- if (tool.enableElicitation) {
2094
+ if (tool.paginated) {
2095
+ if (!this.baseUrl || !this.cache) {
2096
+ throw new ToolError(
2097
+ "PactflowClient must be configured before registering paginated tools"
2098
+ );
2099
+ }
2100
+ result = await withPagination(handler_fn.bind(this), handler, args, {
2101
+ baseUrl: this.baseUrl,
2102
+ authToken: this.requestHeaders?.Authorization,
2103
+ cache: this.cache
2104
+ });
2105
+ } else if (tool.enableElicitation) {
2092
2106
  result = await handler_fn.call(this, args, getInput);
2093
2107
  } else {
2094
2108
  result = await handler_fn.call(this, args);
@@ -1,6 +1,6 @@
1
1
  import { appendClientIdentity } from "../../common/info.js";
2
2
  import { ToolError } from "../../common/tools.js";
3
- import { buildSubdomainCandidate, buildSuffixedSubdomain, buildPortalName, isConflictError, isOrganizationPortalConflict } from "./portal-utils.js";
3
+ import { buildSubdomainCandidate, buildPortalName, isConflictError, isOrganizationPortalConflict } from "./portal-utils.js";
4
4
  import { findTableOfContentsItem, buildPortalLiveUrl, normalizeSlug } from "./utils.js";
5
5
  const SWAGGER_URL_REGEX = /\/(apis|domains|templates)\/([^/]+)\/([^/]+)\/([^/]+)/;
6
6
  function hasId(value) {
@@ -12,6 +12,11 @@ function hasMessage(value) {
12
12
  function hasErrorsFound(value) {
13
13
  return typeof value === "object" && value !== null && "errorsFound" in value;
14
14
  }
15
+ function hasSavedVersion(value) {
16
+ if (typeof value !== "object" || value === null) return false;
17
+ const sv = value.savedVersion;
18
+ return typeof sv === "string" && sv.length > 0;
19
+ }
15
20
  function isStandardizationResult(value) {
16
21
  return typeof value === "object" && value !== null && "validation" in value && Array.isArray(value.validation);
17
22
  }
@@ -281,18 +286,14 @@ class SwaggerAPI {
281
286
  }
282
287
  /**
283
288
  * Create a portal for an organization that has none yet. The subdomain is
284
- * derived from the organization name; on a subdomain conflict a candidate
285
- * suffixed with part of the organization UUID is retried.
289
+ * derived from the organization name with an additional random suffix,
290
+ * mirroring the Portal UI's subdomain generation.
286
291
  */
287
292
  async createPortalForOrganization(organizationId) {
288
293
  const organization = await this.findOrganizationById(organizationId);
289
- const baseSubdomain = buildSubdomainCandidate(
290
- organizationId,
291
- organization?.name
292
- );
293
294
  const candidates = [
294
- baseSubdomain,
295
- buildSuffixedSubdomain(baseSubdomain, organizationId)
295
+ buildSubdomainCandidate(organization?.name),
296
+ buildSubdomainCandidate(organization?.name)
296
297
  ];
297
298
  const portalName = buildPortalName(organization?.name);
298
299
  let lastError;
@@ -1055,7 +1056,7 @@ class SwaggerAPI {
1055
1056
  /**
1056
1057
  * Standardize and fix an API definition using AI
1057
1058
  * @param params Parameters including owner, API name, version, and optional newVersion
1058
- * @returns Standardization response with status and fixed definition
1059
+ * @returns Standardization response with status, fixed definition, and URL to the API
1059
1060
  */
1060
1061
  async standardizeApi(params) {
1061
1062
  const searchParams = new URLSearchParams();
@@ -1082,10 +1083,14 @@ class SwaggerAPI {
1082
1083
  "Unexpected response format from standardizeApi endpoint"
1083
1084
  );
1084
1085
  }
1085
- if (!hasErrorsFound(result)) {
1086
- return { ...result, errorsFound: 0 };
1086
+ const updated = {
1087
+ ...result,
1088
+ errorsFound: hasErrorsFound(result) ? result.errorsFound : 0
1089
+ };
1090
+ if (hasSavedVersion(result)) {
1091
+ updated.url = `${this.config.uiBasePath}/apis/${params.owner}/${params.api}/${result.savedVersion}`;
1087
1092
  }
1088
- return result;
1093
+ return updated;
1089
1094
  }
1090
1095
  }
1091
1096
  export {
@@ -47,6 +47,31 @@ class FunctionalTestingAPI {
47
47
  }
48
48
  return response;
49
49
  }
50
+ async createTest(args) {
51
+ const {
52
+ type: _type,
53
+ steps,
54
+ ...rest
55
+ } = args;
56
+ const sanitizedSteps = steps?.map((step) => {
57
+ const { type: _stepType, ...stepRest } = step;
58
+ return { ...stepRest, type: "api" };
59
+ });
60
+ const response = await this.ftFetch(
61
+ `tests`,
62
+ {
63
+ method: "POST",
64
+ headers: this.getFtHeaders(),
65
+ body: JSON.stringify({
66
+ ...rest,
67
+ type: "api",
68
+ steps: sanitizedSteps
69
+ })
70
+ },
71
+ errorMessageFor(`create Functional Testing test`)
72
+ );
73
+ return response.json();
74
+ }
50
75
  async listTests() {
51
76
  const response = await this.ftFetch(
52
77
  `tests`,
@@ -1,4 +1,4 @@
1
- import { RunFunctionalTestingTestParamsSchema, GetFunctionalTestingExecutionTestSchema, ListFunctionalTestingSuiteExecutionsSchema, CancelFunctionalTestingSuiteExecutionSchema, RunFunctionalTestingSuiteParamsSchema, GetFunctionalTestingSuiteExecutionSchema, GetFunctionalTestHistoryParamsSchema } from "./functional-testing-types.js";
1
+ import { CreateFunctionalTestingTestResponseSchema, CreateFunctionalTestingTestParamsSchema, RunFunctionalTestingTestParamsSchema, GetFunctionalTestingExecutionTestSchema, ListFunctionalTestingSuiteExecutionsSchema, CancelFunctionalTestingSuiteExecutionSchema, RunFunctionalTestingSuiteParamsSchema, GetFunctionalTestingSuiteExecutionSchema, GetFunctionalTestHistoryParamsSchema } from "./functional-testing-types.js";
2
2
  const FUNCTIONAL_TESTING_TOOLS = [
3
3
  {
4
4
  title: "List Tests",
@@ -8,10 +8,20 @@ const FUNCTIONAL_TESTING_TOOLS = [
8
8
  idempotent: true,
9
9
  readOnly: true
10
10
  },
11
+ {
12
+ title: "Create Test",
13
+ toolset: "Functional Testing",
14
+ summary: "Creates a new API test in your Swagger Functional Testing workspace. This tool only creates API tests (not browser or native-mobile tests). Use this when you need to programmatically create a test with a defined set of API request steps. Each step requires a URL and may specify an HTTP method (defaults to GET), request body, headers, and redirect handling. Returns the ID and the URL to definition of the newly created test; the ID can be used with `swagger_run_test` to run it.",
15
+ inputSchema: CreateFunctionalTestingTestParamsSchema,
16
+ outputSchema: CreateFunctionalTestingTestResponseSchema,
17
+ handler: "createFunctionalTestingTest",
18
+ idempotent: false,
19
+ readOnly: false
20
+ },
11
21
  {
12
22
  title: "Run Test",
13
23
  toolset: "Functional Testing",
14
- summary: "Runs a specific API test in your Swagger Functional Testing workspace. The execution is asynchronous — it returns an executionId, not the result directly. Use swagger_get_test_status with that executionId to track progress and retrieve the final result.",
24
+ summary: "Runs a specific API test in your Swagger Functional Testing workspace. The execution is asynchronous — it returns an executionId, not the result directly. Use `swagger_get_test_status` with that executionId to track progress and retrieve the final result.",
15
25
  inputSchema: RunFunctionalTestingTestParamsSchema,
16
26
  handler: "runFunctionalTestingTest",
17
27
  idempotent: false,
@@ -27,11 +27,40 @@ const GetFunctionalTestHistoryParamsSchema = z.object({
27
27
  limit: z.number().int().min(1).max(100).optional().describe("Number of most recent runs to return (default: 25, max: 100)"),
28
28
  offset: z.number().int().min(0).optional().describe("Pagination offset (default: 0)")
29
29
  });
30
+ const CreateFunctionalTestingTestHeaderSchema = z.object({
31
+ name: z.string().describe("Header name").trim().min(1),
32
+ value: z.string().describe("Header value")
33
+ });
34
+ const HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
35
+ const CreateFunctionalTestingTestStepSchema = z.object({
36
+ url: z.url().describe("URL for the API call"),
37
+ httpMethod: z.enum(HTTP_METHODS).describe("HTTP method for the API call (defaults to GET server-side)").optional(),
38
+ requestBody: z.string().describe("Request body").optional(),
39
+ requestHeaders: z.array(CreateFunctionalTestingTestHeaderSchema).describe("HTTP headers").optional(),
40
+ followRedirects: z.boolean().describe("Whether to follow redirects").optional(),
41
+ description: z.string().trim().describe("Human-readable label for this step").optional()
42
+ });
43
+ const CreateFunctionalTestingTestParamsSchema = z.object({
44
+ name: z.string().describe("Name for the new test").trim().min(1),
45
+ description: z.string().trim().describe("Optional description for the test").optional(),
46
+ steps: z.array(CreateFunctionalTestingTestStepSchema).describe("Test steps to include in the test").optional()
47
+ });
48
+ const CreateFunctionalTestingTestResponseSchema = z.object({
49
+ id: z.number().describe("ID of the newly created test"),
50
+ url: z.string().describe(
51
+ "Link to the created test definition in Swagger Functional Testing UI"
52
+ )
53
+ });
30
54
  export {
31
55
  CancelFunctionalTestingSuiteExecutionSchema,
56
+ CreateFunctionalTestingTestHeaderSchema,
57
+ CreateFunctionalTestingTestParamsSchema,
58
+ CreateFunctionalTestingTestResponseSchema,
59
+ CreateFunctionalTestingTestStepSchema,
32
60
  GetFunctionalTestHistoryParamsSchema,
33
61
  GetFunctionalTestingExecutionTestSchema,
34
62
  GetFunctionalTestingSuiteExecutionSchema,
63
+ HTTP_METHODS,
35
64
  ListFunctionalTestingSuiteExecutionsSchema,
36
65
  RunFunctionalTestingSuiteParamsSchema,
37
66
  RunFunctionalTestingTestParamsSchema
@@ -106,7 +106,7 @@ const CreatePortalArgsSchema = z.object({
106
106
  "The display name for the portal - shown to users and in branding (3-40 characters)"
107
107
  ),
108
108
  subdomain: z.string().describe(
109
- "The portal subdomain - used in the portal URL (e.g., 'myportal' for myportal.example.com). Must be unique, lowercase, 3-20 characters, alphanumeric with hyphens"
109
+ "The portal subdomain - used in the portal URL (e.g., 'myportal' for myportal.example.com). Must be unique, lowercase, 3-20 characters, alphanumeric with hyphens. Recommended: slugified organization name plus a random 3-character suffix (e.g., 'acmecorp-k7p') to avoid collisions"
110
110
  ),
111
111
  offline: z.boolean().optional().describe(
112
112
  "If true, the portal will not be visible to customers - useful for development/staging environments. Defaults to false"
@@ -3,21 +3,29 @@ const SUBDOMAIN_MIN_LENGTH = 3;
3
3
  const SUBDOMAIN_MAX_LENGTH = 20;
4
4
  const PORTAL_NAME_MIN_LENGTH = 3;
5
5
  const PORTAL_NAME_MAX_LENGTH = 40;
6
- function slugify(value, maxLength) {
7
- return value.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, maxLength).replace(/-+$/, "");
8
- }
9
- function buildSubdomainCandidate(organizationId, organizationName) {
10
- const fallback = `portal-${organizationId.toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 8)}`;
11
- if (!organizationName) {
12
- return fallback;
6
+ function convertToValidSubdomain(value = "", rng = Math.random) {
7
+ let converted = value.toLowerCase().replace(/[^a-z0-9-]+/g, "").split("-").filter(Boolean).join("-");
8
+ while (converted.length < SUBDOMAIN_MIN_LENGTH) {
9
+ converted = `${converted}${Math.floor(rng() * 10)}`;
10
+ }
11
+ if (converted.length > SUBDOMAIN_MAX_LENGTH) {
12
+ converted = converted.slice(0, SUBDOMAIN_MAX_LENGTH);
13
+ if (converted.endsWith("-")) {
14
+ converted = converted.slice(0, -1);
15
+ }
13
16
  }
14
- const sanitized = slugify(organizationName, SUBDOMAIN_MAX_LENGTH);
15
- return sanitized.length >= SUBDOMAIN_MIN_LENGTH ? sanitized : fallback;
17
+ return converted;
18
+ }
19
+ function appendRandomSuffix(base, rng = Math.random) {
20
+ const randomChars = `-${rng().toString(36).substring(2, 5).padEnd(3, "0")}`;
21
+ const baseSlug = base.slice(0, SUBDOMAIN_MAX_LENGTH - randomChars.length).replace(/-+$/, "");
22
+ return `${baseSlug}${randomChars}`;
16
23
  }
17
- function buildSuffixedSubdomain(baseSubdomain, organizationId) {
18
- const idSuffix = organizationId.toLowerCase().replace(/[^a-z0-9]/g, "").slice(0, 4);
19
- const trimmedBase = baseSubdomain.slice(0, SUBDOMAIN_MAX_LENGTH - idSuffix.length - 1).replace(/-+$/, "");
20
- return `${trimmedBase}-${idSuffix}`;
24
+ function buildSubdomainCandidate(organizationName, rng = Math.random) {
25
+ return appendRandomSuffix(
26
+ convertToValidSubdomain(organizationName, rng),
27
+ rng
28
+ );
21
29
  }
22
30
  function buildPortalName(organizationName) {
23
31
  const trimmed = organizationName?.trim();
@@ -41,10 +49,10 @@ export {
41
49
  PORTAL_NAME_MIN_LENGTH,
42
50
  SUBDOMAIN_MAX_LENGTH,
43
51
  SUBDOMAIN_MIN_LENGTH,
52
+ appendRandomSuffix,
44
53
  buildPortalName,
45
54
  buildSubdomainCandidate,
46
- buildSuffixedSubdomain,
55
+ convertToValidSubdomain,
47
56
  isConflictError,
48
- isOrganizationPortalConflict,
49
- slugify
57
+ isOrganizationPortalConflict
50
58
  };
@@ -104,7 +104,8 @@ const StandardizeOutputSchema = z.looseObject({
104
104
  message: z.string().optional(),
105
105
  errorsFound: z.number().optional(),
106
106
  fixedDefinition: z.string().optional(),
107
- savedVersion: z.string().optional()
107
+ savedVersion: z.string().optional(),
108
+ url: z.string().optional()
108
109
  });
109
110
  const ApiDefinitionOutputSchema = z.object({
110
111
  definition: z.string()
@@ -5,12 +5,12 @@ const READ_ONLY = {
5
5
  };
6
6
  const WRITE = {
7
7
  readOnly: false,
8
- openWorld: true,
8
+ openWorld: false,
9
9
  destructive: false
10
10
  };
11
11
  const WRITE_DESTRUCTIVE = {
12
12
  readOnly: false,
13
- openWorld: true,
13
+ openWorld: false,
14
14
  destructive: true
15
15
  };
16
16
  export {
@@ -235,16 +235,18 @@ const TOOLS = [
235
235
  inputSchema: CreateApiFromPromptParamsSchema,
236
236
  outputSchema: CreateApiFromPromptOutputSchema,
237
237
  handler: "createApiFromPrompt",
238
- ...WRITE_DESTRUCTIVE
238
+ ...WRITE_DESTRUCTIVE,
239
+ openWorld: true
239
240
  },
240
241
  {
241
242
  title: "Standardize API",
242
243
  toolset: "Registry API",
243
- summary: "Standardize and fix an API definition using AI to ensure compliance with governance policies. Scans the API definition for standardization errors and automatically fixes them using SmartBear AI. Optionally provide 'newVersion' (e.g. patch bump '1.0.0' → '1.0.1') to save the fixed definition as a new version — omitting it will overwrite the current version. Returns the number of errors found and the fixed definition if successful. Use this tool when users ask to standardize, fix, govern, or ensure governance compliance of APIs.",
244
+ summary: "Standardize and fix an API definition using AI to ensure compliance with governance policies. Scans the API definition for standardization errors and automatically fixes them using SmartBear AI. Optionally provide 'newVersion' (e.g. patch bump '1.0.0' → '1.0.1') to save the fixed definition as a new version — omitting it will overwrite the current version. Returns the number of errors found, the fixed definition, and a URL to view the standardized API. Use this tool when users ask to standardize, fix, govern, or ensure governance compliance of APIs.",
244
245
  inputSchema: StandardizeApiParamsSchema,
245
246
  outputSchema: StandardizeOutputSchema,
246
247
  handler: "standardizeApi",
247
- ...WRITE_DESTRUCTIVE
248
+ ...WRITE_DESTRUCTIVE,
249
+ openWorld: true
248
250
  },
249
251
  ...FUNCTIONAL_TESTING_TOOLS
250
252
  ];
@@ -12,13 +12,13 @@ import { TOOLS } from "./client/tools.js";
12
12
  import "./client/user-management-types.js";
13
13
  const ConfigurationSchema = z.object({
14
14
  api_key: z.string().optional().describe("Swagger API key for authentication"),
15
- portal_base_path: z.string().optional().describe("Base path for Portal API requests (optional)"),
16
- registry_base_path: z.string().optional().describe("Base path for Registry API requests (optional)"),
17
- ui_base_path: z.string().optional().describe("Base URL for the SwaggerHub UI (optional)"),
15
+ portal_base_path: z.url().optional().describe("Base URL for Portal API requests (optional)"),
16
+ registry_base_path: z.url().optional().describe("Base path for Registry API requests (optional)"),
17
+ ui_base_path: z.url().optional().describe("Base URL for the SwaggerHub UI (optional)"),
18
18
  functional_testing_api_token: z.string().optional().describe(
19
19
  "Swagger Functional Testing API token. Leave empty to disable Functional Testing tools."
20
20
  ),
21
- functional_testing_base_path: z.string().optional().describe(
21
+ functional_testing_base_path: z.url().optional().describe(
22
22
  "Base URL for Swagger Functional Testing API requests (optional)"
23
23
  )
24
24
  });
@@ -172,6 +172,9 @@ class SwaggerClient {
172
172
  return this.getApi().standardizeApi(args);
173
173
  }
174
174
  // Functional Testing methods
175
+ async createFunctionalTestingTest(args) {
176
+ return this.withFunctionalTesting((ftApi) => ftApi.createTest(args));
177
+ }
175
178
  async listFunctionalTestingTests() {
176
179
  return this.withFunctionalTesting((ftApi) => ftApi.listTests());
177
180
  }
@@ -36,6 +36,7 @@ import { GetTestExecutions } from "./tool/test-execution/get-test-executions.js"
36
36
  import { GetTestExecutionSteps } from "./tool/test-execution/get-test-steps.js";
37
37
  import { UpdateTestExecution } from "./tool/test-execution/update-test-execution.js";
38
38
  import { UpdateTestExecutionSteps } from "./tool/test-execution/update-test-steps.js";
39
+ import { GetTestPlans } from "./tool/test-plan/get-test-plans.js";
39
40
  const BASE_URL_DEFAULT = "https://api.zephyrscale.smartbear.com/v2";
40
41
  const ConfigurationSchema = zod__default.object({
41
42
  api_token: zod__default.string().describe("Zephyr Scale API token for authentication"),
@@ -109,7 +110,8 @@ class ZephyrClient {
109
110
  new UpdateTestExecutionSteps(this),
110
111
  new GetTestExecutionSteps(this),
111
112
  new GetTestExecutionLinks(this),
112
- new GetTestExecutions$1(this)
113
+ new GetTestExecutions$1(this),
114
+ new GetTestPlans(this)
113
115
  ];
114
116
  for (const tool of tools) {
115
117
  register(tool.specification, tool.handle);