From 7c15c7ef2bfe90d60b9c97cfb5d900abe1a127bd Mon Sep 17 00:00:00 2001 From: "mcpopenapibot[bot]" <219997244+mcpopenapibot[bot]@users.noreply.github.com> Date: Thu, 11 Sep 2025 14:00:25 +0200 Subject: [PATCH 1/2] chore: sync tools and stdio/tests from postman-mcp-server (#44) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * chore: sync tools, entrypoint, and tests from postman-mcp-server * fixup! chore: sync tools, entrypoint, and tests from postman-mcp-server --------- Co-authored-by: garciasdos <25979809+garciasdos@users.noreply.github.com> Co-authored-by: Diego García --- dist/package.json | 2 +- dist/src/clients/postman.js | 97 +++++++---- dist/src/enabledResources.js | 5 +- dist/src/index.js | 55 ++++-- dist/src/tools/createCollection.js | 9 +- dist/src/tools/createCollectionComment.js | 11 +- dist/src/tools/createCollectionFolder.js | 9 +- dist/src/tools/createCollectionFork.js | 9 +- dist/src/tools/createCollectionRequest.js | 9 +- dist/src/tools/createCollectionResponse.js | 9 +- dist/src/tools/createEnvironment.js | 21 ++- dist/src/tools/createFolderComment.js | 11 +- dist/src/tools/createMock.js | 9 +- dist/src/tools/createMonitor.js | 10 +- dist/src/tools/createRequestComment.js | 11 +- dist/src/tools/createResponseComment.js | 11 +- dist/src/tools/createSpec.js | 46 ++--- dist/src/tools/createSpecFile.js | 9 +- dist/src/tools/createWorkspace.js | 9 +- dist/src/tools/deleteApiCollectionComment.js | 8 +- dist/src/tools/deleteCollection.js | 8 +- dist/src/tools/deleteCollectionComment.js | 8 +- dist/src/tools/deleteCollectionFolder.js | 8 +- dist/src/tools/deleteCollectionRequest.js | 8 +- dist/src/tools/deleteCollectionResponse.js | 8 +- dist/src/tools/deleteEnvironment.js | 8 +- dist/src/tools/deleteFolderComment.js | 8 +- dist/src/tools/deleteMock.js | 8 +- dist/src/tools/deleteMonitor.js | 8 +- dist/src/tools/deletePanElementOrFolder.js | 8 +- dist/src/tools/deleteRequestComment.js | 8 +- dist/src/tools/deleteResponseComment.js | 8 +- dist/src/tools/deleteSpec.js | 8 +- dist/src/tools/deleteSpecFile.js | 8 +- dist/src/tools/deleteWorkspace.js | 8 +- dist/src/tools/duplicateCollection.js | 9 +- dist/src/tools/generateCollection.js | 13 +- dist/src/tools/generateSpecFromCollection.js | 9 +- dist/src/tools/getAllElementsAndFolders.js | 8 +- dist/src/tools/getAllPanAddElementRequests.js | 8 +- dist/src/tools/getAllSpecs.js | 8 +- dist/src/tools/getAsyncSpecTaskStatus.js | 8 +- dist/src/tools/getAuthenticatedUser.js | 8 +- dist/src/tools/getCollection.js | 8 +- dist/src/tools/getCollectionComments.js | 8 +- dist/src/tools/getCollectionFolder.js | 8 +- dist/src/tools/getCollectionForks.js | 8 +- dist/src/tools/getCollectionRequest.js | 8 +- dist/src/tools/getCollectionResponse.js | 8 +- dist/src/tools/getCollectionTags.js | 8 +- dist/src/tools/getCollectionUpdatesTasks.js | 8 +- dist/src/tools/getCollections.js | 8 +- dist/src/tools/getCollectionsForkedByUser.js | 8 +- .../tools/getDuplicateCollectionTaskStatus.js | 8 +- dist/src/tools/getEnvironment.js | 8 +- dist/src/tools/getEnvironments.js | 8 +- dist/src/tools/getFolderComments.js | 8 +- dist/src/tools/getGeneratedCollectionSpecs.js | 8 +- dist/src/tools/getMock.js | 8 +- dist/src/tools/getMocks.js | 8 +- dist/src/tools/getMonitor.js | 8 +- dist/src/tools/getMonitors.js | 8 +- dist/src/tools/getRequestComments.js | 8 +- dist/src/tools/getResponseComments.js | 8 +- dist/src/tools/getSourceCollectionStatus.js | 8 +- dist/src/tools/getSpec.js | 8 +- dist/src/tools/getSpecCollections.js | 8 +- dist/src/tools/getSpecDefinition.js | 8 +- dist/src/tools/getSpecFile.js | 8 +- dist/src/tools/getSpecFiles.js | 8 +- ...ncTask.js => getStatusOfAnAsyncApiTask.js} | 10 +- dist/src/tools/getTaggedEntities.js | 8 +- dist/src/tools/getWorkspace.js | 8 +- dist/src/tools/getWorkspaceGlobalVariables.js | 8 +- dist/src/tools/getWorkspaceTags.js | 8 +- dist/src/tools/getWorkspaces.js | 8 +- dist/src/tools/mergeCollectionFork.js | 57 ++++++ dist/src/tools/patchCollection.js | 28 ++- dist/src/tools/patchEnvironment.js | 12 +- dist/src/tools/postPanElementOrFolder.js | 8 +- dist/src/tools/publishDocumentation.js | 9 +- dist/src/tools/publishMock.js | 8 +- dist/src/tools/pullCollectionChanges.js | 8 +- dist/src/tools/putCollection.js | 9 +- dist/src/tools/putEnvironment.js | 21 ++- dist/src/tools/resolveCommentThread.js | 8 +- dist/src/tools/runMonitor.js | 12 +- dist/src/tools/syncCollectionWithSpec.js | 8 +- dist/src/tools/syncSpecWithCollection.js | 8 +- dist/src/tools/transferCollectionFolders.js | 9 +- dist/src/tools/transferCollectionRequests.js | 9 +- dist/src/tools/transferCollectionResponses.js | 9 +- dist/src/tools/unpublishDocumentation.js | 8 +- dist/src/tools/unpublishMock.js | 8 +- dist/src/tools/updateApiCollectionComment.js | 9 +- dist/src/tools/updateCollectionComment.js | 9 +- dist/src/tools/updateCollectionFolder.js | 9 +- dist/src/tools/updateCollectionRequest.js | 9 +- dist/src/tools/updateCollectionResponse.js | 9 +- dist/src/tools/updateCollectionTags.js | 9 +- dist/src/tools/updateFolderComment.js | 9 +- dist/src/tools/updateMock.js | 9 +- dist/src/tools/updateMonitor.js | 10 +- dist/src/tools/updatePanElementOrFolder.js | 8 +- dist/src/tools/updateRequestComment.js | 9 +- dist/src/tools/updateResponseComment.js | 9 +- dist/src/tools/updateSpecFile.js | 9 +- dist/src/tools/updateSpecProperties.js | 9 +- dist/src/tools/updateWorkspace.js | 9 +- .../tools/updateWorkspaceGlobalVariables.js | 10 +- dist/src/tools/updateWorkspaceTags.js | 9 +- src/clients/postman.ts | 162 ++++++++++++++---- src/enabledResources.ts | 5 +- src/index.ts | 65 +++++-- src/tools/createCollection.ts | 11 +- src/tools/createCollectionComment.ts | 13 +- src/tools/createCollectionFolder.ts | 11 +- src/tools/createCollectionFork.ts | 11 +- src/tools/createCollectionRequest.ts | 11 +- src/tools/createCollectionResponse.ts | 11 +- src/tools/createEnvironment.ts | 31 ++-- src/tools/createFolderComment.ts | 13 +- src/tools/createMock.ts | 11 +- src/tools/createMonitor.ts | 12 +- src/tools/createRequestComment.ts | 13 +- src/tools/createResponseComment.ts | 13 +- src/tools/createSpec.ts | 56 +++--- src/tools/createSpecFile.ts | 11 +- src/tools/createWorkspace.ts | 11 +- src/tools/deleteApiCollectionComment.ts | 11 +- src/tools/deleteCollection.ts | 11 +- src/tools/deleteCollectionComment.ts | 11 +- src/tools/deleteCollectionFolder.ts | 11 +- src/tools/deleteCollectionRequest.ts | 11 +- src/tools/deleteCollectionResponse.ts | 11 +- src/tools/deleteEnvironment.ts | 11 +- src/tools/deleteFolderComment.ts | 11 +- src/tools/deleteMock.ts | 11 +- src/tools/deleteMonitor.ts | 11 +- src/tools/deletePanElementOrFolder.ts | 11 +- src/tools/deleteRequestComment.ts | 11 +- src/tools/deleteResponseComment.ts | 11 +- src/tools/deleteSpec.ts | 11 +- src/tools/deleteSpecFile.ts | 11 +- src/tools/deleteWorkspace.ts | 11 +- src/tools/duplicateCollection.ts | 11 +- src/tools/generateCollection.ts | 17 +- src/tools/generateSpecFromCollection.ts | 11 +- src/tools/getAllElementsAndFolders.ts | 11 +- src/tools/getAllPanAddElementRequests.ts | 11 +- src/tools/getAllSpecs.ts | 11 +- src/tools/getAsyncSpecTaskStatus.ts | 11 +- src/tools/getAuthenticatedUser.ts | 11 +- src/tools/getCollection.ts | 11 +- src/tools/getCollectionComments.ts | 11 +- src/tools/getCollectionFolder.ts | 11 +- src/tools/getCollectionForks.ts | 11 +- src/tools/getCollectionRequest.ts | 11 +- src/tools/getCollectionResponse.ts | 11 +- src/tools/getCollectionTags.ts | 11 +- src/tools/getCollectionUpdatesTasks.ts | 11 +- src/tools/getCollections.ts | 11 +- src/tools/getCollectionsForkedByUser.ts | 11 +- src/tools/getDuplicateCollectionTaskStatus.ts | 11 +- src/tools/getEnvironment.ts | 11 +- src/tools/getEnvironments.ts | 11 +- src/tools/getFolderComments.ts | 11 +- src/tools/getGeneratedCollectionSpecs.ts | 11 +- src/tools/getMock.ts | 11 +- src/tools/getMocks.ts | 11 +- src/tools/getMonitor.ts | 11 +- src/tools/getMonitors.ts | 11 +- src/tools/getRequestComments.ts | 11 +- src/tools/getResponseComments.ts | 11 +- src/tools/getSourceCollectionStatus.ts | 11 +- src/tools/getSpec.ts | 11 +- src/tools/getSpecCollections.ts | 11 +- src/tools/getSpecDefinition.ts | 11 +- src/tools/getSpecFile.ts | 11 +- src/tools/getSpecFiles.ts | 11 +- ...ncTask.ts => getStatusOfAnAsyncApiTask.ts} | 13 +- src/tools/getTaggedEntities.ts | 11 +- src/tools/getWorkspace.ts | 11 +- src/tools/getWorkspaceGlobalVariables.ts | 11 +- src/tools/getWorkspaceTags.ts | 11 +- src/tools/getWorkspaces.ts | 11 +- src/tools/mergeCollectionFork.ts | 63 +++++++ src/tools/patchCollection.ts | 34 ++-- src/tools/patchEnvironment.ts | 15 +- src/tools/postPanElementOrFolder.ts | 11 +- src/tools/publishDocumentation.ts | 11 +- src/tools/publishMock.ts | 11 +- src/tools/pullCollectionChanges.ts | 11 +- src/tools/putCollection.ts | 11 +- src/tools/putEnvironment.ts | 31 ++-- src/tools/resolveCommentThread.ts | 11 +- src/tools/runMonitor.ts | 15 +- src/tools/syncCollectionWithSpec.ts | 11 +- src/tools/syncSpecWithCollection.ts | 11 +- src/tools/transferCollectionFolders.ts | 11 +- src/tools/transferCollectionRequests.ts | 11 +- src/tools/transferCollectionResponses.ts | 11 +- src/tools/unpublishDocumentation.ts | 11 +- src/tools/unpublishMock.ts | 11 +- src/tools/updateApiCollectionComment.ts | 11 +- src/tools/updateCollectionComment.ts | 11 +- src/tools/updateCollectionFolder.ts | 11 +- src/tools/updateCollectionRequest.ts | 11 +- src/tools/updateCollectionResponse.ts | 11 +- src/tools/updateCollectionTags.ts | 11 +- src/tools/updateFolderComment.ts | 11 +- src/tools/updateMock.ts | 11 +- src/tools/updateMonitor.ts | 12 +- src/tools/updatePanElementOrFolder.ts | 11 +- src/tools/updateRequestComment.ts | 11 +- src/tools/updateResponseComment.ts | 11 +- src/tools/updateSpecFile.ts | 11 +- src/tools/updateSpecProperties.ts | 11 +- src/tools/updateWorkspace.ts | 11 +- src/tools/updateWorkspaceGlobalVariables.ts | 12 +- src/tools/updateWorkspaceTags.ts | 11 +- 221 files changed, 1420 insertions(+), 1386 deletions(-) rename dist/src/tools/{getStatusOfAnAsyncTask.js => getStatusOfAnAsyncApiTask.js} (86%) create mode 100644 dist/src/tools/mergeCollectionFork.js rename src/tools/{getStatusOfAnAsyncTask.ts => getStatusOfAnAsyncApiTask.ts} (84%) create mode 100644 src/tools/mergeCollectionFork.ts diff --git a/dist/package.json b/dist/package.json index 9a5ebaa..dbbd7b1 100644 --- a/dist/package.json +++ b/dist/package.json @@ -1,6 +1,6 @@ { "name": "@postman/postman-mcp-server", - "version": "2.1.2", + "version": "2.1.4", "description": "A simple MCP server to operate on the Postman API", "main": "dist/src/index.js", "type": "module", diff --git a/dist/src/clients/postman.js b/dist/src/clients/postman.js index 7d5ff21..27788e2 100644 --- a/dist/src/clients/postman.js +++ b/dist/src/clients/postman.js @@ -1,31 +1,77 @@ -import { ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js'; +import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; import packageJson from '../../package.json' with { type: 'json' }; -const BASE_URL = 'https://api.postman.com'; export var ContentType; (function (ContentType) { ContentType["Json"] = "application/json"; ContentType["JsonPatch"] = "application/json-patch+json"; })(ContentType || (ContentType = {})); -export async function fetchPostmanAPI(endpoint, options) { - const apiKey = options.apiKey || process.env.POSTMAN_API_KEY; - if (!apiKey) { - throw new Error('API key is required.'); - } - const contentType = options.contentType || ContentType.Json; - const userAgentHeader = options.headers && 'user-agent' in options.headers - ? `${options.headers['user-agent']}/${packageJson.name}/${packageJson.version}` - : `${packageJson.name}/${packageJson.version}`; - const headers = { - 'content-type': contentType, - 'x-api-key': apiKey, - 'user-agent': userAgentHeader, - }; - const { headers: _, ...optionsWithoutHeaders } = options; - const response = await fetch(`${BASE_URL}${endpoint}`, { - ...optionsWithoutHeaders, - headers, - }); - if (!response.ok) { +export class PostmanAPIClient { + baseUrl; + apiKey; + static instance = null; + constructor(apiKey, baseUrl = process.env.POSTMAN_API_BASE_URL || 'https://api.postman.com') { + if (!apiKey && !process.env.POSTMAN_API_KEY) { + throw new Error('API key is required. Provide it as parameter or set POSTMAN_API_KEY environment variable.'); + } + this.apiKey = apiKey || process.env.POSTMAN_API_KEY; + this.baseUrl = baseUrl; + } + static getInstance(apiKey, baseUrl) { + if (!PostmanAPIClient.instance) { + const key = apiKey || process.env.POSTMAN_API_KEY; + if (!key) { + throw new Error('API key is required. Provide it as parameter or set POSTMAN_API_KEY environment variable.'); + } + PostmanAPIClient.instance = new PostmanAPIClient(key, baseUrl); + } + return PostmanAPIClient.instance; + } + static resetInstance() { + PostmanAPIClient.instance = null; + } + async get(endpoint, options = {}) { + return this.request(endpoint, { ...options, method: 'GET' }); + } + async post(endpoint, options = {}) { + return this.request(endpoint, { ...options, method: 'POST' }); + } + async put(endpoint, options = {}) { + return this.request(endpoint, { ...options, method: 'PUT' }); + } + async patch(endpoint, options = {}) { + return this.request(endpoint, { ...options, method: 'PATCH' }); + } + async delete(endpoint, options = {}) { + return this.request(endpoint, { ...options, method: 'DELETE' }); + } + async request(endpoint, options) { + const contentType = options.contentType || ContentType.Json; + const userAgentHeader = options.headers && 'user-agent' in options.headers + ? `${options.headers['user-agent']}/${packageJson.name}/${packageJson.version}` + : `${packageJson.name}/${packageJson.version}`; + const headers = { + 'content-type': contentType, + 'x-api-key': this.apiKey, + 'user-agent': userAgentHeader, + ...options.headers, + }; + const { headers: _, ...optionsWithoutHeaders } = options; + const response = await fetch(`${this.baseUrl}${endpoint}`, { + ...optionsWithoutHeaders, + headers, + }); + if (!response.ok) { + await this.handleErrorResponse(response); + } + if (response.status === 204) + return null; + const responseContentType = response.headers.get('content-type') || ''; + if (responseContentType.includes('application/json')) { + return response.json(); + } + return response.text(); + } + async handleErrorResponse(response) { const errorText = await response.text(); switch (response.status) { case 400: @@ -41,11 +87,4 @@ export async function fetchPostmanAPI(endpoint, options) { }); } } - if (response.status === 204) - return null; - const responseContentType = response.headers.get('content-type') || ''; - if (responseContentType.includes('application/json')) { - return response.json(); - } - return response.text(); } diff --git a/dist/src/enabledResources.js b/dist/src/enabledResources.js index fe1fe4c..4a64734 100644 --- a/dist/src/enabledResources.js +++ b/dist/src/enabledResources.js @@ -19,7 +19,7 @@ const full = [ 'getCollectionsForkedByUser', 'pullCollectionChanges', 'createCollectionFork', - 'collection-merges', + 'mergeCollectionFork', 'createCollectionFolder', 'deleteCollectionFolder', 'getCollectionFolder', @@ -99,7 +99,7 @@ const full = [ 'publishDocumentation', 'unpublishDocumentation', 'getAsyncSpecTaskStatus', - 'getStatusOfAnAsyncTask', + 'getStatusOfAnAsyncApiTask', 'getAuthenticatedUser', 'getTaggedEntities', 'transferCollectionFolders', @@ -148,6 +148,7 @@ const minimal = [ 'createCollectionRequest', 'createCollectionResponse', 'duplicateCollection', + 'getStatusOfAnAsyncApiTask', ]; const excludedFromGeneration = ['createCollection', 'putCollection']; export const enabledResources = { diff --git a/dist/src/index.js b/dist/src/index.js index 0438600..83a1689 100755 --- a/dist/src/index.js +++ b/dist/src/index.js @@ -9,6 +9,20 @@ import { readdir } from 'node:fs/promises'; import { join, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import { enabledResources } from './enabledResources.js'; +import { PostmanAPIClient } from './clients/postman.js'; +const SUPPORTED_REGIONS = { + us: 'https://api.postman.com', + eu: 'https://api.eu.postman.com', +}; +function isValidRegion(region) { + return region in SUPPORTED_REGIONS; +} +function setRegionEnvironment(region) { + if (!isValidRegion(region)) { + throw new Error(`Invalid region: ${region}. Supported regions: us, eu`); + } + process.env.POSTMAN_API_BASE_URL = SUPPORTED_REGIONS[region]; +} function log(level, message, context) { const timestamp = new Date().toISOString(); const suffix = context ? ` ${JSON.stringify(context)}` : ''; @@ -74,17 +88,33 @@ dotenv.config(); const SERVER_NAME = packageJson.name; const APP_VERSION = packageJson.version; export const USER_AGENT = `${SERVER_NAME}/${APP_VERSION}`; -let currentApiKey = undefined; let clientInfo = undefined; -const allGeneratedTools = await loadAllTools(); -log('info', 'Server initialization starting', { - serverName: SERVER_NAME, - version: APP_VERSION, - toolCount: allGeneratedTools.length, -}); async function run() { const args = process.argv.slice(2); const useFull = args.includes('--full'); + const regionIndex = args.findIndex((arg) => arg === '--region'); + if (regionIndex !== -1 && regionIndex + 1 < args.length) { + const region = args[regionIndex + 1]; + if (isValidRegion(region)) { + setRegionEnvironment(region); + log('info', `Using region: ${region}`, { + region, + baseUrl: process.env.POSTMAN_API_BASE_URL, + }); + } + else { + log('error', `Invalid region: ${region}`); + console.error(`Supported regions: ${Object.keys(SUPPORTED_REGIONS).join(', ')}`); + process.exit(1); + } + } + const client = PostmanAPIClient.getInstance(); + const allGeneratedTools = await loadAllTools(); + log('info', 'Server initialization starting', { + serverName: SERVER_NAME, + version: APP_VERSION, + toolCount: allGeneratedTools.length, + }); const fullTools = allGeneratedTools.filter((t) => enabledResources.full.includes(t.method)); const minimalTools = allGeneratedTools.filter((t) => enabledResources.minimal.includes(t.method)); const tools = useFull ? fullTools : minimalTools; @@ -110,12 +140,8 @@ async function run() { const args = request.params.arguments || {}; try { const start = Date.now(); - if (!currentApiKey) { - log('error', 'Missing API key for tool invocation', { toolName }); - throw new McpError(ErrorCode.InvalidParams, 'API key is required.'); - } const result = await tool.handler(args, { - apiKey: currentApiKey, + client, headers: { ...extra.requestInfo?.headers, 'user-agent': clientInfo?.name, @@ -148,11 +174,6 @@ async function run() { })); return { tools: transformedTools }; }); - currentApiKey = process.env.POSTMAN_API_KEY; - if (!currentApiKey) { - log('error', 'POSTMAN_API_KEY is required'); - process.exit(1); - } log('info', 'Starting stdio transport'); const transport = new StdioServerTransport(); transport.onmessage = (message) => { diff --git a/dist/src/tools/createCollection.js b/dist/src/tools/createCollection.js index 781e660..6e31d91 100644 --- a/dist/src/tools/createCollection.js +++ b/dist/src/tools/createCollection.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -797,13 +797,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.collection !== undefined) bodyPayload.collection = params.collection; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createCollectionComment.js b/dist/src/tools/createCollectionComment.js index 03087be..eabaeca 100644 --- a/dist/src/tools/createCollectionComment.js +++ b/dist/src/tools/createCollectionComment.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -17,7 +17,7 @@ export const parameters = z.object({ .optional(), tags: z .object({ - userName: z + '{{userName}}': z .object({ type: z.literal('user').describe('The `user` value.'), id: z.string().describe("The user's ID."), @@ -46,13 +46,12 @@ export async function handler(params, extra) { bodyPayload.threadId = params.threadId; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createCollectionFolder.js b/dist/src/tools/createCollectionFolder.js index 3976bfa..3f346d5 100644 --- a/dist/src/tools/createCollectionFolder.js +++ b/dist/src/tools/createCollectionFolder.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -31,13 +31,12 @@ export async function handler(params, extra) { bodyPayload.name = params.name; if (params.folder !== undefined) bodyPayload.folder = params.folder; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createCollectionFork.js b/dist/src/tools/createCollectionFork.js index 0f81a5c..288bf15 100644 --- a/dist/src/tools/createCollectionFork.js +++ b/dist/src/tools/createCollectionFork.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -28,13 +28,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.label !== undefined) bodyPayload.label = params.label; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createCollectionRequest.js b/dist/src/tools/createCollectionRequest.js index 77f6cc6..f0cac56 100644 --- a/dist/src/tools/createCollectionRequest.js +++ b/dist/src/tools/createCollectionRequest.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -34,13 +34,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.name !== undefined) bodyPayload.name = params.name; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createCollectionResponse.js b/dist/src/tools/createCollectionResponse.js index f296b59..223ab1f 100644 --- a/dist/src/tools/createCollectionResponse.js +++ b/dist/src/tools/createCollectionResponse.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -31,13 +31,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.name !== undefined) bodyPayload.name = params.name; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createEnvironment.js b/dist/src/tools/createEnvironment.js index 303e953..2dfa207 100644 --- a/dist/src/tools/createEnvironment.js +++ b/dist/src/tools/createEnvironment.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -13,12 +13,18 @@ export const parameters = z.object({ .object({ name: z.string().describe("The environment's name."), values: z - .array(z.object({ + .array(z + .object({ enabled: z.boolean().describe('If true, the variable is enabled.').optional(), key: z.string().describe("The variable's name.").optional(), value: z.string().describe("The variable's value.").optional(), - type: z.enum(['secret', 'default']).describe('The variable type.').optional(), - })) + type: z + .enum(['secret', 'default']) + .describe("The variable's type:\n- `secret` — The variable value is masked.\n- `default` — The variable value is visible in plain text.\n") + .optional(), + description: z.string().max(512).describe("The variable's description.").optional(), + }) + .describe("Information about the environment's variables.")) .describe("Information about the environment's variables.") .optional(), }) @@ -41,13 +47,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.environment !== undefined) bodyPayload.environment = params.environment; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createFolderComment.js b/dist/src/tools/createFolderComment.js index 14539be..3d8cd3e 100644 --- a/dist/src/tools/createFolderComment.js +++ b/dist/src/tools/createFolderComment.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -18,7 +18,7 @@ export const parameters = z.object({ .optional(), tags: z .object({ - userName: z + '{{userName}}': z .object({ type: z.literal('user').describe('The `user` value.'), id: z.string().describe("The user's ID."), @@ -47,13 +47,12 @@ export async function handler(params, extra) { bodyPayload.threadId = params.threadId; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createMock.js b/dist/src/tools/createMock.js index 018f16b..219ac0e 100644 --- a/dist/src/tools/createMock.js +++ b/dist/src/tools/createMock.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -40,13 +40,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.mock !== undefined) bodyPayload.mock = params.mock; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createMonitor.js b/dist/src/tools/createMonitor.js index e292e82..5bb95cc 100644 --- a/dist/src/tools/createMonitor.js +++ b/dist/src/tools/createMonitor.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -36,6 +36,7 @@ export const parameters = z.object({ .describe('The number of times to reattempt a monitor run if it fails or errors. This may impact your [monitor usage](https://learning.postman.com/docs/monitoring-your-api/monitor-usage/#view-monitor-usage).') .optional(), }) + .describe("Information about the monitor's retry settings.") .optional(), options: z .object({ @@ -130,13 +131,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.monitor !== undefined) bodyPayload.monitor = params.monitor; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createRequestComment.js b/dist/src/tools/createRequestComment.js index 3de12b6..8058e7c 100644 --- a/dist/src/tools/createRequestComment.js +++ b/dist/src/tools/createRequestComment.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -20,7 +20,7 @@ export const parameters = z.object({ .optional(), tags: z .object({ - userName: z + '{{userName}}': z .object({ type: z.literal('user').describe('The `user` value.'), id: z.string().describe("The user's ID."), @@ -49,13 +49,12 @@ export async function handler(params, extra) { bodyPayload.threadId = params.threadId; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createResponseComment.js b/dist/src/tools/createResponseComment.js index 1412033..5c119d6 100644 --- a/dist/src/tools/createResponseComment.js +++ b/dist/src/tools/createResponseComment.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -18,7 +18,7 @@ export const parameters = z.object({ .optional(), tags: z .object({ - userName: z + '{{userName}}': z .object({ type: z.literal('user').describe('The `user` value.'), id: z.string().describe("The user's ID."), @@ -47,13 +47,12 @@ export async function handler(params, extra) { bodyPayload.threadId = params.threadId; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createSpec.js b/dist/src/tools/createSpec.js index a05a8e8..701dc7c 100644 --- a/dist/src/tools/createSpec.js +++ b/dist/src/tools/createSpec.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -12,30 +12,19 @@ export const parameters = z.object({ name: z.string().describe("The specification's name."), type: z.enum(['OPENAPI:3.0', 'ASYNCAPI:2.0']).describe("The specification's type."), files: z - .array(z.any().superRefine((x, ctx) => { - const schemas = [ - z.object({ - path: z.string().describe("The file's path. Accepts JSON or YAML files."), - content: z.string().describe("The file's stringified contents."), - type: z - .enum(['DEFAULT', 'ROOT']) - .describe('The type of file. This property is required when creating multi-file specifications:\n- `ROOT` — The file containing the full OpenAPI structure. This serves as the entry point for the API spec and references other (`DEFAULT`) spec files. Multi-file specs can only have one root file.\n- `DEFAULT` — A file referenced by the `ROOT` file.\n'), - }), - z.object({ - path: z.string().describe("The file's path. Accepts JSON or YAML files."), - content: z.string().describe("The file's stringified contents."), - }), - ]; - const errors = schemas.reduce((errors, schema) => ((result) => (result.error ? [...errors, result.error] : errors))(schema.safeParse(x)), []); - if (schemas.length - errors.length !== 1) { - ctx.addIssue({ - path: ctx.path, - code: 'invalid_union', - unionErrors: errors, - message: 'Invalid input: Should pass single schema', - }); - } - })) + .array(z.union([ + z.object({ + path: z.string().describe("The file's path. Accepts JSON or YAML files."), + content: z.string().describe("The file's stringified contents."), + type: z + .enum(['DEFAULT', 'ROOT']) + .describe('The type of file. This property is required when creating multi-file specifications:\n- `ROOT` — The file containing the full OpenAPI structure. This serves as the entry point for the API spec and references other (`DEFAULT`) spec files. Multi-file specs can only have one root file.\n- `DEFAULT` — A file referenced by the `ROOT` file.\n'), + }), + z.object({ + path: z.string().describe("The file's path. Accepts JSON or YAML files."), + content: z.string().describe("The file's stringified contents."), + }), + ])) .describe("A list of the specification's files and their contents."), }); export const annotations = { @@ -58,13 +47,12 @@ export async function handler(params, extra) { bodyPayload.type = params.type; if (params.files !== undefined) bodyPayload.files = params.files; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createSpecFile.js b/dist/src/tools/createSpecFile.js index 9f1bbb6..eafa9fc 100644 --- a/dist/src/tools/createSpecFile.js +++ b/dist/src/tools/createSpecFile.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -28,13 +28,12 @@ export async function handler(params, extra) { bodyPayload.path = params.path; if (params.content !== undefined) bodyPayload.content = params.content; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/createWorkspace.js b/dist/src/tools/createWorkspace.js index 539099a..789b415 100644 --- a/dist/src/tools/createWorkspace.js +++ b/dist/src/tools/createWorkspace.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -34,13 +34,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.workspace !== undefined) bodyPayload.workspace = params.workspace; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/deleteApiCollectionComment.js b/dist/src/tools/deleteApiCollectionComment.js index af86319..a01b17d 100644 --- a/dist/src/tools/deleteApiCollectionComment.js +++ b/dist/src/tools/deleteApiCollectionComment.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -23,11 +22,10 @@ export async function handler(params, extra) { const endpoint = `/apis/${params.apiId}/collections/${params.collectionId}/comments/${params.commentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteCollection.js b/dist/src/tools/deleteCollection.js index 9f4c082..39065b2 100644 --- a/dist/src/tools/deleteCollection.js +++ b/dist/src/tools/deleteCollection.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -23,11 +22,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteCollectionComment.js b/dist/src/tools/deleteCollectionComment.js index 112ba1a..f944247 100644 --- a/dist/src/tools/deleteCollectionComment.js +++ b/dist/src/tools/deleteCollectionComment.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -22,11 +21,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/comments/${params.commentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteCollectionFolder.js b/dist/src/tools/deleteCollectionFolder.js index b159c6a..ea60315 100644 --- a/dist/src/tools/deleteCollectionFolder.js +++ b/dist/src/tools/deleteCollectionFolder.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -22,11 +21,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/folders/${params.folderId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteCollectionRequest.js b/dist/src/tools/deleteCollectionRequest.js index ab03530..5509a21 100644 --- a/dist/src/tools/deleteCollectionRequest.js +++ b/dist/src/tools/deleteCollectionRequest.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -22,11 +21,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/requests/${params.requestId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteCollectionResponse.js b/dist/src/tools/deleteCollectionResponse.js index 647fb48..a768f98 100644 --- a/dist/src/tools/deleteCollectionResponse.js +++ b/dist/src/tools/deleteCollectionResponse.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -22,11 +21,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/responses/${params.responseId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteEnvironment.js b/dist/src/tools/deleteEnvironment.js index ca3b841..341a862 100644 --- a/dist/src/tools/deleteEnvironment.js +++ b/dist/src/tools/deleteEnvironment.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/environments/${params.environmentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteFolderComment.js b/dist/src/tools/deleteFolderComment.js index 3c611b1..b8db80b 100644 --- a/dist/src/tools/deleteFolderComment.js +++ b/dist/src/tools/deleteFolderComment.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -23,11 +22,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/folders/${params.folderId}/comments/${params.commentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteMock.js b/dist/src/tools/deleteMock.js index 8e97579..fbf9d1c 100644 --- a/dist/src/tools/deleteMock.js +++ b/dist/src/tools/deleteMock.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/mocks/${params.mockId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteMonitor.js b/dist/src/tools/deleteMonitor.js index aa9901b..4ac19d4 100644 --- a/dist/src/tools/deleteMonitor.js +++ b/dist/src/tools/deleteMonitor.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/monitors/${params.monitorId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deletePanElementOrFolder.js b/dist/src/tools/deletePanElementOrFolder.js index e6c4152..0c201aa 100644 --- a/dist/src/tools/deletePanElementOrFolder.js +++ b/dist/src/tools/deletePanElementOrFolder.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -24,11 +23,10 @@ export async function handler(params, extra) { const endpoint = `/network/private/${params.elementType}/${params.elementId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteRequestComment.js b/dist/src/tools/deleteRequestComment.js index 2e16328..d5cd9b6 100644 --- a/dist/src/tools/deleteRequestComment.js +++ b/dist/src/tools/deleteRequestComment.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -23,11 +22,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/requests/${params.requestId}/comments/${params.commentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteResponseComment.js b/dist/src/tools/deleteResponseComment.js index acea68b..f042440 100644 --- a/dist/src/tools/deleteResponseComment.js +++ b/dist/src/tools/deleteResponseComment.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -23,11 +22,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/responses/${params.responseId}/comments/${params.commentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteSpec.js b/dist/src/tools/deleteSpec.js index c8a80bc..2607474 100644 --- a/dist/src/tools/deleteSpec.js +++ b/dist/src/tools/deleteSpec.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/specs/${params.specId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteSpecFile.js b/dist/src/tools/deleteSpecFile.js index 26c7da5..3e67ffc 100644 --- a/dist/src/tools/deleteSpecFile.js +++ b/dist/src/tools/deleteSpecFile.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -22,11 +21,10 @@ export async function handler(params, extra) { const endpoint = `/specs/${params.specId}/files/${params.filePath}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/deleteWorkspace.js b/dist/src/tools/deleteWorkspace.js index d08ee66..5b27ecd 100644 --- a/dist/src/tools/deleteWorkspace.js +++ b/dist/src/tools/deleteWorkspace.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/workspaces/${params.workspaceId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/duplicateCollection.js b/dist/src/tools/duplicateCollection.js index ba9104b..9b8897f 100644 --- a/dist/src/tools/duplicateCollection.js +++ b/dist/src/tools/duplicateCollection.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -31,13 +31,12 @@ export async function handler(params, extra) { bodyPayload.workspace = params.workspace; if (params.suffix !== undefined) bodyPayload.suffix = params.suffix; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/generateCollection.js b/dist/src/tools/generateCollection.js index edf8cec..91cbc88 100644 --- a/dist/src/tools/generateCollection.js +++ b/dist/src/tools/generateCollection.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -49,6 +49,10 @@ export const parameters = z.object({ .boolean() .describe('Whether authentication details should be included in all requests, or always inherited from the collection.') .default(false), + nestedFolderHierarchy: z + .boolean() + .describe("If true, creates subfolders in the generated collection based on the order of the endpoints' tags.") + .default(false), }) .describe("The advanced creation options and their values. For more details, see Postman's [OpenAPI to Postman Collection Converter OPTIONS documentation](https://github.com/postmanlabs/openapi-to-postman/blob/develop/OPTIONS.md). These properties are case-sensitive.") .optional(), @@ -69,13 +73,12 @@ export async function handler(params, extra) { bodyPayload.name = params.name; if (params.options !== undefined) bodyPayload.options = params.options; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/generateSpecFromCollection.js b/dist/src/tools/generateSpecFromCollection.js index 4e15e41..4099bbe 100644 --- a/dist/src/tools/generateSpecFromCollection.js +++ b/dist/src/tools/generateSpecFromCollection.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -32,13 +32,12 @@ export async function handler(params, extra) { bodyPayload.type = params.type; if (params.format !== undefined) bodyPayload.format = params.format; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/getAllElementsAndFolders.js b/dist/src/tools/getAllElementsAndFolders.js index db4e561..a7e6469 100644 --- a/dist/src/tools/getAllElementsAndFolders.js +++ b/dist/src/tools/getAllElementsAndFolders.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -105,11 +104,10 @@ export async function handler(params, extra) { if (params.type !== undefined) query.set('type', String(params.type)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getAllPanAddElementRequests.js b/dist/src/tools/getAllPanAddElementRequests.js index b3ddd25..4727086 100644 --- a/dist/src/tools/getAllPanAddElementRequests.js +++ b/dist/src/tools/getAllPanAddElementRequests.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -82,11 +81,10 @@ export async function handler(params, extra) { if (params.limit !== undefined) query.set('limit', String(params.limit)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getAllSpecs.js b/dist/src/tools/getAllSpecs.js index 1c87d7b..3fe0d5c 100644 --- a/dist/src/tools/getAllSpecs.js +++ b/dist/src/tools/getAllSpecs.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -36,11 +35,10 @@ export async function handler(params, extra) { if (params.limit !== undefined) query.set('limit', String(params.limit)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getAsyncSpecTaskStatus.js b/dist/src/tools/getAsyncSpecTaskStatus.js index d2e5304..2375bbc 100644 --- a/dist/src/tools/getAsyncSpecTaskStatus.js +++ b/dist/src/tools/getAsyncSpecTaskStatus.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -23,11 +22,10 @@ export async function handler(params, extra) { const endpoint = `/${params.elementType}/${params.elementId}/tasks/${params.taskId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getAuthenticatedUser.js b/dist/src/tools/getAuthenticatedUser.js index 175d820..1cf8aaa 100644 --- a/dist/src/tools/getAuthenticatedUser.js +++ b/dist/src/tools/getAuthenticatedUser.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/me`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getCollection.js b/dist/src/tools/getCollection.js index c275f16..e27a4e3 100644 --- a/dist/src/tools/getCollection.js +++ b/dist/src/tools/getCollection.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -35,11 +34,10 @@ export async function handler(params, extra) { if (params.model !== undefined) query.set('model', String(params.model)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getCollectionComments.js b/dist/src/tools/getCollectionComments.js index 26cb447..6b51be2 100644 --- a/dist/src/tools/getCollectionComments.js +++ b/dist/src/tools/getCollectionComments.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -21,11 +20,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/comments`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getCollectionFolder.js b/dist/src/tools/getCollectionFolder.js index ffa03e1..aa8fbde 100644 --- a/dist/src/tools/getCollectionFolder.js +++ b/dist/src/tools/getCollectionFolder.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -37,11 +36,10 @@ export async function handler(params, extra) { if (params.populate !== undefined) query.set('populate', String(params.populate)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getCollectionForks.js b/dist/src/tools/getCollectionForks.js index 4f73ede..c3b31e3 100644 --- a/dist/src/tools/getCollectionForks.js +++ b/dist/src/tools/getCollectionForks.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -40,11 +39,10 @@ export async function handler(params, extra) { if (params.direction !== undefined) query.set('direction', String(params.direction)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getCollectionRequest.js b/dist/src/tools/getCollectionRequest.js index 000b132..dfcd181 100644 --- a/dist/src/tools/getCollectionRequest.js +++ b/dist/src/tools/getCollectionRequest.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -37,11 +36,10 @@ export async function handler(params, extra) { if (params.populate !== undefined) query.set('populate', String(params.populate)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getCollectionResponse.js b/dist/src/tools/getCollectionResponse.js index 821d4b7..f2b15e7 100644 --- a/dist/src/tools/getCollectionResponse.js +++ b/dist/src/tools/getCollectionResponse.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -37,11 +36,10 @@ export async function handler(params, extra) { if (params.populate !== undefined) query.set('populate', String(params.populate)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getCollectionTags.js b/dist/src/tools/getCollectionTags.js index 1012166..489da1d 100644 --- a/dist/src/tools/getCollectionTags.js +++ b/dist/src/tools/getCollectionTags.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -21,11 +20,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/tags`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getCollectionUpdatesTasks.js b/dist/src/tools/getCollectionUpdatesTasks.js index d92b64a..351a2a9 100644 --- a/dist/src/tools/getCollectionUpdatesTasks.js +++ b/dist/src/tools/getCollectionUpdatesTasks.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/collection-updates-tasks/${params.taskId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getCollections.js b/dist/src/tools/getCollections.js index a7d9827..d98cc6b 100644 --- a/dist/src/tools/getCollections.js +++ b/dist/src/tools/getCollections.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -40,11 +39,10 @@ export async function handler(params, extra) { if (params.offset !== undefined) query.set('offset', String(params.offset)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getCollectionsForkedByUser.js b/dist/src/tools/getCollectionsForkedByUser.js index 549d411..d429679 100644 --- a/dist/src/tools/getCollectionsForkedByUser.js +++ b/dist/src/tools/getCollectionsForkedByUser.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -39,11 +38,10 @@ export async function handler(params, extra) { if (params.direction !== undefined) query.set('direction', String(params.direction)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getDuplicateCollectionTaskStatus.js b/dist/src/tools/getDuplicateCollectionTaskStatus.js index 454c6d0..f5b7ecc 100644 --- a/dist/src/tools/getDuplicateCollectionTaskStatus.js +++ b/dist/src/tools/getDuplicateCollectionTaskStatus.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/collection-duplicate-tasks/${params.taskId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getEnvironment.js b/dist/src/tools/getEnvironment.js index e841c16..e0a9236 100644 --- a/dist/src/tools/getEnvironment.js +++ b/dist/src/tools/getEnvironment.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/environments/${params.environmentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getEnvironments.js b/dist/src/tools/getEnvironments.js index a56c2be..7736c86 100644 --- a/dist/src/tools/getEnvironments.js +++ b/dist/src/tools/getEnvironments.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -23,11 +22,10 @@ export async function handler(params, extra) { if (params.workspace !== undefined) query.set('workspace', String(params.workspace)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getFolderComments.js b/dist/src/tools/getFolderComments.js index b99f888..6de1d4c 100644 --- a/dist/src/tools/getFolderComments.js +++ b/dist/src/tools/getFolderComments.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -22,11 +21,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/folders/${params.folderId}/comments`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getGeneratedCollectionSpecs.js b/dist/src/tools/getGeneratedCollectionSpecs.js index a93f933..748076d 100644 --- a/dist/src/tools/getGeneratedCollectionSpecs.js +++ b/dist/src/tools/getGeneratedCollectionSpecs.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -22,11 +21,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionUid}/generations/${params.elementType}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getMock.js b/dist/src/tools/getMock.js index 5e346f3..b0a7d1d 100644 --- a/dist/src/tools/getMock.js +++ b/dist/src/tools/getMock.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/mocks/${params.mockId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getMocks.js b/dist/src/tools/getMocks.js index 8fe70ad..dc2ec47 100644 --- a/dist/src/tools/getMocks.js +++ b/dist/src/tools/getMocks.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -26,11 +25,10 @@ export async function handler(params, extra) { if (params.workspace !== undefined) query.set('workspace', String(params.workspace)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getMonitor.js b/dist/src/tools/getMonitor.js index 59e7b3c..2c1137f 100644 --- a/dist/src/tools/getMonitor.js +++ b/dist/src/tools/getMonitor.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/monitors/${params.monitorId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getMonitors.js b/dist/src/tools/getMonitors.js index 64a8f1e..ee02f07 100644 --- a/dist/src/tools/getMonitors.js +++ b/dist/src/tools/getMonitors.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -55,11 +54,10 @@ export async function handler(params, extra) { if (params.limit !== undefined) query.set('limit', String(params.limit)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getRequestComments.js b/dist/src/tools/getRequestComments.js index 46493c4..6e80a69 100644 --- a/dist/src/tools/getRequestComments.js +++ b/dist/src/tools/getRequestComments.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -24,11 +23,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/requests/${params.requestId}/comments`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getResponseComments.js b/dist/src/tools/getResponseComments.js index 430ae2b..00047c5 100644 --- a/dist/src/tools/getResponseComments.js +++ b/dist/src/tools/getResponseComments.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -22,11 +21,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/responses/${params.responseId}/comments`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getSourceCollectionStatus.js b/dist/src/tools/getSourceCollectionStatus.js index e101ca7..9ed2485 100644 --- a/dist/src/tools/getSourceCollectionStatus.js +++ b/dist/src/tools/getSourceCollectionStatus.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/source-status`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getSpec.js b/dist/src/tools/getSpec.js index 7c9192f..0a9d336 100644 --- a/dist/src/tools/getSpec.js +++ b/dist/src/tools/getSpec.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/specs/${params.specId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getSpecCollections.js b/dist/src/tools/getSpecCollections.js index a784c1a..777b22b 100644 --- a/dist/src/tools/getSpecCollections.js +++ b/dist/src/tools/getSpecCollections.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -35,11 +34,10 @@ export async function handler(params, extra) { if (params.cursor !== undefined) query.set('cursor', String(params.cursor)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getSpecDefinition.js b/dist/src/tools/getSpecDefinition.js index 59c2108..230461f 100644 --- a/dist/src/tools/getSpecDefinition.js +++ b/dist/src/tools/getSpecDefinition.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/specs/${params.specId}/definitions`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getSpecFile.js b/dist/src/tools/getSpecFile.js index 0c44cbf..8231ab5 100644 --- a/dist/src/tools/getSpecFile.js +++ b/dist/src/tools/getSpecFile.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -22,11 +21,10 @@ export async function handler(params, extra) { const endpoint = `/specs/${params.specId}/files/${params.filePath}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getSpecFiles.js b/dist/src/tools/getSpecFiles.js index 85a9294..a65cca2 100644 --- a/dist/src/tools/getSpecFiles.js +++ b/dist/src/tools/getSpecFiles.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/specs/${params.specId}/files`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getStatusOfAnAsyncTask.js b/dist/src/tools/getStatusOfAnAsyncApiTask.js similarity index 86% rename from dist/src/tools/getStatusOfAnAsyncTask.js rename to dist/src/tools/getStatusOfAnAsyncApiTask.js index 3ef5e44..4a12554 100644 --- a/dist/src/tools/getStatusOfAnAsyncTask.js +++ b/dist/src/tools/getStatusOfAnAsyncApiTask.js @@ -1,11 +1,10 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); return new McpError(ErrorCode.InternalError, cause); } -export const method = 'getStatusOfAnAsyncTask'; +export const method = 'getStatusOfAnAsyncApiTask'; export const description = 'Gets the status of an asynchronous task.'; export const parameters = z.object({ apiId: z.string().describe("The API's ID."), @@ -25,11 +24,10 @@ export async function handler(params, extra) { const endpoint = `/apis/${params.apiId}/tasks/${params.taskId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getTaggedEntities.js b/dist/src/tools/getTaggedEntities.js index bcf23f9..305983d 100644 --- a/dist/src/tools/getTaggedEntities.js +++ b/dist/src/tools/getTaggedEntities.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -52,11 +51,10 @@ export async function handler(params, extra) { if (params.entityType !== undefined) query.set('entityType', String(params.entityType)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getWorkspace.js b/dist/src/tools/getWorkspace.js index 827c246..e450cd3 100644 --- a/dist/src/tools/getWorkspace.js +++ b/dist/src/tools/getWorkspace.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -27,11 +26,10 @@ export async function handler(params, extra) { if (params.include !== undefined) query.set('include', String(params.include)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getWorkspaceGlobalVariables.js b/dist/src/tools/getWorkspaceGlobalVariables.js index 608b1a6..10fe0db 100644 --- a/dist/src/tools/getWorkspaceGlobalVariables.js +++ b/dist/src/tools/getWorkspaceGlobalVariables.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/workspaces/${params.workspaceId}/global-variables`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getWorkspaceTags.js b/dist/src/tools/getWorkspaceTags.js index dd02bab..569cd83 100644 --- a/dist/src/tools/getWorkspaceTags.js +++ b/dist/src/tools/getWorkspaceTags.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/workspaces/${params.workspaceId}/tags`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/getWorkspaces.js b/dist/src/tools/getWorkspaces.js index f2d034b..d7b85b1 100644 --- a/dist/src/tools/getWorkspaces.js +++ b/dist/src/tools/getWorkspaces.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -39,11 +38,10 @@ export async function handler(params, extra) { if (params.include !== undefined) query.set('include', String(params.include)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/dist/src/tools/mergeCollectionFork.js b/dist/src/tools/mergeCollectionFork.js new file mode 100644 index 0000000..6abbf4b --- /dev/null +++ b/dist/src/tools/mergeCollectionFork.js @@ -0,0 +1,57 @@ +import { z } from 'zod'; +import { ContentType } from '../clients/postman.js'; +import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; +function asMcpError(error) { + const cause = error?.cause ?? String(error); + return new McpError(ErrorCode.InternalError, cause); +} +export const method = 'mergeCollectionFork'; +export const description = '**This endpoint is deprecated.**\n\nMerges a forked collection back into its parent collection. You must have the [Editor role](https://learning.postman.com/docs/collaborating-in-postman/roles-and-permissions/#collection-roles) for the collection to merge a fork.\n'; +export const parameters = z.object({ + destination: z.string().describe("The destination (parent) collection's unique ID."), + source: z.string().describe("The source collection's unique ID."), + strategy: z + .enum(['deleteSource', 'updateSourceWithDestination']) + .describe("The fork's merge strategy:\n- `deleteSource` — Merge the changes into the parent collection. After the merge process is complete, Postman deletes the fork. You must have Editor access to both the parent and forked collections.\n- `updateSourceWithDestination` — Merge the changes into the parent collection. Any differences in the parent collection are also made to the fork.\n") + .default('updateSourceWithDestination'), +}); +export const annotations = { + title: '**This endpoint is deprecated.**\n\nMerges a forked collection back into its parent collection. You must have the [Editor role](https://learning.postman.com/docs/collaborating-in-postman/roles-and-permissions/#collection-roles) for the collection to merge a fork.\n', + readOnlyHint: false, + destructiveHint: false, + idempotentHint: false, +}; +export async function handler(params, extra) { + try { + const endpoint = `/collections/merge`; + const query = new URLSearchParams(); + const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; + const bodyPayload = {}; + if (params.destination !== undefined) + bodyPayload.destination = params.destination; + if (params.source !== undefined) + bodyPayload.source = params.source; + if (params.strategy !== undefined) + bodyPayload.strategy = params.strategy; + const options = { + body: JSON.stringify(bodyPayload), + contentType: ContentType.Json, + headers: extra.headers, + }; + const result = await extra.client.post(url, options); + return { + content: [ + { + type: 'text', + text: `${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}`, + }, + ], + }; + } + catch (e) { + if (e instanceof McpError) { + throw e; + } + throw asMcpError(e); + } +} diff --git a/dist/src/tools/patchCollection.js b/dist/src/tools/patchCollection.js index c121669..6705bcd 100644 --- a/dist/src/tools/patchCollection.js +++ b/dist/src/tools/patchCollection.js @@ -1,12 +1,12 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); return new McpError(ErrorCode.InternalError, cause); } export const method = 'patchCollection'; -export const description = 'Updates specific collection information, such as its name, events, or its variables. For more information about the \\`auth\\`, \\`variable\\`, and \\`events\\` properties, refer to the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html):\n- For \\`variable\\`, refer to the **Variable List** entry. Also accepts \\`variables\\`.\n- For \\`auth\\`, refer to the **Auth** entry.\n- For \\`events\\`, refer to the **Event List** entry.\n'; +export const description = 'Updates specific collection information, such as its name, events, or its variables. For more information, see the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).\n'; export const parameters = z.object({ collectionId: z .string() @@ -28,18 +28,14 @@ export const parameters = z.object({ .describe("The variable's ID. Doesn't apply to collection-level variables.") .optional(), key: z.string().describe("The variable's key (name).").optional(), - description: z - .string() - .describe("The variable's description. Doesn't apply to collection-level variables.") - .optional(), - value: z.string().describe("The key's value.").optional(), - type: z - .enum(['string', 'boolean', 'integer']) - .describe("The variable's type.") + description: z.string().max(512).describe("The variable's description.").optional(), + value: z + .union([z.string(), z.boolean(), z.number().int()]) + .describe("The key's value.") .optional(), disabled: z .boolean() - .describe('If true, the variable is not enabled. Applies only to query parameter variables.') + .describe("If true, the variable is not enabled. Doesn't apply to path parameter variables.") .default(false), }) .describe('Information about the variable.')) @@ -281,12 +277,13 @@ export const parameters = z.object({ .optional(), }) .describe("Information about the collection's events.")) + .describe('A list of scripts configured to run when specific events occur. These scripts can be referenced in the collection by their ID.') .optional(), }) .optional(), }); export const annotations = { - title: 'Updates specific collection information, such as its name, events, or its variables. For more information about the \\`auth\\`, \\`variable\\`, and \\`events\\` properties, refer to the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html):\n- For \\`variable\\`, refer to the **Variable List** entry. Also accepts \\`variables\\`.\n- For \\`auth\\`, refer to the **Auth** entry.\n- For \\`events\\`, refer to the **Event List** entry.\n', + title: 'Updates specific collection information, such as its name, events, or its variables. For more information, see the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).\n', readOnlyHint: false, destructiveHint: false, idempotentHint: true, @@ -299,13 +296,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.collection !== undefined) bodyPayload.collection = params.collection; - const result = await fetchPostmanAPI(url, { - method: 'PATCH', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.patch(url, options); return { content: [ { diff --git a/dist/src/tools/patchEnvironment.js b/dist/src/tools/patchEnvironment.js index daf127d..bf22701 100644 --- a/dist/src/tools/patchEnvironment.js +++ b/dist/src/tools/patchEnvironment.js @@ -1,15 +1,14 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); return new McpError(ErrorCode.InternalError, cause); } export const method = 'patchEnvironment'; -export const description = 'Updates specific environment properties, such as its name and variables.\n\n**Note:**\n\n- The request body size cannot exceed the maximum allowed size of 30MB.\n- If you receive an HTTP \\`411 Length Required\\` error response, manually pass the \\`Content-Length\\` header and its value in the request header.\n'; +export const description = 'Updates specific environment properties, such as its name and variables.\n\n**Note:**\n\n- You can only perform one type of operation at a time. For example, you cannot perform an \\`add\\` and \\`replace\\` operation in the same call.\n- The request body size cannot exceed the maximum allowed size of 30MB.\n- If you receive an HTTP \\`411 Length Required\\` error response, manually pass the \\`Content-Length\\` header and its value in the request header.\n- To add a description to an existing variable, use the \\`add\\` operation.\n'; export const parameters = z.object({ environmentId: z.string().describe("The environment's ID.") }); export const annotations = { - title: 'Updates specific environment properties, such as its name and variables.\n\n**Note:**\n\n- The request body size cannot exceed the maximum allowed size of 30MB.\n- If you receive an HTTP \\`411 Length Required\\` error response, manually pass the \\`Content-Length\\` header and its value in the request header.\n', + title: 'Updates specific environment properties, such as its name and variables.\n\n**Note:**\n\n- You can only perform one type of operation at a time. For example, you cannot perform an \\`add\\` and \\`replace\\` operation in the same call.\n- The request body size cannot exceed the maximum allowed size of 30MB.\n- If you receive an HTTP \\`411 Length Required\\` error response, manually pass the \\`Content-Length\\` header and its value in the request header.\n- To add a description to an existing variable, use the \\`add\\` operation.\n', readOnlyHint: false, destructiveHint: false, idempotentHint: true, @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/environments/${params.environmentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'PATCH', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.patch(url, options); return { content: [ { diff --git a/dist/src/tools/postPanElementOrFolder.js b/dist/src/tools/postPanElementOrFolder.js index cf601af..76b0d8a 100644 --- a/dist/src/tools/postPanElementOrFolder.js +++ b/dist/src/tools/postPanElementOrFolder.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/network/private`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'POST', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/publishDocumentation.js b/dist/src/tools/publishDocumentation.js index 0122f4b..ffc86ee 100644 --- a/dist/src/tools/publishDocumentation.js +++ b/dist/src/tools/publishDocumentation.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -104,13 +104,12 @@ export async function handler(params, extra) { bodyPayload.documentationLayout = params.documentationLayout; if (params.customization !== undefined) bodyPayload.customization = params.customization; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/publishMock.js b/dist/src/tools/publishMock.js index 8e46dc3..723a8ec 100644 --- a/dist/src/tools/publishMock.js +++ b/dist/src/tools/publishMock.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/mocks/${params.mockId}/publish`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'POST', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/pullCollectionChanges.js b/dist/src/tools/pullCollectionChanges.js index 7c5717b..02af56d 100644 --- a/dist/src/tools/pullCollectionChanges.js +++ b/dist/src/tools/pullCollectionChanges.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/pulls`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'PUT', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/putCollection.js b/dist/src/tools/putCollection.js index 53f0ead..a2d911b 100644 --- a/dist/src/tools/putCollection.js +++ b/dist/src/tools/putCollection.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -894,13 +894,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.collection !== undefined) bodyPayload.collection = params.collection; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/putEnvironment.js b/dist/src/tools/putEnvironment.js index 3ea12e9..97d801c 100644 --- a/dist/src/tools/putEnvironment.js +++ b/dist/src/tools/putEnvironment.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -13,12 +13,18 @@ export const parameters = z.object({ .object({ name: z.string().describe("The environment's name.").optional(), values: z - .array(z.object({ + .array(z + .object({ enabled: z.boolean().describe('If true, the variable is enabled.').optional(), key: z.string().describe("The variable's name.").optional(), value: z.string().describe("The variable's value.").optional(), - type: z.enum(['secret', 'default']).describe('The variable type.').optional(), - })) + type: z + .enum(['secret', 'default']) + .describe("The variable's type:\n- `secret` — The variable value is masked.\n- `default` — The variable value is visible in plain text.\n") + .optional(), + description: z.string().max(512).describe("The variable's description.").optional(), + }) + .describe("Information about the environment's variables.")) .describe("Information about the environment's variables.") .optional(), }) @@ -39,13 +45,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.environment !== undefined) bodyPayload.environment = params.environment; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/resolveCommentThread.js b/dist/src/tools/resolveCommentThread.js index 5337a09..67256e6 100644 --- a/dist/src/tools/resolveCommentThread.js +++ b/dist/src/tools/resolveCommentThread.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -21,11 +20,10 @@ export async function handler(params, extra) { const endpoint = `/comments-resolutions/${params.threadId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'POST', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/runMonitor.js b/dist/src/tools/runMonitor.js index 8a2ea07..0e8fcae 100644 --- a/dist/src/tools/runMonitor.js +++ b/dist/src/tools/runMonitor.js @@ -1,12 +1,11 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); return new McpError(ErrorCode.InternalError, cause); } export const method = 'runMonitor'; -export const description = 'Runs a monitor and returns its run results.\n\n**Note:**\n\n- This endpoint has a timeout restriction of 300 seconds. It is recommended that you include the \\`async=true\\` query parameter when using this endpoint.\n- If you pass the \\`async=true\\` query parameter, the response does not return the \\`stats\\`, \\`executions\\`, and \\`failures\\` responses. To get this information for an asynchronous run, call the GET \\`/monitors/{id}\\` endpoint.\n'; +export const description = "Runs a monitor and returns its run results.\n\n**Note:**\n\n- If you pass the \\`async=true\\` query parameter, the response does not return the \\`stats\\`, \\`executions\\`, and \\`failures\\` responses. To get this information for an asynchronous run, call the GET \\`/monitors/{id}\\` endpoint.\n- If the call exceeds 300 seconds, the endpoint returns an HTTP \\`202 Accepted\\` response. Use the GET \\`/monitors/{id}\\` endpoint to check the run's status in the response's \\`lastRun\\` property. To avoid this, it is recommended that you include the \\`async=true\\` query parameter when using this endpoint.\n"; export const parameters = z.object({ monitorId: z.string().describe("The monitor's ID."), async: z @@ -15,7 +14,7 @@ export const parameters = z.object({ .default(false), }); export const annotations = { - title: 'Runs a monitor and returns its run results.\n\n**Note:**\n\n- This endpoint has a timeout restriction of 300 seconds. It is recommended that you include the \\`async=true\\` query parameter when using this endpoint.\n- If you pass the \\`async=true\\` query parameter, the response does not return the \\`stats\\`, \\`executions\\`, and \\`failures\\` responses. To get this information for an asynchronous run, call the GET \\`/monitors/{id}\\` endpoint.\n', + title: "Runs a monitor and returns its run results.\n\n**Note:**\n\n- If you pass the \\`async=true\\` query parameter, the response does not return the \\`stats\\`, \\`executions\\`, and \\`failures\\` responses. To get this information for an asynchronous run, call the GET \\`/monitors/{id}\\` endpoint.\n- If the call exceeds 300 seconds, the endpoint returns an HTTP \\`202 Accepted\\` response. Use the GET \\`/monitors/{id}\\` endpoint to check the run's status in the response's \\`lastRun\\` property. To avoid this, it is recommended that you include the \\`async=true\\` query parameter when using this endpoint.\n", readOnlyHint: false, destructiveHint: false, idempotentHint: false, @@ -27,11 +26,10 @@ export async function handler(params, extra) { if (params.async !== undefined) query.set('async', String(params.async)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'POST', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/syncCollectionWithSpec.js b/dist/src/tools/syncCollectionWithSpec.js index 9be68be..ea2c052 100644 --- a/dist/src/tools/syncCollectionWithSpec.js +++ b/dist/src/tools/syncCollectionWithSpec.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -24,11 +23,10 @@ export async function handler(params, extra) { if (params.specId !== undefined) query.set('specId', String(params.specId)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'PUT', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/syncSpecWithCollection.js b/dist/src/tools/syncSpecWithCollection.js index d3c99b2..dd943df 100644 --- a/dist/src/tools/syncSpecWithCollection.js +++ b/dist/src/tools/syncSpecWithCollection.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -24,11 +23,10 @@ export async function handler(params, extra) { if (params.collectionUid !== undefined) query.set('collectionUid', String(params.collectionUid)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'PUT', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/transferCollectionFolders.js b/dist/src/tools/transferCollectionFolders.js index 74bef86..f008a1a 100644 --- a/dist/src/tools/transferCollectionFolders.js +++ b/dist/src/tools/transferCollectionFolders.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -59,13 +59,12 @@ export async function handler(params, extra) { bodyPayload.target = params.target; if (params.location !== undefined) bodyPayload.location = params.location; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/transferCollectionRequests.js b/dist/src/tools/transferCollectionRequests.js index d923854..013f57a 100644 --- a/dist/src/tools/transferCollectionRequests.js +++ b/dist/src/tools/transferCollectionRequests.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -59,13 +59,12 @@ export async function handler(params, extra) { bodyPayload.target = params.target; if (params.location !== undefined) bodyPayload.location = params.location; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/transferCollectionResponses.js b/dist/src/tools/transferCollectionResponses.js index 5e12bed..7922c5e 100644 --- a/dist/src/tools/transferCollectionResponses.js +++ b/dist/src/tools/transferCollectionResponses.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -59,13 +59,12 @@ export async function handler(params, extra) { bodyPayload.target = params.target; if (params.location !== undefined) bodyPayload.location = params.location; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/dist/src/tools/unpublishDocumentation.js b/dist/src/tools/unpublishDocumentation.js index 5ececa4..c76e317 100644 --- a/dist/src/tools/unpublishDocumentation.js +++ b/dist/src/tools/unpublishDocumentation.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -21,11 +20,10 @@ export async function handler(params, extra) { const endpoint = `/collections/${params.collectionId}/public-documentations`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/unpublishMock.js b/dist/src/tools/unpublishMock.js index fc39157..3e37725 100644 --- a/dist/src/tools/unpublishMock.js +++ b/dist/src/tools/unpublishMock.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,11 +18,10 @@ export async function handler(params, extra) { const endpoint = `/mocks/${params.mockId}/unpublish`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/dist/src/tools/updateApiCollectionComment.js b/dist/src/tools/updateApiCollectionComment.js index 736ed9c..a039a0f 100644 --- a/dist/src/tools/updateApiCollectionComment.js +++ b/dist/src/tools/updateApiCollectionComment.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -41,13 +41,12 @@ export async function handler(params, extra) { bodyPayload.body = params.body; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateCollectionComment.js b/dist/src/tools/updateCollectionComment.js index 0d99ae9..258f301 100644 --- a/dist/src/tools/updateCollectionComment.js +++ b/dist/src/tools/updateCollectionComment.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -40,13 +40,12 @@ export async function handler(params, extra) { bodyPayload.body = params.body; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateCollectionFolder.js b/dist/src/tools/updateCollectionFolder.js index 1c2442c..9658c18 100644 --- a/dist/src/tools/updateCollectionFolder.js +++ b/dist/src/tools/updateCollectionFolder.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -29,13 +29,12 @@ export async function handler(params, extra) { bodyPayload.name = params.name; if (params.description !== undefined) bodyPayload.description = params.description; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateCollectionRequest.js b/dist/src/tools/updateCollectionRequest.js index 1b82200..6d62019 100644 --- a/dist/src/tools/updateCollectionRequest.js +++ b/dist/src/tools/updateCollectionRequest.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -48,13 +48,12 @@ export async function handler(params, extra) { bodyPayload.name = params.name; if (params.method !== undefined) bodyPayload.method = params.method; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateCollectionResponse.js b/dist/src/tools/updateCollectionResponse.js index 42b282d..8700360 100644 --- a/dist/src/tools/updateCollectionResponse.js +++ b/dist/src/tools/updateCollectionResponse.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -35,13 +35,12 @@ export async function handler(params, extra) { bodyPayload.name = params.name; if (params.responseCode !== undefined) bodyPayload.responseCode = params.responseCode; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateCollectionTags.js b/dist/src/tools/updateCollectionTags.js index 15ca40d..74c723a 100644 --- a/dist/src/tools/updateCollectionTags.js +++ b/dist/src/tools/updateCollectionTags.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -38,13 +38,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateFolderComment.js b/dist/src/tools/updateFolderComment.js index 0407aba..3d2e6d6 100644 --- a/dist/src/tools/updateFolderComment.js +++ b/dist/src/tools/updateFolderComment.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -41,13 +41,12 @@ export async function handler(params, extra) { bodyPayload.body = params.body; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateMock.js b/dist/src/tools/updateMock.js index 5f666a9..ff5fe9c 100644 --- a/dist/src/tools/updateMock.js +++ b/dist/src/tools/updateMock.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -46,13 +46,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.mock !== undefined) bodyPayload.mock = params.mock; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateMonitor.js b/dist/src/tools/updateMonitor.js index fb3ef55..2f48e99 100644 --- a/dist/src/tools/updateMonitor.js +++ b/dist/src/tools/updateMonitor.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -31,6 +31,7 @@ export const parameters = z.object({ .describe('The number of times to reattempt a monitor run if it fails or errors. This may impact your [monitor usage](https://learning.postman.com/docs/monitoring-your-api/monitor-usage/#view-monitor-usage).') .optional(), }) + .describe("Information about the monitor's retry settings.") .optional(), options: z .object({ @@ -124,13 +125,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.monitor !== undefined) bodyPayload.monitor = params.monitor; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updatePanElementOrFolder.js b/dist/src/tools/updatePanElementOrFolder.js index ba7f337..e3fc3a3 100644 --- a/dist/src/tools/updatePanElementOrFolder.js +++ b/dist/src/tools/updatePanElementOrFolder.js @@ -1,5 +1,4 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -24,11 +23,10 @@ export async function handler(params, extra) { const endpoint = `/network/private/${params.elementType}/${params.elementId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'PUT', - apiKey: extra.apiKey, + const options = { headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateRequestComment.js b/dist/src/tools/updateRequestComment.js index e409150..b7c9ef9 100644 --- a/dist/src/tools/updateRequestComment.js +++ b/dist/src/tools/updateRequestComment.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -41,13 +41,12 @@ export async function handler(params, extra) { bodyPayload.body = params.body; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateResponseComment.js b/dist/src/tools/updateResponseComment.js index dc77ff1..7e1b8cd 100644 --- a/dist/src/tools/updateResponseComment.js +++ b/dist/src/tools/updateResponseComment.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -41,13 +41,12 @@ export async function handler(params, extra) { bodyPayload.body = params.body; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateSpecFile.js b/dist/src/tools/updateSpecFile.js index 61038dd..4d33112 100644 --- a/dist/src/tools/updateSpecFile.js +++ b/dist/src/tools/updateSpecFile.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -35,13 +35,12 @@ export async function handler(params, extra) { bodyPayload.type = params.type; if (params.content !== undefined) bodyPayload.content = params.content; - const result = await fetchPostmanAPI(url, { - method: 'PATCH', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.patch(url, options); return { content: [ { diff --git a/dist/src/tools/updateSpecProperties.js b/dist/src/tools/updateSpecProperties.js index a187b5b..2d64b67 100644 --- a/dist/src/tools/updateSpecProperties.js +++ b/dist/src/tools/updateSpecProperties.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -25,13 +25,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.name !== undefined) bodyPayload.name = params.name; - const result = await fetchPostmanAPI(url, { - method: 'PATCH', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.patch(url, options); return { content: [ { diff --git a/dist/src/tools/updateWorkspace.js b/dist/src/tools/updateWorkspace.js index bdef443..8c45e04 100644 --- a/dist/src/tools/updateWorkspace.js +++ b/dist/src/tools/updateWorkspace.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -35,13 +35,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.workspace !== undefined) bodyPayload.workspace = params.workspace; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateWorkspaceGlobalVariables.js b/dist/src/tools/updateWorkspaceGlobalVariables.js index 835a379..7157db3 100644 --- a/dist/src/tools/updateWorkspaceGlobalVariables.js +++ b/dist/src/tools/updateWorkspaceGlobalVariables.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -19,6 +19,7 @@ export const parameters = z.object({ .optional(), value: z.string().describe("The variable's value.").optional(), enabled: z.boolean().describe('If true, the variable is enabled.').optional(), + description: z.string().max(512).describe("The variable's description.").optional(), }) .describe('Information about the global variable.')) .describe("A list of the workspace's global variables.") @@ -38,13 +39,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.values !== undefined) bodyPayload.values = params.values; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/dist/src/tools/updateWorkspaceTags.js b/dist/src/tools/updateWorkspaceTags.js index 4da2f4e..214740e 100644 --- a/dist/src/tools/updateWorkspaceTags.js +++ b/dist/src/tools/updateWorkspaceTags.js @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { ContentType } from '../clients/postman.js'; import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error) { const cause = error?.cause ?? String(error); @@ -38,13 +38,12 @@ export async function handler(params, extra) { const bodyPayload = {}; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/clients/postman.ts b/src/clients/postman.ts index b318f24..7038379 100644 --- a/src/clients/postman.ts +++ b/src/clients/postman.ts @@ -1,48 +1,147 @@ -import { ErrorCode, IsomorphicHeaders, McpError } from '@modelcontextprotocol/sdk/types.js'; +import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; import packageJson from '../../package.json' with { type: 'json' }; -const BASE_URL = 'https://api.postman.com'; export enum ContentType { Json = 'application/json', JsonPatch = 'application/json-patch+json', } -export interface FetchPostmanAPIOptions extends Omit { +export interface PostmanAPIRequestOptions extends Omit { contentType?: ContentType; - apiKey: string; headers?: IsomorphicHeaders; } -export async function fetchPostmanAPI( - endpoint: string, - options: FetchPostmanAPIOptions -): Promise { - const apiKey = options.apiKey || process.env.POSTMAN_API_KEY; - if (!apiKey) { - throw new Error('API key is required.'); +export interface IPostmanAPIClient { + get( + endpoint: string, + options?: Omit + ): Promise; + post(endpoint: string, options?: PostmanAPIRequestOptions): Promise; + put(endpoint: string, options?: PostmanAPIRequestOptions): Promise; + patch(endpoint: string, options?: PostmanAPIRequestOptions): Promise; + delete( + endpoint: string, + options?: Omit + ): Promise; +} + +/** + * Postman API Client following SOLID principles + * - Single Responsibility: Handles HTTP requests to Postman API + * - Open/Closed: Extensible for different request types + * - Liskov Substitution: Consistent interface implementation + * - Interface Segregation: Focused IPostmanAPIClient interface + * - Dependency Inversion: Depends on abstractions, not concretions + */ +export class PostmanAPIClient implements IPostmanAPIClient { + private readonly baseUrl: string; + private readonly apiKey: string; + private static instance: PostmanAPIClient | null = null; + + constructor( + apiKey: string, + baseUrl: string = process.env.POSTMAN_API_BASE_URL || 'https://api.postman.com' + ) { + if (!apiKey && !process.env.POSTMAN_API_KEY) { + throw new Error( + 'API key is required. Provide it as parameter or set POSTMAN_API_KEY environment variable.' + ); + } + this.apiKey = apiKey || process.env.POSTMAN_API_KEY!; + this.baseUrl = baseUrl; + } + + /** + * Get singleton instance of PostmanAPIClient + * Creates instance if it doesn't exist, otherwise returns existing instance + */ + static getInstance(apiKey?: string, baseUrl?: string): PostmanAPIClient { + if (!PostmanAPIClient.instance) { + const key = apiKey || process.env.POSTMAN_API_KEY; + if (!key) { + throw new Error( + 'API key is required. Provide it as parameter or set POSTMAN_API_KEY environment variable.' + ); + } + PostmanAPIClient.instance = new PostmanAPIClient(key, baseUrl); + } + return PostmanAPIClient.instance; + } + + /** + * Reset singleton instance (useful for testing or reconfiguration) + */ + static resetInstance(): void { + PostmanAPIClient.instance = null; + } + + async get( + endpoint: string, + options: Omit = {} + ): Promise { + return this.request(endpoint, { ...options, method: 'GET' }); + } + + async post(endpoint: string, options: PostmanAPIRequestOptions = {}): Promise { + return this.request(endpoint, { ...options, method: 'POST' }); + } + + async put(endpoint: string, options: PostmanAPIRequestOptions = {}): Promise { + return this.request(endpoint, { ...options, method: 'PUT' }); } - const contentType = options.contentType || ContentType.Json; - const userAgentHeader = - options.headers && 'user-agent' in options.headers - ? `${options.headers['user-agent']}/${packageJson.name}/${packageJson.version}` - : `${packageJson.name}/${packageJson.version}`; + async patch(endpoint: string, options: PostmanAPIRequestOptions = {}): Promise { + return this.request(endpoint, { ...options, method: 'PATCH' }); + } + + async delete( + endpoint: string, + options: Omit = {} + ): Promise { + return this.request(endpoint, { ...options, method: 'DELETE' }); + } + + private async request( + endpoint: string, + options: PostmanAPIRequestOptions & { method: string } + ): Promise { + const contentType = options.contentType || ContentType.Json; + + const userAgentHeader = + options.headers && 'user-agent' in options.headers + ? `${options.headers['user-agent']}/${packageJson.name}/${packageJson.version}` + : `${packageJson.name}/${packageJson.version}`; + + const headers = { + 'content-type': contentType, + 'x-api-key': this.apiKey, + 'user-agent': userAgentHeader, + ...options.headers, + }; + + const { headers: _, ...optionsWithoutHeaders } = options; + const response = await fetch(`${this.baseUrl}${endpoint}`, { + ...optionsWithoutHeaders, + headers, + }); + + if (!response.ok) { + await this.handleErrorResponse(response); + } - const headers = { - 'content-type': contentType, - 'x-api-key': apiKey, - 'user-agent': userAgentHeader, - }; + if (response.status === 204) return null as T; - const { headers: _, ...optionsWithoutHeaders } = options; + const responseContentType = response.headers.get('content-type') || ''; + if (responseContentType.includes('application/json')) { + return response.json(); + } - const response = await fetch(`${BASE_URL}${endpoint}`, { - ...optionsWithoutHeaders, - headers, - }); + return response.text() as T; + } - if (!response.ok) { + private async handleErrorResponse(response: Response): Promise { const errorText = await response.text(); + switch (response.status) { case 400: case 422: @@ -61,13 +160,4 @@ export async function fetchPostmanAPI( }); } } - - if (response.status === 204) return null; - - const responseContentType = response.headers.get('content-type') || ''; - if (responseContentType.includes('application/json')) { - return response.json(); - } - - return response.text(); } diff --git a/src/enabledResources.ts b/src/enabledResources.ts index b622f5c..fa461ad 100644 --- a/src/enabledResources.ts +++ b/src/enabledResources.ts @@ -22,7 +22,7 @@ const full = [ 'getCollectionsForkedByUser', 'pullCollectionChanges', 'createCollectionFork', - 'collection-merges', + 'mergeCollectionFork', // Collection Folders 'createCollectionFolder', @@ -126,7 +126,7 @@ const full = [ // Tasks and Status 'getAsyncSpecTaskStatus', - 'getStatusOfAnAsyncTask', + 'getStatusOfAnAsyncApiTask', // User and Tags 'getAuthenticatedUser', @@ -185,6 +185,7 @@ const minimal = [ 'createCollectionRequest', 'createCollectionResponse', 'duplicateCollection', + 'getStatusOfAnAsyncApiTask', ] as const; const excludedFromGeneration = ['createCollection', 'putCollection'] as const; diff --git a/src/index.ts b/src/index.ts index 03b3da3..232bf6c 100644 --- a/src/index.ts +++ b/src/index.ts @@ -20,6 +20,23 @@ import { join, dirname } from 'node:path'; import { fileURLToPath } from 'node:url'; import type { z } from 'zod'; import { enabledResources } from './enabledResources.js'; +import { PostmanAPIClient } from './clients/postman.js'; + +const SUPPORTED_REGIONS = { + us: 'https://api.postman.com', + eu: 'https://api.eu.postman.com', +} as const; + +function isValidRegion(region: string): region is keyof typeof SUPPORTED_REGIONS { + return region in SUPPORTED_REGIONS; +} + +function setRegionEnvironment(region: string): void { + if (!isValidRegion(region)) { + throw new Error(`Invalid region: ${region}. Supported regions: us, eu`); + } + process.env.POSTMAN_API_BASE_URL = SUPPORTED_REGIONS[region]; +} type LogLevel = 'debug' | 'info' | 'warn' | 'error'; @@ -64,7 +81,7 @@ interface ToolModule { handler: ( params: any, extra: { - apiKey: string; + client: PostmanAPIClient; headers?: IsomorphicHeaders; } ) => Promise<{ @@ -128,20 +145,38 @@ const SERVER_NAME = packageJson.name; const APP_VERSION = packageJson.version; export const USER_AGENT = `${SERVER_NAME}/${APP_VERSION}`; -let currentApiKey: string | undefined = undefined; let clientInfo: InitializeRequest['params']['clientInfo'] | undefined = undefined; -const allGeneratedTools = await loadAllTools(); -log('info', 'Server initialization starting', { - serverName: SERVER_NAME, - version: APP_VERSION, - toolCount: allGeneratedTools.length, -}); - async function run() { const args = process.argv.slice(2); const useFull = args.includes('--full'); + const regionIndex = args.findIndex((arg) => arg === '--region'); + if (regionIndex !== -1 && regionIndex + 1 < args.length) { + const region = args[regionIndex + 1]; + if (isValidRegion(region)) { + setRegionEnvironment(region); + log('info', `Using region: ${region}`, { + region, + baseUrl: process.env.POSTMAN_API_BASE_URL, + }); + } else { + log('error', `Invalid region: ${region}`); + console.error(`Supported regions: ${Object.keys(SUPPORTED_REGIONS).join(', ')}`); + process.exit(1); + } + } + + // Create singleton client with selected base URL + const client = PostmanAPIClient.getInstance(); + + const allGeneratedTools = await loadAllTools(); + log('info', 'Server initialization starting', { + serverName: SERVER_NAME, + version: APP_VERSION, + toolCount: allGeneratedTools.length, + }); + const fullTools = allGeneratedTools.filter((t) => enabledResources.full.includes(t.method)); const minimalTools = allGeneratedTools.filter((t) => enabledResources.minimal.includes(t.method as MinimalResourceMethod) @@ -184,13 +219,9 @@ async function run() { try { const start = Date.now(); - if (!currentApiKey) { - log('error', 'Missing API key for tool invocation', { toolName }); - throw new McpError(ErrorCode.InvalidParams, 'API key is required.'); - } const result = await tool.handler(args as any, { - apiKey: currentApiKey, + client, headers: { ...extra.requestInfo?.headers, 'user-agent': clientInfo?.name, @@ -227,11 +258,7 @@ async function run() { return { tools: transformedTools }; }); - currentApiKey = process.env.POSTMAN_API_KEY; - if (!currentApiKey) { - log('error', 'POSTMAN_API_KEY is required'); - process.exit(1); - } + // API key validation is handled by the singleton client log('info', 'Starting stdio transport'); const transport = new StdioServerTransport(); transport.onmessage = (message) => { diff --git a/src/tools/createCollection.ts b/src/tools/createCollection.ts index 5d8a5f5..a61d4f4 100644 --- a/src/tools/createCollection.ts +++ b/src/tools/createCollection.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -1019,7 +1019,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections`; @@ -1028,13 +1028,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.collection !== undefined) bodyPayload.collection = params.collection; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createCollectionComment.ts b/src/tools/createCollectionComment.ts index ea9abac..2f94eb9 100644 --- a/src/tools/createCollectionComment.ts +++ b/src/tools/createCollectionComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -22,7 +22,7 @@ export const parameters = z.object({ .optional(), tags: z .object({ - userName: z + '{{userName}}': z .object({ type: z.literal('user').describe('The `user` value.'), id: z.string().describe("The user's ID."), @@ -45,7 +45,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/comments`; @@ -55,13 +55,12 @@ export async function handler( if (params.body !== undefined) bodyPayload.body = params.body; if (params.threadId !== undefined) bodyPayload.threadId = params.threadId; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createCollectionFolder.ts b/src/tools/createCollectionFolder.ts index 7093c8a..1d65fe8 100644 --- a/src/tools/createCollectionFolder.ts +++ b/src/tools/createCollectionFolder.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -30,7 +30,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/folders`; @@ -39,13 +39,12 @@ export async function handler( const bodyPayload: any = {}; if (params.name !== undefined) bodyPayload.name = params.name; if (params.folder !== undefined) bodyPayload.folder = params.folder; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createCollectionFork.ts b/src/tools/createCollectionFork.ts index 8d7bdd6..092e0d1 100644 --- a/src/tools/createCollectionFork.ts +++ b/src/tools/createCollectionFork.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -25,7 +25,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/fork/${params.collectionId}`; @@ -34,13 +34,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.label !== undefined) bodyPayload.label = params.label; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createCollectionRequest.ts b/src/tools/createCollectionRequest.ts index 494f4c6..14c8ff1 100644 --- a/src/tools/createCollectionRequest.ts +++ b/src/tools/createCollectionRequest.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -35,7 +35,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/requests`; @@ -44,13 +44,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.name !== undefined) bodyPayload.name = params.name; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createCollectionResponse.ts b/src/tools/createCollectionResponse.ts index 6cc0dd2..9ef7559 100644 --- a/src/tools/createCollectionResponse.ts +++ b/src/tools/createCollectionResponse.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -30,7 +30,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/responses`; @@ -39,13 +39,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.name !== undefined) bodyPayload.name = params.name; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createEnvironment.ts b/src/tools/createEnvironment.ts index 48d682f..036c657 100644 --- a/src/tools/createEnvironment.ts +++ b/src/tools/createEnvironment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -17,12 +17,20 @@ export const parameters = z.object({ name: z.string().describe("The environment's name."), values: z .array( - z.object({ - enabled: z.boolean().describe('If true, the variable is enabled.').optional(), - key: z.string().describe("The variable's name.").optional(), - value: z.string().describe("The variable's value.").optional(), - type: z.enum(['secret', 'default']).describe('The variable type.').optional(), - }) + z + .object({ + enabled: z.boolean().describe('If true, the variable is enabled.').optional(), + key: z.string().describe("The variable's name.").optional(), + value: z.string().describe("The variable's value.").optional(), + type: z + .enum(['secret', 'default']) + .describe( + "The variable's type:\n- `secret` — The variable value is masked.\n- `default` — The variable value is visible in plain text.\n" + ) + .optional(), + description: z.string().max(512).describe("The variable's description.").optional(), + }) + .describe("Information about the environment's variables.") ) .describe("Information about the environment's variables.") .optional(), @@ -40,7 +48,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/environments`; @@ -49,13 +57,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.environment !== undefined) bodyPayload.environment = params.environment; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createFolderComment.ts b/src/tools/createFolderComment.ts index a07a5c2..1663166 100644 --- a/src/tools/createFolderComment.ts +++ b/src/tools/createFolderComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -23,7 +23,7 @@ export const parameters = z.object({ .optional(), tags: z .object({ - userName: z + '{{userName}}': z .object({ type: z.literal('user').describe('The `user` value.'), id: z.string().describe("The user's ID."), @@ -46,7 +46,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/folders/${params.folderId}/comments`; @@ -56,13 +56,12 @@ export async function handler( if (params.body !== undefined) bodyPayload.body = params.body; if (params.threadId !== undefined) bodyPayload.threadId = params.threadId; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createMock.ts b/src/tools/createMock.ts index 8860296..169a589 100644 --- a/src/tools/createMock.ts +++ b/src/tools/createMock.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -39,7 +39,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/mocks`; @@ -48,13 +48,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.mock !== undefined) bodyPayload.mock = params.mock; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createMonitor.ts b/src/tools/createMonitor.ts index 9465015..99982c1 100644 --- a/src/tools/createMonitor.ts +++ b/src/tools/createMonitor.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -41,6 +41,7 @@ export const parameters = z.object({ ) .optional(), }) + .describe("Information about the monitor's retry settings.") .optional(), options: z .object({ @@ -141,7 +142,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/monitors`; @@ -150,13 +151,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.monitor !== undefined) bodyPayload.monitor = params.monitor; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createRequestComment.ts b/src/tools/createRequestComment.ts index 2417681..8198b0a 100644 --- a/src/tools/createRequestComment.ts +++ b/src/tools/createRequestComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -27,7 +27,7 @@ export const parameters = z.object({ .optional(), tags: z .object({ - userName: z + '{{userName}}': z .object({ type: z.literal('user').describe('The `user` value.'), id: z.string().describe("The user's ID."), @@ -50,7 +50,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/requests/${params.requestId}/comments`; @@ -60,13 +60,12 @@ export async function handler( if (params.body !== undefined) bodyPayload.body = params.body; if (params.threadId !== undefined) bodyPayload.threadId = params.threadId; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createResponseComment.ts b/src/tools/createResponseComment.ts index 577b171..f23c2f1 100644 --- a/src/tools/createResponseComment.ts +++ b/src/tools/createResponseComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -23,7 +23,7 @@ export const parameters = z.object({ .optional(), tags: z .object({ - userName: z + '{{userName}}': z .object({ type: z.literal('user').describe('The `user` value.'), id: z.string().describe("The user's ID."), @@ -46,7 +46,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/responses/${params.responseId}/comments`; @@ -56,13 +56,12 @@ export async function handler( if (params.body !== undefined) bodyPayload.body = params.body; if (params.threadId !== undefined) bodyPayload.threadId = params.threadId; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createSpec.ts b/src/tools/createSpec.ts index 42943d3..fcac726 100644 --- a/src/tools/createSpec.ts +++ b/src/tools/createSpec.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -16,36 +16,21 @@ export const parameters = z.object({ type: z.enum(['OPENAPI:3.0', 'ASYNCAPI:2.0']).describe("The specification's type."), files: z .array( - z.any().superRefine((x, ctx) => { - const schemas = [ - z.object({ - path: z.string().describe("The file's path. Accepts JSON or YAML files."), - content: z.string().describe("The file's stringified contents."), - type: z - .enum(['DEFAULT', 'ROOT']) - .describe( - 'The type of file. This property is required when creating multi-file specifications:\n- `ROOT` — The file containing the full OpenAPI structure. This serves as the entry point for the API spec and references other (`DEFAULT`) spec files. Multi-file specs can only have one root file.\n- `DEFAULT` — A file referenced by the `ROOT` file.\n' - ), - }), - z.object({ - path: z.string().describe("The file's path. Accepts JSON or YAML files."), - content: z.string().describe("The file's stringified contents."), - }), - ]; - const errors = schemas.reduce( - (errors, schema) => - ((result) => (result.error ? [...errors, result.error] : errors))(schema.safeParse(x)), - [] - ); - if (schemas.length - errors.length !== 1) { - ctx.addIssue({ - path: ctx.path, - code: 'invalid_union', - unionErrors: errors, - message: 'Invalid input: Should pass single schema', - }); - } - }) + z.union([ + z.object({ + path: z.string().describe("The file's path. Accepts JSON or YAML files."), + content: z.string().describe("The file's stringified contents."), + type: z + .enum(['DEFAULT', 'ROOT']) + .describe( + 'The type of file. This property is required when creating multi-file specifications:\n- `ROOT` — The file containing the full OpenAPI structure. This serves as the entry point for the API spec and references other (`DEFAULT`) spec files. Multi-file specs can only have one root file.\n- `DEFAULT` — A file referenced by the `ROOT` file.\n' + ), + }), + z.object({ + path: z.string().describe("The file's path. Accepts JSON or YAML files."), + content: z.string().describe("The file's stringified contents."), + }), + ]) ) .describe("A list of the specification's files and their contents."), }); @@ -59,7 +44,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs`; @@ -70,13 +55,12 @@ export async function handler( if (params.name !== undefined) bodyPayload.name = params.name; if (params.type !== undefined) bodyPayload.type = params.type; if (params.files !== undefined) bodyPayload.files = params.files; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createSpecFile.ts b/src/tools/createSpecFile.ts index 83ac20a..9420fe4 100644 --- a/src/tools/createSpecFile.ts +++ b/src/tools/createSpecFile.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -25,7 +25,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}/files`; @@ -34,13 +34,12 @@ export async function handler( const bodyPayload: any = {}; if (params.path !== undefined) bodyPayload.path = params.path; if (params.content !== undefined) bodyPayload.content = params.content; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/createWorkspace.ts b/src/tools/createWorkspace.ts index d76221b..efdefd0 100644 --- a/src/tools/createWorkspace.ts +++ b/src/tools/createWorkspace.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -35,7 +35,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/workspaces`; @@ -43,13 +43,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.workspace !== undefined) bodyPayload.workspace = params.workspace; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/deleteApiCollectionComment.ts b/src/tools/deleteApiCollectionComment.ts index eaaa824..8d11bc1 100644 --- a/src/tools/deleteApiCollectionComment.ts +++ b/src/tools/deleteApiCollectionComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -25,17 +25,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/apis/${params.apiId}/collections/${params.collectionId}/comments/${params.commentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteCollection.ts b/src/tools/deleteCollection.ts index 0422da8..0e38ac6 100644 --- a/src/tools/deleteCollection.ts +++ b/src/tools/deleteCollection.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -25,17 +25,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteCollectionComment.ts b/src/tools/deleteCollectionComment.ts index 561e33f..f5ea07e 100644 --- a/src/tools/deleteCollectionComment.ts +++ b/src/tools/deleteCollectionComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -24,17 +24,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/comments/${params.commentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteCollectionFolder.ts b/src/tools/deleteCollectionFolder.ts index f31c32a..cbfa605 100644 --- a/src/tools/deleteCollectionFolder.ts +++ b/src/tools/deleteCollectionFolder.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -22,17 +22,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/folders/${params.folderId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteCollectionRequest.ts b/src/tools/deleteCollectionRequest.ts index 385c645..b5584b6 100644 --- a/src/tools/deleteCollectionRequest.ts +++ b/src/tools/deleteCollectionRequest.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -22,17 +22,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/requests/${params.requestId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteCollectionResponse.ts b/src/tools/deleteCollectionResponse.ts index bbb772e..2d6fe9f 100644 --- a/src/tools/deleteCollectionResponse.ts +++ b/src/tools/deleteCollectionResponse.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -22,17 +22,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/responses/${params.responseId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteEnvironment.ts b/src/tools/deleteEnvironment.ts index fd7a067..ab87143 100644 --- a/src/tools/deleteEnvironment.ts +++ b/src/tools/deleteEnvironment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/environments/${params.environmentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteFolderComment.ts b/src/tools/deleteFolderComment.ts index 537f44e..47bcba2 100644 --- a/src/tools/deleteFolderComment.ts +++ b/src/tools/deleteFolderComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -25,17 +25,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/folders/${params.folderId}/comments/${params.commentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteMock.ts b/src/tools/deleteMock.ts index 4646eb1..fb22bad 100644 --- a/src/tools/deleteMock.ts +++ b/src/tools/deleteMock.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/mocks/${params.mockId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteMonitor.ts b/src/tools/deleteMonitor.ts index 14de212..971802e 100644 --- a/src/tools/deleteMonitor.ts +++ b/src/tools/deleteMonitor.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/monitors/${params.monitorId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deletePanElementOrFolder.ts b/src/tools/deletePanElementOrFolder.ts index 686d7c6..c7b6781 100644 --- a/src/tools/deletePanElementOrFolder.ts +++ b/src/tools/deletePanElementOrFolder.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -28,17 +28,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/network/private/${params.elementType}/${params.elementId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteRequestComment.ts b/src/tools/deleteRequestComment.ts index 0260336..1c9fb4f 100644 --- a/src/tools/deleteRequestComment.ts +++ b/src/tools/deleteRequestComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -25,17 +25,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/requests/${params.requestId}/comments/${params.commentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteResponseComment.ts b/src/tools/deleteResponseComment.ts index 6fc6209..c30b9f3 100644 --- a/src/tools/deleteResponseComment.ts +++ b/src/tools/deleteResponseComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -25,17 +25,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/responses/${params.responseId}/comments/${params.commentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteSpec.ts b/src/tools/deleteSpec.ts index e1f4b85..0632b58 100644 --- a/src/tools/deleteSpec.ts +++ b/src/tools/deleteSpec.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteSpecFile.ts b/src/tools/deleteSpecFile.ts index 4b49c97..1acb9e1 100644 --- a/src/tools/deleteSpecFile.ts +++ b/src/tools/deleteSpecFile.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -24,17 +24,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}/files/${params.filePath}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/deleteWorkspace.ts b/src/tools/deleteWorkspace.ts index 01548d0..e45be60 100644 --- a/src/tools/deleteWorkspace.ts +++ b/src/tools/deleteWorkspace.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/workspaces/${params.workspaceId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/duplicateCollection.ts b/src/tools/duplicateCollection.ts index 21cfd13..cb6fabc 100644 --- a/src/tools/duplicateCollection.ts +++ b/src/tools/duplicateCollection.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -28,7 +28,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/duplicates`; @@ -37,13 +37,12 @@ export async function handler( const bodyPayload: any = {}; if (params.workspace !== undefined) bodyPayload.workspace = params.workspace; if (params.suffix !== undefined) bodyPayload.suffix = params.suffix; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/generateCollection.ts b/src/tools/generateCollection.ts index deac919..dc27150 100644 --- a/src/tools/generateCollection.ts +++ b/src/tools/generateCollection.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -64,6 +64,12 @@ export const parameters = z.object({ 'Whether authentication details should be included in all requests, or always inherited from the collection.' ) .default(false), + nestedFolderHierarchy: z + .boolean() + .describe( + "If true, creates subfolders in the generated collection based on the order of the endpoints' tags." + ) + .default(false), }) .describe( "The advanced creation options and their values. For more details, see Postman's [OpenAPI to Postman Collection Converter OPTIONS documentation](https://github.com/postmanlabs/openapi-to-postman/blob/develop/OPTIONS.md). These properties are case-sensitive." @@ -80,7 +86,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}/generations/${params.elementType}`; @@ -89,13 +95,12 @@ export async function handler( const bodyPayload: any = {}; if (params.name !== undefined) bodyPayload.name = params.name; if (params.options !== undefined) bodyPayload.options = params.options; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/generateSpecFromCollection.ts b/src/tools/generateSpecFromCollection.ts index 2d5211b..3c77e45 100644 --- a/src/tools/generateSpecFromCollection.ts +++ b/src/tools/generateSpecFromCollection.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -27,7 +27,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionUid}/generations/${params.elementType}`; @@ -37,13 +37,12 @@ export async function handler( if (params.name !== undefined) bodyPayload.name = params.name; if (params.type !== undefined) bodyPayload.type = params.type; if (params.format !== undefined) bodyPayload.format = params.format; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/getAllElementsAndFolders.ts b/src/tools/getAllElementsAndFolders.ts index b770a89..ca82f4f 100644 --- a/src/tools/getAllElementsAndFolders.ts +++ b/src/tools/getAllElementsAndFolders.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -99,7 +99,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/network/private`; @@ -119,11 +119,10 @@ export async function handler( query.set('parentFolderId', String(params.parentFolderId)); if (params.type !== undefined) query.set('type', String(params.type)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getAllPanAddElementRequests.ts b/src/tools/getAllPanAddElementRequests.ts index e486890..a553d94 100644 --- a/src/tools/getAllPanAddElementRequests.ts +++ b/src/tools/getAllPanAddElementRequests.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -76,7 +76,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/network/private/network-entity/request/all`; @@ -92,11 +92,10 @@ export async function handler( if (params.offset !== undefined) query.set('offset', String(params.offset)); if (params.limit !== undefined) query.set('limit', String(params.limit)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getAllSpecs.ts b/src/tools/getAllSpecs.ts index 74fbf17..ba9b1ae 100644 --- a/src/tools/getAllSpecs.ts +++ b/src/tools/getAllSpecs.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -32,7 +32,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs`; @@ -41,11 +41,10 @@ export async function handler( if (params.cursor !== undefined) query.set('cursor', String(params.cursor)); if (params.limit !== undefined) query.set('limit', String(params.limit)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getAsyncSpecTaskStatus.ts b/src/tools/getAsyncSpecTaskStatus.ts index 375e6e5..2e5b1ed 100644 --- a/src/tools/getAsyncSpecTaskStatus.ts +++ b/src/tools/getAsyncSpecTaskStatus.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -23,17 +23,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/${params.elementType}/${params.elementId}/tasks/${params.taskId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getAuthenticatedUser.ts b/src/tools/getAuthenticatedUser.ts index 241ac13..47d992d 100644 --- a/src/tools/getAuthenticatedUser.ts +++ b/src/tools/getAuthenticatedUser.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/me`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getCollection.ts b/src/tools/getCollection.ts index 4789599..e8bc9ec 100644 --- a/src/tools/getCollection.ts +++ b/src/tools/getCollection.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -39,7 +39,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}`; @@ -47,11 +47,10 @@ export async function handler( if (params.access_key !== undefined) query.set('access_key', String(params.access_key)); if (params.model !== undefined) query.set('model', String(params.model)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getCollectionComments.ts b/src/tools/getCollectionComments.ts index 1c1696b..6dafe50 100644 --- a/src/tools/getCollectionComments.ts +++ b/src/tools/getCollectionComments.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/comments`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getCollectionFolder.ts b/src/tools/getCollectionFolder.ts index 06e40ff..2392c2c 100644 --- a/src/tools/getCollectionFolder.ts +++ b/src/tools/getCollectionFolder.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -31,7 +31,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/folders/${params.folderId}`; @@ -40,11 +40,10 @@ export async function handler( if (params.uid !== undefined) query.set('uid', String(params.uid)); if (params.populate !== undefined) query.set('populate', String(params.populate)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getCollectionForks.ts b/src/tools/getCollectionForks.ts index 9c825c8..9e1009a 100644 --- a/src/tools/getCollectionForks.ts +++ b/src/tools/getCollectionForks.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -40,7 +40,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/forks`; @@ -49,11 +49,10 @@ export async function handler( if (params.limit !== undefined) query.set('limit', String(params.limit)); if (params.direction !== undefined) query.set('direction', String(params.direction)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getCollectionRequest.ts b/src/tools/getCollectionRequest.ts index aaf8bc0..1d6019f 100644 --- a/src/tools/getCollectionRequest.ts +++ b/src/tools/getCollectionRequest.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -31,7 +31,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/requests/${params.requestId}`; @@ -40,11 +40,10 @@ export async function handler( if (params.uid !== undefined) query.set('uid', String(params.uid)); if (params.populate !== undefined) query.set('populate', String(params.populate)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getCollectionResponse.ts b/src/tools/getCollectionResponse.ts index 40648f5..a6e044c 100644 --- a/src/tools/getCollectionResponse.ts +++ b/src/tools/getCollectionResponse.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -31,7 +31,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/responses/${params.responseId}`; @@ -40,11 +40,10 @@ export async function handler( if (params.uid !== undefined) query.set('uid', String(params.uid)); if (params.populate !== undefined) query.set('populate', String(params.populate)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getCollectionTags.ts b/src/tools/getCollectionTags.ts index f152309..d0dcbc2 100644 --- a/src/tools/getCollectionTags.ts +++ b/src/tools/getCollectionTags.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/tags`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getCollectionUpdatesTasks.ts b/src/tools/getCollectionUpdatesTasks.ts index 8a18781..1bcc48b 100644 --- a/src/tools/getCollectionUpdatesTasks.ts +++ b/src/tools/getCollectionUpdatesTasks.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collection-updates-tasks/${params.taskId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getCollections.ts b/src/tools/getCollections.ts index e6354c3..164c135 100644 --- a/src/tools/getCollections.ts +++ b/src/tools/getCollections.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -34,7 +34,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections`; @@ -44,11 +44,10 @@ export async function handler( if (params.limit !== undefined) query.set('limit', String(params.limit)); if (params.offset !== undefined) query.set('offset', String(params.offset)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getCollectionsForkedByUser.ts b/src/tools/getCollectionsForkedByUser.ts index 5c5e834..c077dd5 100644 --- a/src/tools/getCollectionsForkedByUser.ts +++ b/src/tools/getCollectionsForkedByUser.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -37,7 +37,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/collection-forks`; @@ -46,11 +46,10 @@ export async function handler( if (params.limit !== undefined) query.set('limit', String(params.limit)); if (params.direction !== undefined) query.set('direction', String(params.direction)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getDuplicateCollectionTaskStatus.ts b/src/tools/getDuplicateCollectionTaskStatus.ts index b940bc9..45caea2 100644 --- a/src/tools/getDuplicateCollectionTaskStatus.ts +++ b/src/tools/getDuplicateCollectionTaskStatus.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collection-duplicate-tasks/${params.taskId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getEnvironment.ts b/src/tools/getEnvironment.ts index b48ef2b..726956c 100644 --- a/src/tools/getEnvironment.ts +++ b/src/tools/getEnvironment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/environments/${params.environmentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getEnvironments.ts b/src/tools/getEnvironments.ts index 4182311..f6f8b46 100644 --- a/src/tools/getEnvironments.ts +++ b/src/tools/getEnvironments.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -23,18 +23,17 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/environments`; const query = new URLSearchParams(); if (params.workspace !== undefined) query.set('workspace', String(params.workspace)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getFolderComments.ts b/src/tools/getFolderComments.ts index c30f92d..df70002 100644 --- a/src/tools/getFolderComments.ts +++ b/src/tools/getFolderComments.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -22,17 +22,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/folders/${params.folderId}/comments`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getGeneratedCollectionSpecs.ts b/src/tools/getGeneratedCollectionSpecs.ts index d151a96..416c533 100644 --- a/src/tools/getGeneratedCollectionSpecs.ts +++ b/src/tools/getGeneratedCollectionSpecs.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -22,17 +22,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionUid}/generations/${params.elementType}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getMock.ts b/src/tools/getMock.ts index 5875fe6..810147e 100644 --- a/src/tools/getMock.ts +++ b/src/tools/getMock.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/mocks/${params.mockId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getMocks.ts b/src/tools/getMocks.ts index fac0180..ada963d 100644 --- a/src/tools/getMocks.ts +++ b/src/tools/getMocks.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -24,7 +24,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/mocks`; @@ -32,11 +32,10 @@ export async function handler( if (params.teamId !== undefined) query.set('teamId', String(params.teamId)); if (params.workspace !== undefined) query.set('workspace', String(params.workspace)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getMonitor.ts b/src/tools/getMonitor.ts index ae0334f..3f12f25 100644 --- a/src/tools/getMonitor.ts +++ b/src/tools/getMonitor.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/monitors/${params.monitorId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getMonitors.ts b/src/tools/getMonitors.ts index bee1af5..5e93276 100644 --- a/src/tools/getMonitors.ts +++ b/src/tools/getMonitors.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -45,7 +45,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/monitors`; @@ -60,11 +60,10 @@ export async function handler( if (params.cursor !== undefined) query.set('cursor', String(params.cursor)); if (params.limit !== undefined) query.set('limit', String(params.limit)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getRequestComments.ts b/src/tools/getRequestComments.ts index c14f38f..f20cb6c 100644 --- a/src/tools/getRequestComments.ts +++ b/src/tools/getRequestComments.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -26,17 +26,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/requests/${params.requestId}/comments`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getResponseComments.ts b/src/tools/getResponseComments.ts index 55c65ef..3d450da 100644 --- a/src/tools/getResponseComments.ts +++ b/src/tools/getResponseComments.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -22,17 +22,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/responses/${params.responseId}/comments`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getSourceCollectionStatus.ts b/src/tools/getSourceCollectionStatus.ts index a8828f6..f5a6a3e 100644 --- a/src/tools/getSourceCollectionStatus.ts +++ b/src/tools/getSourceCollectionStatus.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/source-status`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getSpec.ts b/src/tools/getSpec.ts index 2b90b53..4b11a34 100644 --- a/src/tools/getSpec.ts +++ b/src/tools/getSpec.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getSpecCollections.ts b/src/tools/getSpecCollections.ts index bb7c7e6..e0f1cdd 100644 --- a/src/tools/getSpecCollections.ts +++ b/src/tools/getSpecCollections.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -33,7 +33,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}/generations/${params.elementType}`; @@ -41,11 +41,10 @@ export async function handler( if (params.limit !== undefined) query.set('limit', String(params.limit)); if (params.cursor !== undefined) query.set('cursor', String(params.cursor)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getSpecDefinition.ts b/src/tools/getSpecDefinition.ts index 4954163..2818043 100644 --- a/src/tools/getSpecDefinition.ts +++ b/src/tools/getSpecDefinition.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}/definitions`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getSpecFile.ts b/src/tools/getSpecFile.ts index 85dcee8..96796f6 100644 --- a/src/tools/getSpecFile.ts +++ b/src/tools/getSpecFile.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -22,17 +22,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}/files/${params.filePath}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getSpecFiles.ts b/src/tools/getSpecFiles.ts index 0ee167d..b0b0ce5 100644 --- a/src/tools/getSpecFiles.ts +++ b/src/tools/getSpecFiles.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}/files`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getStatusOfAnAsyncTask.ts b/src/tools/getStatusOfAnAsyncApiTask.ts similarity index 84% rename from src/tools/getStatusOfAnAsyncTask.ts rename to src/tools/getStatusOfAnAsyncApiTask.ts index b1e725d..39f1298 100644 --- a/src/tools/getStatusOfAnAsyncTask.ts +++ b/src/tools/getStatusOfAnAsyncApiTask.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -7,7 +7,7 @@ function asMcpError(error: unknown): McpError { return new McpError(ErrorCode.InternalError, cause); } -export const method = 'getStatusOfAnAsyncTask'; +export const method = 'getStatusOfAnAsyncApiTask'; export const description = 'Gets the status of an asynchronous task.'; export const parameters = z.object({ apiId: z.string().describe("The API's ID."), @@ -25,17 +25,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/apis/${params.apiId}/tasks/${params.taskId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getTaggedEntities.ts b/src/tools/getTaggedEntities.ts index 11d7144..e3996da 100644 --- a/src/tools/getTaggedEntities.ts +++ b/src/tools/getTaggedEntities.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -50,7 +50,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/tags/${params.slug}/entities`; @@ -60,11 +60,10 @@ export async function handler( if (params.cursor !== undefined) query.set('cursor', String(params.cursor)); if (params.entityType !== undefined) query.set('entityType', String(params.entityType)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getWorkspace.ts b/src/tools/getWorkspace.ts index 8004ec7..2a4a922 100644 --- a/src/tools/getWorkspace.ts +++ b/src/tools/getWorkspace.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -29,18 +29,17 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/workspaces/${params.workspaceId}`; const query = new URLSearchParams(); if (params.include !== undefined) query.set('include', String(params.include)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getWorkspaceGlobalVariables.ts b/src/tools/getWorkspaceGlobalVariables.ts index 56704f4..2e74239 100644 --- a/src/tools/getWorkspaceGlobalVariables.ts +++ b/src/tools/getWorkspaceGlobalVariables.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/workspaces/${params.workspaceId}/global-variables`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getWorkspaceTags.ts b/src/tools/getWorkspaceTags.ts index 9c8fdc9..727db2d 100644 --- a/src/tools/getWorkspaceTags.ts +++ b/src/tools/getWorkspaceTags.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -19,17 +19,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/workspaces/${params.workspaceId}/tags`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/getWorkspaces.ts b/src/tools/getWorkspaces.ts index 743a9ca..7a95c6a 100644 --- a/src/tools/getWorkspaces.ts +++ b/src/tools/getWorkspaces.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -39,7 +39,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/workspaces`; @@ -48,11 +48,10 @@ export async function handler( if (params.createdBy !== undefined) query.set('createdBy', String(params.createdBy)); if (params.include !== undefined) query.set('include', String(params.include)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'GET', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.get(url, options); return { content: [ { diff --git a/src/tools/mergeCollectionFork.ts b/src/tools/mergeCollectionFork.ts new file mode 100644 index 0000000..e003942 --- /dev/null +++ b/src/tools/mergeCollectionFork.ts @@ -0,0 +1,63 @@ +import { z } from 'zod'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; +import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; + +function asMcpError(error: unknown): McpError { + const cause = (error as any)?.cause ?? String(error); + return new McpError(ErrorCode.InternalError, cause); +} + +export const method = 'mergeCollectionFork'; +export const description = + '**This endpoint is deprecated.**\n\nMerges a forked collection back into its parent collection. You must have the [Editor role](https://learning.postman.com/docs/collaborating-in-postman/roles-and-permissions/#collection-roles) for the collection to merge a fork.\n'; +export const parameters = z.object({ + destination: z.string().describe("The destination (parent) collection's unique ID."), + source: z.string().describe("The source collection's unique ID."), + strategy: z + .enum(['deleteSource', 'updateSourceWithDestination']) + .describe( + "The fork's merge strategy:\n- `deleteSource` — Merge the changes into the parent collection. After the merge process is complete, Postman deletes the fork. You must have Editor access to both the parent and forked collections.\n- `updateSourceWithDestination` — Merge the changes into the parent collection. Any differences in the parent collection are also made to the fork.\n" + ) + .default('updateSourceWithDestination'), +}); +export const annotations = { + title: + '**This endpoint is deprecated.**\n\nMerges a forked collection back into its parent collection. You must have the [Editor role](https://learning.postman.com/docs/collaborating-in-postman/roles-and-permissions/#collection-roles) for the collection to merge a fork.\n', + readOnlyHint: false, + destructiveHint: false, + idempotentHint: false, +}; + +export async function handler( + params: z.infer, + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } +): Promise<{ content: Array<{ type: string; text: string } & Record> }> { + try { + const endpoint = `/collections/merge`; + const query = new URLSearchParams(); + const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; + const bodyPayload: any = {}; + if (params.destination !== undefined) bodyPayload.destination = params.destination; + if (params.source !== undefined) bodyPayload.source = params.source; + if (params.strategy !== undefined) bodyPayload.strategy = params.strategy; + const options: any = { + body: JSON.stringify(bodyPayload), + contentType: ContentType.Json, + headers: extra.headers, + }; + const result = await extra.client.post(url, options); + return { + content: [ + { + type: 'text', + text: `${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}`, + }, + ], + }; + } catch (e: unknown) { + if (e instanceof McpError) { + throw e; + } + throw asMcpError(e); + } +} diff --git a/src/tools/patchCollection.ts b/src/tools/patchCollection.ts index 0ebf980..d74254e 100644 --- a/src/tools/patchCollection.ts +++ b/src/tools/patchCollection.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -9,7 +9,7 @@ function asMcpError(error: unknown): McpError { export const method = 'patchCollection'; export const description = - 'Updates specific collection information, such as its name, events, or its variables. For more information about the \\`auth\\`, \\`variable\\`, and \\`events\\` properties, refer to the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html):\n- For \\`variable\\`, refer to the **Variable List** entry. Also accepts \\`variables\\`.\n- For \\`auth\\`, refer to the **Auth** entry.\n- For \\`events\\`, refer to the **Event List** entry.\n'; + 'Updates specific collection information, such as its name, events, or its variables. For more information, see the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).\n'; export const parameters = z.object({ collectionId: z .string() @@ -34,21 +34,15 @@ export const parameters = z.object({ .describe("The variable's ID. Doesn't apply to collection-level variables.") .optional(), key: z.string().describe("The variable's key (name).").optional(), - description: z - .string() - .describe( - "The variable's description. Doesn't apply to collection-level variables." - ) - .optional(), - value: z.string().describe("The key's value.").optional(), - type: z - .enum(['string', 'boolean', 'integer']) - .describe("The variable's type.") + description: z.string().max(512).describe("The variable's description.").optional(), + value: z + .union([z.string(), z.boolean(), z.number().int()]) + .describe("The key's value.") .optional(), disabled: z .boolean() .describe( - 'If true, the variable is not enabled. Applies only to query parameter variables.' + "If true, the variable is not enabled. Doesn't apply to path parameter variables." ) .default(false), }) @@ -372,13 +366,16 @@ export const parameters = z.object({ }) .describe("Information about the collection's events.") ) + .describe( + 'A list of scripts configured to run when specific events occur. These scripts can be referenced in the collection by their ID.' + ) .optional(), }) .optional(), }); export const annotations = { title: - 'Updates specific collection information, such as its name, events, or its variables. For more information about the \\`auth\\`, \\`variable\\`, and \\`events\\` properties, refer to the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html):\n- For \\`variable\\`, refer to the **Variable List** entry. Also accepts \\`variables\\`.\n- For \\`auth\\`, refer to the **Auth** entry.\n- For \\`events\\`, refer to the **Event List** entry.\n', + 'Updates specific collection information, such as its name, events, or its variables. For more information, see the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).\n', readOnlyHint: false, destructiveHint: false, idempotentHint: true, @@ -386,7 +383,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}`; @@ -394,13 +391,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.collection !== undefined) bodyPayload.collection = params.collection; - const result = await fetchPostmanAPI(url, { - method: 'PATCH', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.patch(url, options); return { content: [ { diff --git a/src/tools/patchEnvironment.ts b/src/tools/patchEnvironment.ts index c4623b5..d962aaf 100644 --- a/src/tools/patchEnvironment.ts +++ b/src/tools/patchEnvironment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -9,11 +9,11 @@ function asMcpError(error: unknown): McpError { export const method = 'patchEnvironment'; export const description = - 'Updates specific environment properties, such as its name and variables.\n\n**Note:**\n\n- The request body size cannot exceed the maximum allowed size of 30MB.\n- If you receive an HTTP \\`411 Length Required\\` error response, manually pass the \\`Content-Length\\` header and its value in the request header.\n'; + 'Updates specific environment properties, such as its name and variables.\n\n**Note:**\n\n- You can only perform one type of operation at a time. For example, you cannot perform an \\`add\\` and \\`replace\\` operation in the same call.\n- The request body size cannot exceed the maximum allowed size of 30MB.\n- If you receive an HTTP \\`411 Length Required\\` error response, manually pass the \\`Content-Length\\` header and its value in the request header.\n- To add a description to an existing variable, use the \\`add\\` operation.\n'; export const parameters = z.object({ environmentId: z.string().describe("The environment's ID.") }); export const annotations = { title: - 'Updates specific environment properties, such as its name and variables.\n\n**Note:**\n\n- The request body size cannot exceed the maximum allowed size of 30MB.\n- If you receive an HTTP \\`411 Length Required\\` error response, manually pass the \\`Content-Length\\` header and its value in the request header.\n', + 'Updates specific environment properties, such as its name and variables.\n\n**Note:**\n\n- You can only perform one type of operation at a time. For example, you cannot perform an \\`add\\` and \\`replace\\` operation in the same call.\n- The request body size cannot exceed the maximum allowed size of 30MB.\n- If you receive an HTTP \\`411 Length Required\\` error response, manually pass the \\`Content-Length\\` header and its value in the request header.\n- To add a description to an existing variable, use the \\`add\\` operation.\n', readOnlyHint: false, destructiveHint: false, idempotentHint: true, @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/environments/${params.environmentId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'PATCH', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.patch(url, options); return { content: [ { diff --git a/src/tools/postPanElementOrFolder.ts b/src/tools/postPanElementOrFolder.ts index 7cf526e..a72320a 100644 --- a/src/tools/postPanElementOrFolder.ts +++ b/src/tools/postPanElementOrFolder.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/network/private`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'POST', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/publishDocumentation.ts b/src/tools/publishDocumentation.ts index aba576f..ea1b4bc 100644 --- a/src/tools/publishDocumentation.ts +++ b/src/tools/publishDocumentation.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -119,7 +119,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/public-documentations`; @@ -131,13 +131,12 @@ export async function handler( if (params.documentationLayout !== undefined) bodyPayload.documentationLayout = params.documentationLayout; if (params.customization !== undefined) bodyPayload.customization = params.customization; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/publishMock.ts b/src/tools/publishMock.ts index 88b9589..87c25ef 100644 --- a/src/tools/publishMock.ts +++ b/src/tools/publishMock.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/mocks/${params.mockId}/publish`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'POST', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/pullCollectionChanges.ts b/src/tools/pullCollectionChanges.ts index 8705c6e..68b4ff3 100644 --- a/src/tools/pullCollectionChanges.ts +++ b/src/tools/pullCollectionChanges.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/pulls`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'PUT', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/putCollection.ts b/src/tools/putCollection.ts index 7a404f4..2ea5549 100644 --- a/src/tools/putCollection.ts +++ b/src/tools/putCollection.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -1148,7 +1148,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}`; @@ -1156,13 +1156,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.collection !== undefined) bodyPayload.collection = params.collection; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/putEnvironment.ts b/src/tools/putEnvironment.ts index d6acc07..4b7d0e1 100644 --- a/src/tools/putEnvironment.ts +++ b/src/tools/putEnvironment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -17,12 +17,20 @@ export const parameters = z.object({ name: z.string().describe("The environment's name.").optional(), values: z .array( - z.object({ - enabled: z.boolean().describe('If true, the variable is enabled.').optional(), - key: z.string().describe("The variable's name.").optional(), - value: z.string().describe("The variable's value.").optional(), - type: z.enum(['secret', 'default']).describe('The variable type.').optional(), - }) + z + .object({ + enabled: z.boolean().describe('If true, the variable is enabled.').optional(), + key: z.string().describe("The variable's name.").optional(), + value: z.string().describe("The variable's value.").optional(), + type: z + .enum(['secret', 'default']) + .describe( + "The variable's type:\n- `secret` — The variable value is masked.\n- `default` — The variable value is visible in plain text.\n" + ) + .optional(), + description: z.string().max(512).describe("The variable's description.").optional(), + }) + .describe("Information about the environment's variables.") ) .describe("Information about the environment's variables.") .optional(), @@ -40,7 +48,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/environments/${params.environmentId}`; @@ -48,13 +56,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.environment !== undefined) bodyPayload.environment = params.environment; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/resolveCommentThread.ts b/src/tools/resolveCommentThread.ts index c3ce153..87f02c8 100644 --- a/src/tools/resolveCommentThread.ts +++ b/src/tools/resolveCommentThread.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -23,17 +23,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/comments-resolutions/${params.threadId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'POST', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/runMonitor.ts b/src/tools/runMonitor.ts index 014dcfd..beea4c1 100644 --- a/src/tools/runMonitor.ts +++ b/src/tools/runMonitor.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -9,7 +9,7 @@ function asMcpError(error: unknown): McpError { export const method = 'runMonitor'; export const description = - 'Runs a monitor and returns its run results.\n\n**Note:**\n\n- This endpoint has a timeout restriction of 300 seconds. It is recommended that you include the \\`async=true\\` query parameter when using this endpoint.\n- If you pass the \\`async=true\\` query parameter, the response does not return the \\`stats\\`, \\`executions\\`, and \\`failures\\` responses. To get this information for an asynchronous run, call the GET \\`/monitors/{id}\\` endpoint.\n'; + "Runs a monitor and returns its run results.\n\n**Note:**\n\n- If you pass the \\`async=true\\` query parameter, the response does not return the \\`stats\\`, \\`executions\\`, and \\`failures\\` responses. To get this information for an asynchronous run, call the GET \\`/monitors/{id}\\` endpoint.\n- If the call exceeds 300 seconds, the endpoint returns an HTTP \\`202 Accepted\\` response. Use the GET \\`/monitors/{id}\\` endpoint to check the run's status in the response's \\`lastRun\\` property. To avoid this, it is recommended that you include the \\`async=true\\` query parameter when using this endpoint.\n"; export const parameters = z.object({ monitorId: z.string().describe("The monitor's ID."), async: z @@ -21,7 +21,7 @@ export const parameters = z.object({ }); export const annotations = { title: - 'Runs a monitor and returns its run results.\n\n**Note:**\n\n- This endpoint has a timeout restriction of 300 seconds. It is recommended that you include the \\`async=true\\` query parameter when using this endpoint.\n- If you pass the \\`async=true\\` query parameter, the response does not return the \\`stats\\`, \\`executions\\`, and \\`failures\\` responses. To get this information for an asynchronous run, call the GET \\`/monitors/{id}\\` endpoint.\n', + "Runs a monitor and returns its run results.\n\n**Note:**\n\n- If you pass the \\`async=true\\` query parameter, the response does not return the \\`stats\\`, \\`executions\\`, and \\`failures\\` responses. To get this information for an asynchronous run, call the GET \\`/monitors/{id}\\` endpoint.\n- If the call exceeds 300 seconds, the endpoint returns an HTTP \\`202 Accepted\\` response. Use the GET \\`/monitors/{id}\\` endpoint to check the run's status in the response's \\`lastRun\\` property. To avoid this, it is recommended that you include the \\`async=true\\` query parameter when using this endpoint.\n", readOnlyHint: false, destructiveHint: false, idempotentHint: false, @@ -29,18 +29,17 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/monitors/${params.monitorId}/run`; const query = new URLSearchParams(); if (params.async !== undefined) query.set('async', String(params.async)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'POST', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/syncCollectionWithSpec.ts b/src/tools/syncCollectionWithSpec.ts index ca8fc88..b97e38e 100644 --- a/src/tools/syncCollectionWithSpec.ts +++ b/src/tools/syncCollectionWithSpec.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -24,18 +24,17 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionUid}/synchronizations`; const query = new URLSearchParams(); if (params.specId !== undefined) query.set('specId', String(params.specId)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'PUT', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/syncSpecWithCollection.ts b/src/tools/syncSpecWithCollection.ts index ac64b6d..d35d447 100644 --- a/src/tools/syncSpecWithCollection.ts +++ b/src/tools/syncSpecWithCollection.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -24,7 +24,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}/synchronizations`; @@ -32,11 +32,10 @@ export async function handler( if (params.collectionUid !== undefined) query.set('collectionUid', String(params.collectionUid)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'PUT', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/transferCollectionFolders.ts b/src/tools/transferCollectionFolders.ts index e860ac6..6a82f69 100644 --- a/src/tools/transferCollectionFolders.ts +++ b/src/tools/transferCollectionFolders.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -56,7 +56,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collection-folders-transfers`; @@ -67,13 +67,12 @@ export async function handler( if (params.mode !== undefined) bodyPayload.mode = params.mode; if (params.target !== undefined) bodyPayload.target = params.target; if (params.location !== undefined) bodyPayload.location = params.location; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/transferCollectionRequests.ts b/src/tools/transferCollectionRequests.ts index ad5a984..0f88131 100644 --- a/src/tools/transferCollectionRequests.ts +++ b/src/tools/transferCollectionRequests.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -56,7 +56,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collection-requests-transfers`; @@ -67,13 +67,12 @@ export async function handler( if (params.mode !== undefined) bodyPayload.mode = params.mode; if (params.target !== undefined) bodyPayload.target = params.target; if (params.location !== undefined) bodyPayload.location = params.location; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/transferCollectionResponses.ts b/src/tools/transferCollectionResponses.ts index bb99202..88e98a9 100644 --- a/src/tools/transferCollectionResponses.ts +++ b/src/tools/transferCollectionResponses.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -56,7 +56,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collection-responses-transfers`; @@ -67,13 +67,12 @@ export async function handler( if (params.mode !== undefined) bodyPayload.mode = params.mode; if (params.target !== undefined) bodyPayload.target = params.target; if (params.location !== undefined) bodyPayload.location = params.location; - const result = await fetchPostmanAPI(url, { - method: 'POST', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.post(url, options); return { content: [ { diff --git a/src/tools/unpublishDocumentation.ts b/src/tools/unpublishDocumentation.ts index 151ae2d..06571a0 100644 --- a/src/tools/unpublishDocumentation.ts +++ b/src/tools/unpublishDocumentation.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -23,17 +23,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/public-documentations`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/unpublishMock.ts b/src/tools/unpublishMock.ts index 0ff1c76..3c0feb2 100644 --- a/src/tools/unpublishMock.ts +++ b/src/tools/unpublishMock.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -21,17 +21,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/mocks/${params.mockId}/unpublish`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'DELETE', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.delete(url, options); return { content: [ { diff --git a/src/tools/updateApiCollectionComment.ts b/src/tools/updateApiCollectionComment.ts index 70f2717..6c40ae6 100644 --- a/src/tools/updateApiCollectionComment.ts +++ b/src/tools/updateApiCollectionComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -40,7 +40,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/apis/${params.apiId}/collections/${params.collectionId}/comments/${params.commentId}`; @@ -49,13 +49,12 @@ export async function handler( const bodyPayload: any = {}; if (params.body !== undefined) bodyPayload.body = params.body; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateCollectionComment.ts b/src/tools/updateCollectionComment.ts index 03ef04f..914d1c5 100644 --- a/src/tools/updateCollectionComment.ts +++ b/src/tools/updateCollectionComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -39,7 +39,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/comments/${params.commentId}`; @@ -48,13 +48,12 @@ export async function handler( const bodyPayload: any = {}; if (params.body !== undefined) bodyPayload.body = params.body; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateCollectionFolder.ts b/src/tools/updateCollectionFolder.ts index 8d36c4f..a04843c 100644 --- a/src/tools/updateCollectionFolder.ts +++ b/src/tools/updateCollectionFolder.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -26,7 +26,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/folders/${params.folderId}`; @@ -35,13 +35,12 @@ export async function handler( const bodyPayload: any = {}; if (params.name !== undefined) bodyPayload.name = params.name; if (params.description !== undefined) bodyPayload.description = params.description; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateCollectionRequest.ts b/src/tools/updateCollectionRequest.ts index d7ccd16..fa67949 100644 --- a/src/tools/updateCollectionRequest.ts +++ b/src/tools/updateCollectionRequest.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -45,7 +45,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/requests/${params.requestId}`; @@ -54,13 +54,12 @@ export async function handler( const bodyPayload: any = {}; if (params.name !== undefined) bodyPayload.name = params.name; if (params.method !== undefined) bodyPayload.method = params.method; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateCollectionResponse.ts b/src/tools/updateCollectionResponse.ts index 46d08fd..1bc867b 100644 --- a/src/tools/updateCollectionResponse.ts +++ b/src/tools/updateCollectionResponse.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -32,7 +32,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/responses/${params.responseId}`; @@ -41,13 +41,12 @@ export async function handler( const bodyPayload: any = {}; if (params.name !== undefined) bodyPayload.name = params.name; if (params.responseCode !== undefined) bodyPayload.responseCode = params.responseCode; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateCollectionTags.ts b/src/tools/updateCollectionTags.ts index f905781..9d9815a 100644 --- a/src/tools/updateCollectionTags.ts +++ b/src/tools/updateCollectionTags.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -39,7 +39,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/tags`; @@ -47,13 +47,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateFolderComment.ts b/src/tools/updateFolderComment.ts index 44d7410..b99293d 100644 --- a/src/tools/updateFolderComment.ts +++ b/src/tools/updateFolderComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -40,7 +40,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/folders/${params.folderId}/comments/${params.commentId}`; @@ -49,13 +49,12 @@ export async function handler( const bodyPayload: any = {}; if (params.body !== undefined) bodyPayload.body = params.body; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateMock.ts b/src/tools/updateMock.ts index 14498a8..566737a 100644 --- a/src/tools/updateMock.ts +++ b/src/tools/updateMock.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -47,7 +47,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/mocks/${params.mockId}`; @@ -55,13 +55,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.mock !== undefined) bodyPayload.mock = params.mock; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateMonitor.ts b/src/tools/updateMonitor.ts index 670e354..93bc209 100644 --- a/src/tools/updateMonitor.ts +++ b/src/tools/updateMonitor.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -36,6 +36,7 @@ export const parameters = z.object({ ) .optional(), }) + .describe("Information about the monitor's retry settings.") .optional(), options: z .object({ @@ -137,7 +138,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/monitors/${params.monitorId}`; @@ -145,13 +146,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.monitor !== undefined) bodyPayload.monitor = params.monitor; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updatePanElementOrFolder.ts b/src/tools/updatePanElementOrFolder.ts index 81a2c44..78e91bf 100644 --- a/src/tools/updatePanElementOrFolder.ts +++ b/src/tools/updatePanElementOrFolder.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI } from '../clients/postman.js'; +import { PostmanAPIClient } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -28,17 +28,16 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/network/private/${params.elementType}/${params.elementId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; - const result = await fetchPostmanAPI(url, { - method: 'PUT', - apiKey: extra.apiKey, + const options: any = { headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateRequestComment.ts b/src/tools/updateRequestComment.ts index 7fa03ec..a8cf850 100644 --- a/src/tools/updateRequestComment.ts +++ b/src/tools/updateRequestComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -40,7 +40,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/requests/${params.requestId}/comments/${params.commentId}`; @@ -49,13 +49,12 @@ export async function handler( const bodyPayload: any = {}; if (params.body !== undefined) bodyPayload.body = params.body; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateResponseComment.ts b/src/tools/updateResponseComment.ts index 26aca01..f295702 100644 --- a/src/tools/updateResponseComment.ts +++ b/src/tools/updateResponseComment.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -40,7 +40,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/collections/${params.collectionId}/responses/${params.responseId}/comments/${params.commentId}`; @@ -49,13 +49,12 @@ export async function handler( const bodyPayload: any = {}; if (params.body !== undefined) bodyPayload.body = params.body; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateSpecFile.ts b/src/tools/updateSpecFile.ts index 29b06f9..9546700 100644 --- a/src/tools/updateSpecFile.ts +++ b/src/tools/updateSpecFile.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -32,7 +32,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}/files/${params.filePath}`; @@ -42,13 +42,12 @@ export async function handler( if (params.name !== undefined) bodyPayload.name = params.name; if (params.type !== undefined) bodyPayload.type = params.type; if (params.content !== undefined) bodyPayload.content = params.content; - const result = await fetchPostmanAPI(url, { - method: 'PATCH', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.patch(url, options); return { content: [ { diff --git a/src/tools/updateSpecProperties.ts b/src/tools/updateSpecProperties.ts index 52e71dc..fc44785 100644 --- a/src/tools/updateSpecProperties.ts +++ b/src/tools/updateSpecProperties.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -22,7 +22,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/specs/${params.specId}`; @@ -30,13 +30,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.name !== undefined) bodyPayload.name = params.name; - const result = await fetchPostmanAPI(url, { - method: 'PATCH', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.patch(url, options); return { content: [ { diff --git a/src/tools/updateWorkspace.ts b/src/tools/updateWorkspace.ts index 7a9f1f1..5b4ad85 100644 --- a/src/tools/updateWorkspace.ts +++ b/src/tools/updateWorkspace.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -36,7 +36,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/workspaces/${params.workspaceId}`; @@ -44,13 +44,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.workspace !== undefined) bodyPayload.workspace = params.workspace; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateWorkspaceGlobalVariables.ts b/src/tools/updateWorkspaceGlobalVariables.ts index 743fc4e..c6f6274 100644 --- a/src/tools/updateWorkspaceGlobalVariables.ts +++ b/src/tools/updateWorkspaceGlobalVariables.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -25,6 +25,7 @@ export const parameters = z.object({ .optional(), value: z.string().describe("The variable's value.").optional(), enabled: z.boolean().describe('If true, the variable is enabled.').optional(), + description: z.string().max(512).describe("The variable's description.").optional(), }) .describe('Information about the global variable.') ) @@ -41,7 +42,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/workspaces/${params.workspaceId}/global-variables`; @@ -49,13 +50,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.values !== undefined) bodyPayload.values = params.values; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { diff --git a/src/tools/updateWorkspaceTags.ts b/src/tools/updateWorkspaceTags.ts index e2d0574..9b3ffcd 100644 --- a/src/tools/updateWorkspaceTags.ts +++ b/src/tools/updateWorkspaceTags.ts @@ -1,5 +1,5 @@ import { z } from 'zod'; -import { fetchPostmanAPI, ContentType } from '../clients/postman.js'; +import { PostmanAPIClient, ContentType } from '../clients/postman.js'; import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; function asMcpError(error: unknown): McpError { @@ -39,7 +39,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { apiKey: string; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } ): Promise<{ content: Array<{ type: string; text: string } & Record> }> { try { const endpoint = `/workspaces/${params.workspaceId}/tags`; @@ -47,13 +47,12 @@ export async function handler( const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; if (params.tags !== undefined) bodyPayload.tags = params.tags; - const result = await fetchPostmanAPI(url, { - method: 'PUT', + const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, - apiKey: extra.apiKey, headers: extra.headers, - }); + }; + const result = await extra.client.put(url, options); return { content: [ { From 863b4c9668e8f81b2ee9a3de991e96f8fee81184 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Diego=20Garc=C3=ADa?= Date: Thu, 11 Sep 2025 17:03:26 +0200 Subject: [PATCH 2/2] chore: v2.2.0 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index e194096..de2e8af 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@postman/postman-mcp-server", - "version": "2.1.4", + "version": "2.2.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@postman/postman-mcp-server", - "version": "2.1.4", + "version": "2.2.0", "license": "Apache-2.0", "dependencies": { "@apidevtools/swagger-parser": "^11.0.0", diff --git a/package.json b/package.json index 72f66d0..6db99f9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@postman/postman-mcp-server", - "version": "2.1.4", + "version": "2.2.0", "description": "A simple MCP server to operate on the Postman API", "main": "dist/src/index.js", "type": "module",