@smartbear/mcp 0.36.0 → 0.37.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.
@@ -71,13 +71,193 @@ const CreateFunctionalTestingTestHeaderSchema = z.object({
71
71
  value: z.string().describe("Header value")
72
72
  });
73
73
  const HTTP_METHODS = ["GET", "POST", "PUT", "PATCH", "DELETE"];
74
+ const CreateFunctionalTestingStatusRangeSchema = z.object({
75
+ start: z.number().int().min(100).max(599).describe("Start of the HTTP status code range, inclusive"),
76
+ end: z.number().int().min(100).max(599).describe("End of the HTTP status code range, inclusive")
77
+ }).refine((range) => range.start <= range.end, {
78
+ message: "start must be less than or equal to end",
79
+ path: ["start"]
80
+ });
81
+ const CreateFunctionalTestingBodyRuleSchema = z.object({
82
+ path: z.string().regex(
83
+ /^(\["[^"]*"\])+$/,
84
+ `Path must be in bracket notation, e.g. '["data"]["id"]'.`
85
+ ).describe(
86
+ `Path to the field to assert, in bracket notation (e.g. '["data"]["id"]').`
87
+ ),
88
+ assertionType: z.enum(["string", "number", "regex"]).describe("Type of assertion"),
89
+ operator: z.enum(["eq", "lt", "gt", "lte", "gte", "contains"]).optional().describe(
90
+ "Comparison operator for compare assertions. Required (with target) when targets is not set; not usable together with targets, lower/upper, or with assertionType 'regex'."
91
+ ),
92
+ target: z.string().optional().describe(
93
+ "Expected value for compare assertions. Required (with operator) when targets is not set; not usable together with targets, lower/upper, or with assertionType 'regex'."
94
+ ),
95
+ targets: z.array(z.string()).optional().describe(
96
+ "List of allowed values for a list-match assertion (assertionType 'string' or 'number' only). Not usable together with operator/target or lower/upper."
97
+ ),
98
+ lower: z.string().optional().describe(
99
+ "Lower bound for a number range assertion (assertionType 'number' only). Must be set together with upper."
100
+ ),
101
+ upper: z.string().optional().describe(
102
+ "Upper bound for a number range assertion (assertionType 'number' only). Must be set together with lower."
103
+ ),
104
+ pattern: z.enum(["nonempty"]).optional().describe(
105
+ "Pattern type for regex assertions. Required when assertionType is 'regex' (only 'nonempty' is supported - there is no way to assert against an arbitrary regex string)."
106
+ ),
107
+ assignment: z.string().optional().describe("Variable name to assign the extracted value to")
108
+ }).meta({
109
+ // Structural rules (in addition to the .superRefine() below) so the generated
110
+ // JSON Schema states which fields are required/forbidden per assertionType and
111
+ // assertion mode, instead of leaving every field optional with the constraint
112
+ // only in prose.
113
+ allOf: [
114
+ {
115
+ if: { properties: { assertionType: { const: "regex" } } },
116
+ // biome-ignore lint/suspicious/noThenProperty: JSON Schema if/then/else keyword, not a thenable
117
+ then: {
118
+ required: ["pattern"],
119
+ properties: {
120
+ operator: false,
121
+ target: false,
122
+ targets: false,
123
+ lower: false,
124
+ upper: false
125
+ }
126
+ },
127
+ message: "pattern is required, and operator/target/targets/lower/upper must not be set, when assertionType is 'regex'"
128
+ },
129
+ {
130
+ if: { not: { properties: { assertionType: { const: "regex" } } } },
131
+ // biome-ignore lint/suspicious/noThenProperty: JSON Schema if/then/else keyword, not a thenable
132
+ then: { properties: { pattern: false } },
133
+ message: "pattern must not be set unless assertionType is 'regex'"
134
+ },
135
+ {
136
+ if: { required: ["targets"] },
137
+ // biome-ignore lint/suspicious/noThenProperty: JSON Schema if/then/else keyword, not a thenable
138
+ then: {
139
+ properties: {
140
+ operator: false,
141
+ target: false,
142
+ lower: false,
143
+ upper: false
144
+ }
145
+ },
146
+ message: "targets cannot be combined with operator/target or lower/upper"
147
+ },
148
+ {
149
+ if: {
150
+ anyOf: [{ required: ["lower"] }, { required: ["upper"] }]
151
+ },
152
+ // biome-ignore lint/suspicious/noThenProperty: JSON Schema if/then/else keyword, not a thenable
153
+ then: {
154
+ required: ["lower", "upper"],
155
+ properties: {
156
+ assertionType: { const: "number" },
157
+ operator: false,
158
+ target: false,
159
+ targets: false
160
+ }
161
+ },
162
+ message: "lower and upper must both be set together, only with assertionType 'number', and cannot be combined with operator/target/targets"
163
+ }
164
+ ]
165
+ }).superRefine((rule, ctx) => {
166
+ const hasRange = rule.lower !== void 0 || rule.upper !== void 0;
167
+ const hasCompare = rule.operator !== void 0 || rule.target !== void 0;
168
+ const hasTargets = rule.targets !== void 0;
169
+ if (rule.assertionType === "regex") {
170
+ if (rule.pattern === void 0) {
171
+ ctx.addIssue({
172
+ code: "custom",
173
+ path: ["pattern"],
174
+ message: "pattern is required when assertionType is 'regex'."
175
+ });
176
+ }
177
+ if (hasCompare || hasTargets || hasRange) {
178
+ ctx.addIssue({
179
+ code: "custom",
180
+ path: ["assertionType"],
181
+ message: "operator, target, targets, lower and upper have no effect with assertionType 'regex' (the backend silently ignores them) and must not be set."
182
+ });
183
+ }
184
+ return;
185
+ }
186
+ if (rule.pattern !== void 0) {
187
+ ctx.addIssue({
188
+ code: "custom",
189
+ path: ["pattern"],
190
+ message: "pattern is only valid with assertionType 'regex'."
191
+ });
192
+ }
193
+ if (hasRange && rule.assertionType !== "number") {
194
+ ctx.addIssue({
195
+ code: "custom",
196
+ path: ["lower"],
197
+ message: "lower/upper range assertions are only valid with assertionType 'number'."
198
+ });
199
+ return;
200
+ }
201
+ if (hasTargets) {
202
+ if (hasCompare || hasRange) {
203
+ ctx.addIssue({
204
+ code: "custom",
205
+ path: ["targets"],
206
+ message: "targets defines a list-match assertion and cannot be combined with operator/target or lower/upper."
207
+ });
208
+ }
209
+ return;
210
+ }
211
+ if (hasRange) {
212
+ if (hasCompare) {
213
+ ctx.addIssue({
214
+ code: "custom",
215
+ path: ["lower"],
216
+ message: "lower/upper cannot be combined with operator/target."
217
+ });
218
+ }
219
+ if (rule.lower === void 0 || rule.upper === void 0) {
220
+ ctx.addIssue({
221
+ code: "custom",
222
+ path: ["lower"],
223
+ message: "Both lower and upper are required for a range assertion; setting only one silently evaluates as always-false at runtime."
224
+ });
225
+ }
226
+ return;
227
+ }
228
+ if (rule.operator === void 0) {
229
+ ctx.addIssue({
230
+ code: "custom",
231
+ path: ["operator"],
232
+ message: "operator is required for a compare assertion when targets/lower/upper are not set."
233
+ });
234
+ }
235
+ if (rule.target === void 0) {
236
+ ctx.addIssue({
237
+ code: "custom",
238
+ path: ["target"],
239
+ message: "target is required for a compare assertion when targets/lower/upper are not set."
240
+ });
241
+ }
242
+ });
243
+ const CreateFunctionalTestingAssertionsSchema = z.object({
244
+ statusCodes: z.array(CreateFunctionalTestingStatusRangeSchema).optional().describe(
245
+ "Expected HTTP status code ranges, e.g. [{start: 200, end: 299}]"
246
+ ),
247
+ body: z.string().optional().describe("Expected exact response body, compared as-is"),
248
+ bodyType: z.enum(["json", "xml"]).optional().describe('Response body format, defaults to "json"'),
249
+ bodyRules: z.array(CreateFunctionalTestingBodyRuleSchema).optional().describe("Assertion rules evaluated against the response body")
250
+ });
74
251
  const CreateFunctionalTestingTestStepSchema = z.object({
75
252
  url: z.url().describe("URL for the API call"),
76
253
  httpMethod: z.enum(HTTP_METHODS).describe("HTTP method for the API call (defaults to GET server-side)").optional(),
77
254
  requestBody: z.string().describe("Request body").optional(),
78
255
  requestHeaders: z.array(CreateFunctionalTestingTestHeaderSchema).describe("HTTP headers").optional(),
79
256
  followRedirects: z.boolean().describe("Whether to follow redirects").optional(),
80
- description: z.string().trim().describe("Human-readable label for this step").optional()
257
+ description: z.string().trim().describe("Human-readable label for this step").optional(),
258
+ assertions: CreateFunctionalTestingAssertionsSchema.optional().describe(
259
+ "Expected response assertions: status code ranges, exact body match, and/or field-level body rules."
260
+ )
81
261
  });
82
262
  const CreateFunctionalTestingTestParamsSchema = z.object({
83
263
  name: z.string().describe("Name for the new test").trim().min(1),
@@ -92,6 +272,9 @@ const CreateFunctionalTestingTestResponseSchema = z.object({
92
272
  });
93
273
  export {
94
274
  CancelFunctionalTestingSuiteExecutionSchema,
275
+ CreateFunctionalTestingAssertionsSchema,
276
+ CreateFunctionalTestingBodyRuleSchema,
277
+ CreateFunctionalTestingStatusRangeSchema,
95
278
  CreateFunctionalTestingSuiteParamsSchema,
96
279
  CreateFunctionalTestingSuiteResponseSchema,
97
280
  CreateFunctionalTestingTestHeaderSchema,
@@ -0,0 +1,31 @@
1
+ function countOccurrences(text, search) {
2
+ if (!search) return 0;
3
+ return text.split(search).length - 1;
4
+ }
5
+ function applyEdits(text, edits) {
6
+ const failed = [];
7
+ edits.forEach((edit, index) => {
8
+ const matchCount = countOccurrences(text, edit.oldString);
9
+ if (matchCount === 0) {
10
+ failed.push({
11
+ index,
12
+ oldString: edit.oldString,
13
+ error: "no_match",
14
+ matchCount: 0
15
+ });
16
+ } else if (matchCount > 1 && !edit.replaceAll) {
17
+ failed.push({
18
+ index,
19
+ oldString: edit.oldString,
20
+ error: "ambiguous",
21
+ matchCount
22
+ });
23
+ } else {
24
+ text = text.split(edit.oldString).join(edit.replaceString);
25
+ }
26
+ });
27
+ return { text, failed };
28
+ }
29
+ export {
30
+ applyEdits
31
+ };
@@ -23,6 +23,9 @@ const ApiDefinitionParamsSchema = z.object({
23
23
  ),
24
24
  flatten: z.boolean().optional().describe(
25
25
  "Set to true to create models from inline schemas in OpenAPI definition (default false)"
26
+ ),
27
+ format: z.enum(["json", "text"]).optional().describe(
28
+ "Response format: 'json' (default) may convert YAML to JSON; 'text' returns the definition as YAML — required for swagger_patch_api edits."
26
29
  )
27
30
  });
28
31
  const CreateApiParamsSchema = z.object({
@@ -69,6 +72,30 @@ const StandardizeApiParamsSchema = z.object({
69
72
  "The version to save the fixed definition as (e.g. '1.0.1'). Omitting this will overwrite the current version — prefer providing a patch bump (e.g. '1.0.0' → '1.0.1') unless the user specifies otherwise."
70
73
  )
71
74
  });
75
+ const PatchApiEditSchema = z.object({
76
+ oldString: z.string().min(1).describe(
77
+ "Exact text to find in the YAML definition (including indentation and newlines), copied from swagger_get_api_definition with format:'text'. Must match exactly one location unless replaceAll is true. For repeated text (e.g. 'responses:', 'description: OK'), start from the nearest unique parent key (path name, schema name, operationId)."
78
+ ),
79
+ replaceString: z.string().describe(
80
+ "Replacement text. Repeat the quoted context unchanged and change only the minimal part. An empty string deletes the matched text."
81
+ ),
82
+ replaceAll: z.boolean().optional().describe(
83
+ "Replace every occurrence of oldString instead of requiring a unique match (default false). Use for identical fixes at many flagged locations."
84
+ )
85
+ });
86
+ const PatchApiParamsSchema = z.object({
87
+ owner: z.string().describe("API owner (organization or user, case-sensitive)"),
88
+ apiName: z.string().describe("API name (case-sensitive)"),
89
+ version: z.string().describe(
90
+ "Version of the definition to patch (base version, e.g. '1.0.0')"
91
+ ),
92
+ newVersion: z.string().optional().describe(
93
+ "Version to save the patched definition as (e.g. '1.0.1'). Must not already exist and is always created as private. Omit to overwrite the base version, which keeps its current visibility. The definition's info.version is updated automatically — do not add an edit for it."
94
+ ),
95
+ edits: z.array(PatchApiEditSchema).min(1).max(50).describe(
96
+ "Search/replace edits applied sequentially to the YAML definition. Nothing is saved unless every edit applies (atomic)."
97
+ )
98
+ });
72
99
  const CreateApiOutputSchema = z.looseObject({
73
100
  owner: z.string().optional(),
74
101
  apiName: z.string().optional(),
@@ -122,6 +149,19 @@ const SearchApisOutputSchema = z.object({
122
149
  })
123
150
  )
124
151
  });
152
+ const PatchApiFailedEditSchema = z.object({
153
+ index: z.number().describe("Position of the failed edit in the request's edits array"),
154
+ oldString: z.string().describe("The failed edit's oldString"),
155
+ error: z.enum(["no_match", "ambiguous"]),
156
+ matchCount: z.number().describe("How many times search matched (0 for no_match)")
157
+ });
158
+ const PatchApiOutputSchema = z.looseObject({
159
+ failed: z.array(PatchApiFailedEditSchema).optional().describe("Only present when at least one edit failed"),
160
+ saved: z.boolean().optional(),
161
+ operation: z.enum(["create", "update"]).optional(),
162
+ version: z.string().optional(),
163
+ url: z.string().optional()
164
+ });
125
165
  export {
126
166
  ApiDefinitionOutputSchema,
127
167
  ApiDefinitionParamsSchema,
@@ -130,6 +170,10 @@ export {
130
170
  CreateApiFromPromptParamsSchema,
131
171
  CreateApiOutputSchema,
132
172
  CreateApiParamsSchema,
173
+ PatchApiEditSchema,
174
+ PatchApiFailedEditSchema,
175
+ PatchApiOutputSchema,
176
+ PatchApiParamsSchema,
133
177
  ScanApiStandardizationFromRegistryParamsSchema,
134
178
  ScanFromRegistryOutputSchema,
135
179
  ScanOutputSchema,
@@ -1,6 +1,6 @@
1
1
  import { FUNCTIONAL_TESTING_TOOLS } from "./functional-testing-tools.js";
2
2
  import { PortalsListOutputSchema, PortalOutputSchema, CreatePortalArgsSchema, PortalArgsSchema, UpdatePortalArgsSchema, ResolvePortalOutputSchema, ResolveOrganizationPortalArgsSchema, ProductsListOutputSchema, ProductOutputSchema, CreateProductArgsSchema, ProductArgsSchema, DeleteProductOutputSchema, UpdateProductArgsSchema, PublishOutputSchema, PublishProductArgsSchema, SectionsListOutputSchema, GetProductSectionsArgsSchema, CreateTocOutputSchema, CreateTableOfContentsArgsSchema, TocListOutputSchema, GetTableOfContentsArgsSchema, DeleteTableOfContentsOutputSchema, DeleteTableOfContentsArgsSchema, CreateDocPageOutputSchema, CreateDocumentationPageArgsSchema, DocumentOutputSchema, GetDocumentArgsSchema, UpdateDocumentArgsSchema } from "./portal-types.js";
3
- import { SearchApisOutputSchema, ApiSearchParamsSchema, ApiDefinitionOutputSchema, ApiDefinitionParamsSchema, CreateApiOutputSchema, CreateApiParamsSchema, ScanOutputSchema, ScanStandardizationParamsSchema, ScanFromRegistryOutputSchema, ScanApiStandardizationFromRegistryParamsSchema, CreateApiFromPromptOutputSchema, CreateApiFromPromptParamsSchema, StandardizeOutputSchema, StandardizeApiParamsSchema } from "./registry-types.js";
3
+ import { SearchApisOutputSchema, ApiSearchParamsSchema, ApiDefinitionOutputSchema, ApiDefinitionParamsSchema, CreateApiOutputSchema, CreateApiParamsSchema, ScanOutputSchema, ScanStandardizationParamsSchema, ScanFromRegistryOutputSchema, ScanApiStandardizationFromRegistryParamsSchema, CreateApiFromPromptOutputSchema, CreateApiFromPromptParamsSchema, StandardizeOutputSchema, StandardizeApiParamsSchema, PatchApiOutputSchema, PatchApiParamsSchema } from "./registry-types.js";
4
4
  import { READ_ONLY, WRITE, WRITE_DESTRUCTIVE } from "./tool-constants.js";
5
5
  import { OrganizationsListOutputSchema, OrganizationsQuerySchema } from "./user-management-types.js";
6
6
  const TOOLS = [
@@ -182,7 +182,7 @@ const TOOLS = [
182
182
  {
183
183
  title: "Get API Definition",
184
184
  toolset: "Registry API",
185
- summary: "Fetch resolved API definition from SwaggerHub Registry based on owner, API name, and version.",
185
+ summary: "Fetch resolved API definition from SwaggerHub Registry based on owner, API name, and version. By default returns the definition as JSON (converting YAML-stored definitions to JSON). Set format:'text' to get the YAML definition — required as the source for swagger_patch_api edits.",
186
186
  inputSchema: ApiDefinitionParamsSchema,
187
187
  outputSchema: ApiDefinitionOutputSchema,
188
188
  formatResponse: (result) => ({
@@ -248,6 +248,15 @@ const TOOLS = [
248
248
  ...WRITE_DESTRUCTIVE,
249
249
  openWorld: true
250
250
  },
251
+ {
252
+ title: "Patch API",
253
+ toolset: "Registry API",
254
+ summary: "Apply targeted search/replace edits to a YAML API definition in SwaggerHub Registry. Only OpenAPI and AsyncAPI definitions are supported. Each edit's 'oldString' must be copied exactly from swagger_get_api_definition with format:'text' and without 'resolved' or 'flatten' — those options transform the definition, so edits based on them will not match the stored source. JSON definitions are not supported. Nothing is saved unless every edit applies — failed edits are returned with 'no_match' or 'ambiguous' status. When 'newVersion' is given the patched definition is saved as a new private version; patching in place keeps the visibility of the existing version. Use this tool to fix specific issues in an existing API without regenerating the whole definition.",
255
+ inputSchema: PatchApiParamsSchema,
256
+ outputSchema: PatchApiOutputSchema,
257
+ handler: "patchApi",
258
+ ...WRITE_DESTRUCTIVE
259
+ },
251
260
  ...FUNCTIONAL_TESTING_TOOLS
252
261
  ];
253
262
  export {
@@ -1,3 +1,9 @@
1
+ function isAsyncAPI(specification = "") {
2
+ return /asyncapi\s*[:-]\s*['"]?\d+\./i.test(specification);
3
+ }
4
+ function isOpenAPI(specification = "") {
5
+ return /swagger\s*:\s*['"]?2\.0['"]?/i.test(specification) || /openapi\s*[:-]\s*['"]?3\.(0|1|2)\./i.test(specification);
6
+ }
1
7
  function normalizeSlug(value) {
2
8
  const slug = value.toLowerCase().trim().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "");
3
9
  if (slug.length < 3) {
@@ -33,5 +39,7 @@ function buildPortalLiveUrl(config, portal, productSlug, section, tocItem, previ
33
39
  export {
34
40
  buildPortalLiveUrl,
35
41
  findTableOfContentsItem,
42
+ isAsyncAPI,
43
+ isOpenAPI,
36
44
  normalizeSlug
37
45
  };
@@ -150,7 +150,8 @@ class SwaggerClient {
150
150
  return this.getApi().searchApis(args);
151
151
  }
152
152
  async getApiDefinition(args) {
153
- return this.getApi().getApiDefinition(args);
153
+ const accept = args.format === "text" ? "text/plain" : "application/json";
154
+ return this.getApi().getApiDefinition(args, { accept });
154
155
  }
155
156
  async createOrUpdateApi(args) {
156
157
  return this.getApi().createOrUpdateApi(args);
@@ -171,6 +172,9 @@ class SwaggerClient {
171
172
  async standardizeApi(args) {
172
173
  return this.getApi().standardizeApi(args);
173
174
  }
175
+ async patchApi(args) {
176
+ return this.getApi().patchApi(args);
177
+ }
174
178
  // Functional Testing methods
175
179
  async createFunctionalTestingTest(args) {
176
180
  return this.withFunctionalTesting((ftApi) => ftApi.createTest(args));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@smartbear/mcp",
3
- "version": "0.36.0",
3
+ "version": "0.37.0",
4
4
  "engines": {
5
5
  "node": ">=22"
6
6
  },