diff --git a/dist/src/clients/postman.js b/dist/src/clients/postman.js index eae9a5b..9d7c76c 100644 --- a/dist/src/clients/postman.js +++ b/dist/src/clients/postman.js @@ -1,5 +1,5 @@ import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; -import packageJson from '../../package.json' with { type: 'json' }; +import { USER_AGENT } from '../constants.js'; export var ContentType; (function (ContentType) { ContentType["Json"] = "application/json"; @@ -45,9 +45,7 @@ export class PostmanAPIClient { const contentType = options.contentType || ContentType.Json; const userAgentKey = Object.keys(options.headers ?? {}).find((key) => key.toLowerCase() === 'user-agent'); const userAgentValue = userAgentKey ? options.headers?.[userAgentKey] : undefined; - const userAgentHeader = userAgentValue - ? `${userAgentValue}/${packageJson.name}/${packageJson.version}` - : `${packageJson.name}/${packageJson.version}`; + const userAgentHeader = userAgentValue ? `${userAgentValue}/${USER_AGENT}` : USER_AGENT; const disallowed = new Set([ 'content-length', 'transfer-encoding', diff --git a/dist/src/constants.js b/dist/src/constants.js new file mode 100644 index 0000000..234f873 --- /dev/null +++ b/dist/src/constants.js @@ -0,0 +1,4 @@ +import packageJson from '../package.json' with { type: 'json' }; +export const SERVER_NAME = packageJson.name; +export const APP_VERSION = packageJson.version; +export const USER_AGENT = `${packageJson.name}/${packageJson.version}`; diff --git a/dist/src/index.js b/dist/src/index.js index d6c31f0..597b6a4 100755 --- a/dist/src/index.js +++ b/dist/src/index.js @@ -3,12 +3,12 @@ import dotenv from 'dotenv'; import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'; import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'; import { ErrorCode, isInitializeRequest, McpError, } from '@modelcontextprotocol/sdk/types.js'; -import packageJson from '../package.json' with { type: 'json' }; 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'; +import { SERVER_NAME, APP_VERSION } from './constants.js'; const SUPPORTED_REGIONS = { us: 'https://api.postman.com', eu: 'https://api.eu.postman.com', @@ -93,9 +93,6 @@ if (dotEnvOutput.error) { else { log('info', `Environment variables loaded: ${dotEnvOutput.parsed ? Object.keys(dotEnvOutput.parsed).length : 0} environment variables: ${Object.keys(dotEnvOutput.parsed || {}).join(', ')}`); } -const SERVER_NAME = packageJson.name; -const APP_VERSION = packageJson.version; -export const USER_AGENT = `${SERVER_NAME}/${APP_VERSION}`; let clientInfo = undefined; async function run() { const args = process.argv.slice(2); @@ -141,6 +138,10 @@ async function run() { process.exit(0); }); const client = new PostmanAPIClient(apiKey); + const serverContext = { + serverType: useFull ? 'full' : 'minimal', + availableTools: tools.map((t) => t.method), + }; log('info', 'Registering tools with McpServer'); for (const tool of tools) { server.tool(tool.method, tool.description, tool.parameters.shape, tool.annotations || {}, async (args, extra) => { @@ -154,6 +155,7 @@ async function run() { ...extra?.requestInfo?.headers, 'user-agent': clientInfo?.name, }, + serverContext, }); const durationMs = Date.now() - start; log('info', `Tool invocation completed: ${toolName} (${durationMs}ms)`, { diff --git a/dist/src/tools/createCollection.js b/dist/src/tools/createCollection.js index 48f973c..0a277a7 100644 --- a/dist/src/tools/createCollection.js +++ b/dist/src/tools/createCollection.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollection'; export const description = 'Creates a collection using the [Postman Collection v2.1.0 schema format](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).\n\n**Note:**\n\nIf you do not include the \\`workspace\\` query parameter, the system creates the collection in the oldest personal Internal workspace you own.\n'; export const parameters = z.object({ @@ -126,13 +122,13 @@ export const parameters = z.object({ 'edgegrid', ]) .describe('The authorization type.'), - noauth: z.any().optional(), + noauth: z.unknown().optional(), apikey: z .array(z .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -148,7 +144,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -164,7 +160,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -180,7 +176,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -196,7 +192,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -212,7 +208,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -228,7 +224,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -244,7 +240,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -260,7 +256,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -276,7 +272,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -339,7 +335,7 @@ export const parameters = z.object({ .describe('A list of x-www-form-encoded key/value pairs.') .optional(), formdata: z - .array(z.record(z.any()).and(z.union([ + .array(z.record(z.string(), z.unknown()).and(z.union([ z.object({ key: z.string().describe('The key value.').optional(), value: z.string().describe("The key's value.").optional(), @@ -357,7 +353,7 @@ export const parameters = z.object({ z.object({ key: z.string().describe('The key value.').optional(), src: z - .any() + .unknown() .superRefine((x, ctx) => { const schemas = [z.string().nullable(), z.array(z.string())]; const errors = schemas.reduce((errors, schema) => ((result) => result.error ? [...errors, result.error] : errors)(schema.safeParse(x)), []); @@ -407,7 +403,7 @@ export const parameters = z.object({ .describe('If the `mode` value is `graphql`, an object containing the GraphQL request information.') .optional(), options: z - .record(z.any()) + .record(z.string(), z.unknown()) .describe('Additional configurations and options set for various modes.') .optional(), }) @@ -416,6 +412,10 @@ export const parameters = z.object({ }) .describe('Information about the collection request.') .optional(), + response: z + .array(z.unknown().describe("Information about the request's response.")) + .describe("A list of the collection's responses.") + .optional(), protocolProfileBehavior: z .object({ strictSSL: z @@ -544,13 +544,13 @@ export const parameters = z.object({ 'edgegrid', ]) .describe('The authorization type.'), - noauth: z.any().optional(), + noauth: z.unknown().optional(), apikey: z .array(z .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -566,7 +566,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -582,7 +582,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -598,7 +598,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -614,7 +614,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -630,7 +630,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -646,7 +646,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -662,7 +662,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -678,7 +678,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -694,7 +694,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -783,16 +783,16 @@ export const annotations = { destructiveHint: false, idempotentHint: false, }; -export async function handler(params, extra) { +export async function handler(args, extra) { try { const endpoint = `/collections`; const query = new URLSearchParams(); - if (params.workspace !== undefined) - query.set('workspace', String(params.workspace)); + if (args.workspace !== undefined) + query.set('workspace', String(args.workspace)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload = {}; - if (params.collection !== undefined) - bodyPayload.collection = params.collection; + if (args.collection !== undefined) + bodyPayload.collection = args.collection; const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, diff --git a/dist/src/tools/createCollectionComment.js b/dist/src/tools/createCollectionComment.js index 6df5bf1..8f59b6b 100644 --- a/dist/src/tools/createCollectionComment.js +++ b/dist/src/tools/createCollectionComment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollectionComment'; export const description = 'Creates a comment on a collection. To create a reply on an existing comment, include the \\`threadId\\` property in the request body.\n\n**Note:**\n\nThis endpoint accepts a max of 10,000 characters.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/createCollectionFolder.js b/dist/src/tools/createCollectionFolder.js index 46e586d..1ef8b28 100644 --- a/dist/src/tools/createCollectionFolder.js +++ b/dist/src/tools/createCollectionFolder.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollectionFolder'; export const description = 'Creates a folder in a collection. For a complete list of properties, refer to the **Folder** entry in the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).\n\nYou can use this endpoint to to import requests and responses into a newly-created folder. To do this, include the \\`requests\\` field and the list of request objects in the request body. For more information, see the provided example.\n\n**Note:**\n\nIt is recommended that you pass the \\`name\\` property in the request body. If you do not, the system uses a null value. As a result, this creates a folder with a blank name.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/createCollectionFork.js b/dist/src/tools/createCollectionFork.js index 440c180..a85b354 100644 --- a/dist/src/tools/createCollectionFork.js +++ b/dist/src/tools/createCollectionFork.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollectionFork'; export const description = 'Creates a [fork](https://learning.postman.com/docs/collaborating-in-postman/version-control/#creating-a-fork) from an existing collection into a workspace.'; export const parameters = z.object({ diff --git a/dist/src/tools/createCollectionRequest.js b/dist/src/tools/createCollectionRequest.js index 9a6ccaf..5d986a6 100644 --- a/dist/src/tools/createCollectionRequest.js +++ b/dist/src/tools/createCollectionRequest.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollectionRequest'; export const description = 'Creates a request in a collection. For a complete list of properties, refer to the **Request** entry in the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).\n\n**Note:**\n\nIt is recommended that you pass the \\`name\\` property in the request body. If you do not, the system uses a null value. As a result, this creates a request with a blank name.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/createCollectionResponse.js b/dist/src/tools/createCollectionResponse.js index 1477483..3b01f23 100644 --- a/dist/src/tools/createCollectionResponse.js +++ b/dist/src/tools/createCollectionResponse.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollectionResponse'; export const description = 'Creates a request response in a collection. For a complete list of request body properties, refer to the **Response** entry in the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).\n\n**Note:**\n\nIt is recommended that you pass the \\`name\\` property in the request body. If you do not, the system uses a null value. As a result, this creates a response with a blank name.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/createEnvironment.js b/dist/src/tools/createEnvironment.js index e3ded37..a9dadb5 100644 --- a/dist/src/tools/createEnvironment.js +++ b/dist/src/tools/createEnvironment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createEnvironment'; export const description = 'Creates an environment.\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- If you do not include the \\`workspace\\` query parameter, the system creates the environment in the oldest personal Internal workspace you own.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/createFolderComment.js b/dist/src/tools/createFolderComment.js index 1cbf53f..20ece27 100644 --- a/dist/src/tools/createFolderComment.js +++ b/dist/src/tools/createFolderComment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createFolderComment'; export const description = 'Creates a comment on a folder. To create a reply on an existing comment, include the \\`threadId\\` property in the request body.\n\n**Note:**\n\nThis endpoint accepts a max of 10,000 characters.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/createMock.js b/dist/src/tools/createMock.js index b9865cb..2090189 100644 --- a/dist/src/tools/createMock.js +++ b/dist/src/tools/createMock.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createMock'; export const description = 'Creates a mock server in a collection.\n\n- Pass the collection UID (ownerId-collectionId), not the bare collection ID.\n- If you only have a \\`collectionId\\`, resolve the UID first:\n 1) Prefer GET \\`/collections/{collectionId}\\` and read \\`uid\\`, or\n 2) Construct \\`{ownerId}-{collectionId}\\` using ownerId from GET \\`/me\\`:\n - For team-owned collections: \\`ownerId = me.teamId\\`\n - For personal collections: \\`ownerId = me.user.id\\`\n- Use the \\`workspace\\` query to place the mock in a specific workspace. Prefer explicit workspace scoping.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/createMonitor.js b/dist/src/tools/createMonitor.js index a79f6ee..1e84d95 100644 --- a/dist/src/tools/createMonitor.js +++ b/dist/src/tools/createMonitor.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createMonitor'; export const description = 'Creates a monitor.\n\n**Note:**\n\n- You cannot create monitors for collections added to an API definition.\n- If you do not pass the \\`workspace\\` query parameter, the system creates the monitor in the oldest personal Internal workspace you own.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/createRequestComment.js b/dist/src/tools/createRequestComment.js index 0c91a6b..8a5dae6 100644 --- a/dist/src/tools/createRequestComment.js +++ b/dist/src/tools/createRequestComment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createRequestComment'; export const description = "The request ID must contain the team ID as a prefix, in \\`teamId-requestId\\` format.\n\nFor example, if you're creating a comment on collection ID \\`24585957-7b2c98f7-30db-4b67-8685-0079f48a0947\\` (note on the prefix), and\nthe collection request's ID is \\`2c450b59-9bbf-729b-6ac0-f92535a7c336\\`, then the \\`{requestId}\\` must be \\`24585957-2c450b59-9bbf-729b-6ac0-f92535a7c336\\`.\n"; export const parameters = z.object({ diff --git a/dist/src/tools/createResponseComment.js b/dist/src/tools/createResponseComment.js index e367ce4..3244848 100644 --- a/dist/src/tools/createResponseComment.js +++ b/dist/src/tools/createResponseComment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createResponseComment'; export const description = 'Creates a comment on a response. To create a reply on an existing comment, include the \\`threadId\\` property in the request body.\n\n**Note:**\n\nThis endpoint accepts a max of 10,000 characters.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/createSpec.js b/dist/src/tools/createSpec.js index e9a9738..df4b839 100644 --- a/dist/src/tools/createSpec.js +++ b/dist/src/tools/createSpec.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createSpec'; export const description = "Creates an API specification in Postman's [Spec Hub](https://learning.postman.com/docs/design-apis/specifications/overview/). Specifications can be single or multi-file.\n\n**Note:**\n- Postman supports OpenAPI 3.0 and AsyncAPI 2.0 specifications.\n- If the file path contains a \\`/\\` (forward slash) character, then a folder is created. For example, if the path is the \\`components/schemas.json\\` value, then a \\`components\\` folder is created with the \\`schemas.json\\` file inside.\n- Multi-file specifications can only have one root file.\n- Files cannot exceed a maximum of 10 MB in size.\n"; export const parameters = z.object({ diff --git a/dist/src/tools/createSpecFile.js b/dist/src/tools/createSpecFile.js index 4ff65bc..1e864fe 100644 --- a/dist/src/tools/createSpecFile.js +++ b/dist/src/tools/createSpecFile.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createSpecFile'; export const description = 'Creates an API specification file.\n\n**Note:**\n\n- If the file path contains a \\`/\\` (forward slash) character, then a folder is created. For example, if the path is the \\`components/schemas.json\\` value, then a \\`components\\` folder is created with the \\`schemas.json\\` file inside.\n- Creating a spec file assigns it the \\`DEFAULT\\` file type.\n- Multi-file specifications can only have one root file.\n- Files cannot exceed a maximum of 10 MB in size.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/createWorkspace.js b/dist/src/tools/createWorkspace.js index f305f9a..f0fbfe7 100644 --- a/dist/src/tools/createWorkspace.js +++ b/dist/src/tools/createWorkspace.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createWorkspace'; export const description = 'Creates a new [workspace](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/creating-workspaces/).\n\n**Note:**\n\n- This endpoint returns a 403 \\`Forbidden\\` response if the user does not have permission to create workspaces. [Admins and Super Admins](https://learning.postman.com/docs/collaborating-in-postman/roles-and-permissions/#team-roles) can configure workspace permissions to restrict users and/or user groups from creating workspaces or require approvals for the creation of team workspaces.\n- There are rate limits when publishing public workspaces.\n- Public team workspace names must be unique.\n\n### Important\n\nWe deprecated linking collections or environments between workspaces. We do not recommend that you do this.\n\nIf you have a linked collection or environment, note the following:\n- The endpoint does not create a clone of a collection or environment.\n- Any changes you make to a linked collection or environment changes them in all workspaces.\n- If you delete a collection or environment linked between workspaces, the system deletes it in all the workspaces.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/deleteApiCollectionComment.js b/dist/src/tools/deleteApiCollectionComment.js index ace59c0..8cb033c 100644 --- a/dist/src/tools/deleteApiCollectionComment.js +++ b/dist/src/tools/deleteApiCollectionComment.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteApiCollectionComment'; export const description = "Deletes a comment from an API's collection. On success, this returns an HTTP \\`204 No Content\\` response.\n\n**Note:**\n\nDeleting the first comment of a thread deletes all the comments in the thread.\n"; export const parameters = z.object({ diff --git a/dist/src/tools/deleteCollection.js b/dist/src/tools/deleteCollection.js index db944f3..0bc0008 100644 --- a/dist/src/tools/deleteCollection.js +++ b/dist/src/tools/deleteCollection.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteCollection'; export const description = 'Deletes a collection.'; export const parameters = z.object({ diff --git a/dist/src/tools/deleteCollectionComment.js b/dist/src/tools/deleteCollectionComment.js index 64399a4..abc6c7f 100644 --- a/dist/src/tools/deleteCollectionComment.js +++ b/dist/src/tools/deleteCollectionComment.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteCollectionComment'; export const description = 'Deletes a comment from a collection. On success, this returns an HTTP \\`204 No Content\\` response.\n\n**Note:**\n\nDeleting the first comment of a thread deletes all the comments in the thread.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/deleteCollectionFolder.js b/dist/src/tools/deleteCollectionFolder.js index 84b9004..5f4d960 100644 --- a/dist/src/tools/deleteCollectionFolder.js +++ b/dist/src/tools/deleteCollectionFolder.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteCollectionFolder'; export const description = 'Deletes a folder in a collection.'; export const parameters = z.object({ diff --git a/dist/src/tools/deleteCollectionRequest.js b/dist/src/tools/deleteCollectionRequest.js index e291f74..92696ad 100644 --- a/dist/src/tools/deleteCollectionRequest.js +++ b/dist/src/tools/deleteCollectionRequest.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteCollectionRequest'; export const description = 'Deletes a request in a collection.'; export const parameters = z.object({ diff --git a/dist/src/tools/deleteCollectionResponse.js b/dist/src/tools/deleteCollectionResponse.js index 51e8a02..0fc9927 100644 --- a/dist/src/tools/deleteCollectionResponse.js +++ b/dist/src/tools/deleteCollectionResponse.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteCollectionResponse'; export const description = 'Deletes a response in a collection.'; export const parameters = z.object({ diff --git a/dist/src/tools/deleteEnvironment.js b/dist/src/tools/deleteEnvironment.js index f09ffb3..456dd8b 100644 --- a/dist/src/tools/deleteEnvironment.js +++ b/dist/src/tools/deleteEnvironment.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteEnvironment'; export const description = 'Deletes an environment.'; export const parameters = z.object({ environmentId: z.string().describe("The environment's ID.") }); diff --git a/dist/src/tools/deleteFolderComment.js b/dist/src/tools/deleteFolderComment.js index 7391f5e..4bcdf60 100644 --- a/dist/src/tools/deleteFolderComment.js +++ b/dist/src/tools/deleteFolderComment.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteFolderComment'; export const description = 'Deletes a comment from a folder. On success, this returns an HTTP \\`204 No Content\\` response.\n\n**Note:**\n\nDeleting the first comment of a thread deletes all the comments in the thread.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/deleteMock.js b/dist/src/tools/deleteMock.js index 864d2ff..423f39a 100644 --- a/dist/src/tools/deleteMock.js +++ b/dist/src/tools/deleteMock.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteMock'; export const description = 'Deletes a mock server.\n- Resource: Mock server entity. This is destructive.\n- Ensure you are targeting the correct mock ID.\n'; export const parameters = z.object({ mockId: z.string().describe("The mock's ID.") }); diff --git a/dist/src/tools/deleteMonitor.js b/dist/src/tools/deleteMonitor.js index 3c361da..795efe6 100644 --- a/dist/src/tools/deleteMonitor.js +++ b/dist/src/tools/deleteMonitor.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteMonitor'; export const description = 'Deletes a monitor.'; export const parameters = z.object({ monitorId: z.string().describe("The monitor's ID.") }); diff --git a/dist/src/tools/deletePanElementOrFolder.js b/dist/src/tools/deletePanElementOrFolder.js index c90cf2f..5c1816a 100644 --- a/dist/src/tools/deletePanElementOrFolder.js +++ b/dist/src/tools/deletePanElementOrFolder.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deletePanElementOrFolder'; export const description = "Removes an element or delete a folder from your team's [Private API Network](https://learning.postman.com/docs/collaborating-in-postman/adding-private-network/).\n\n**Note:**\n\nRemoving an API, collection, or workspace element does not delete it. It only removes it from the Private API Network folder.\n"; export const parameters = z.object({ diff --git a/dist/src/tools/deleteRequestComment.js b/dist/src/tools/deleteRequestComment.js index b1e9ed6..81e582c 100644 --- a/dist/src/tools/deleteRequestComment.js +++ b/dist/src/tools/deleteRequestComment.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteRequestComment'; export const description = 'Deletes a comment from a request. On success, this returns an HTTP \\`204 No Content\\` response.\n\n**Note:**\n\nDeleting the first comment of a thread deletes all the comments in the thread.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/deleteResponseComment.js b/dist/src/tools/deleteResponseComment.js index c666690..3d4e113 100644 --- a/dist/src/tools/deleteResponseComment.js +++ b/dist/src/tools/deleteResponseComment.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteResponseComment'; export const description = 'Deletes a comment from a response. On success, this returns an HTTP \\`204 No Content\\` response.\n\n**Note:**\n\nDeleting the first comment of a thread deletes all the comments in the thread.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/deleteSpec.js b/dist/src/tools/deleteSpec.js index b4a3bdd..54174bf 100644 --- a/dist/src/tools/deleteSpec.js +++ b/dist/src/tools/deleteSpec.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteSpec'; export const description = 'Deletes an API specification. On success, this returns an HTTP \\`204 No Content\\` response.'; export const parameters = z.object({ specId: z.string().describe("The spec's ID.") }); diff --git a/dist/src/tools/deleteSpecFile.js b/dist/src/tools/deleteSpecFile.js index 0d439b5..c4e8b2b 100644 --- a/dist/src/tools/deleteSpecFile.js +++ b/dist/src/tools/deleteSpecFile.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteSpecFile'; export const description = 'Deletes a file in an API specification. On success, this returns an HTTP \\`204 No Content\\` response.'; export const parameters = z.object({ diff --git a/dist/src/tools/deleteWorkspace.js b/dist/src/tools/deleteWorkspace.js index b986548..50387aa 100644 --- a/dist/src/tools/deleteWorkspace.js +++ b/dist/src/tools/deleteWorkspace.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteWorkspace'; export const description = 'Deletes an existing workspace.\n\n### Important\n\nIf you delete a workspace that has a linked collection or environment with another workspace, this will delete the collection and environment in all workspaces.\n'; export const parameters = z.object({ workspaceId: z.string().describe("The workspace's ID.") }); diff --git a/dist/src/tools/duplicateCollection.js b/dist/src/tools/duplicateCollection.js index 80a73c2..b194225 100644 --- a/dist/src/tools/duplicateCollection.js +++ b/dist/src/tools/duplicateCollection.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'duplicateCollection'; export const description = "Creates a duplicate of the given collection in another workspace.\n\nUse the GET \\`/collection-duplicate-tasks/{taskId}\\` endpoint to get the duplication task's current status.\n"; export const parameters = z.object({ diff --git a/dist/src/tools/generateCollection.js b/dist/src/tools/generateCollection.js index 6268615..acd6899 100644 --- a/dist/src/tools/generateCollection.js +++ b/dist/src/tools/generateCollection.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'generateCollection'; export const description = 'Creates a collection from the given API specification.\nThe specification must already exist or be created before it can be used to generate a collection.\nThe response contains a polling link to the task status.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/generateSpecFromCollection.js b/dist/src/tools/generateSpecFromCollection.js index ac4a34b..0ae4fa6 100644 --- a/dist/src/tools/generateSpecFromCollection.js +++ b/dist/src/tools/generateSpecFromCollection.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'generateSpecFromCollection'; export const description = 'Generates an API specification for the given collection. The response contains a polling link to the task status.'; export const parameters = z.object({ diff --git a/dist/src/tools/getAllElementsAndFolders.js b/dist/src/tools/getAllElementsAndFolders.js index d328ff9..f8d117d 100644 --- a/dist/src/tools/getAllElementsAndFolders.js +++ b/dist/src/tools/getAllElementsAndFolders.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getAllElementsAndFolders'; export const description = "Gets information about the folders and their elements added to your team's [Private API Network](https://learning.postman.com/docs/collaborating-in-postman/adding-private-network/).\n\n**Note:**\n\nThe \\`limit\\` and \\`offset\\` parameters are separately applied to elements and folders. For example, if you query a \\`limit\\` value of \\`10\\` and an \\`offset\\` value \\`0\\`, the endpoint returns 10 elements and 10 folders for a total of 20 items. The \\`totalCount\\` property in the \\`meta\\` response is the total count of both elements and folders.\n"; export const parameters = z.object({ diff --git a/dist/src/tools/getAllPanAddElementRequests.js b/dist/src/tools/getAllPanAddElementRequests.js index 6e65632..444cd41 100644 --- a/dist/src/tools/getAllPanAddElementRequests.js +++ b/dist/src/tools/getAllPanAddElementRequests.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getAllPanAddElementRequests'; export const description = "Gets a list requests to add elements to your team's [Private API Network](https://learning.postman.com/docs/collaborating-in-postman/adding-private-network/)."; export const parameters = z.object({ diff --git a/dist/src/tools/getAllSpecs.js b/dist/src/tools/getAllSpecs.js index 037089a..daf121f 100644 --- a/dist/src/tools/getAllSpecs.js +++ b/dist/src/tools/getAllSpecs.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getAllSpecs'; export const description = 'Gets all API specifications in a workspace.'; export const parameters = z.object({ diff --git a/dist/src/tools/getAsyncSpecTaskStatus.js b/dist/src/tools/getAsyncSpecTaskStatus.js index 8ad0e56..e1a225e 100644 --- a/dist/src/tools/getAsyncSpecTaskStatus.js +++ b/dist/src/tools/getAsyncSpecTaskStatus.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getAsyncSpecTaskStatus'; export const description = 'Gets the status of an asynchronous API specification creation task.'; export const parameters = z.object({ diff --git a/dist/src/tools/getAuthenticatedUser.js b/dist/src/tools/getAuthenticatedUser.js index 89d1b6e..aaa1875 100644 --- a/dist/src/tools/getAuthenticatedUser.js +++ b/dist/src/tools/getAuthenticatedUser.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getAuthenticatedUser'; export const description = 'Gets information about the authenticated user.\n- This endpoint provides “current user” context (\\`user.id\\`, \\`username\\`, \\`teamId\\`, roles).\n- When a user asks for “my …” (e.g., “my workspaces, my information, etc.”), call this first to resolve the user ID.\n'; export const parameters = z.object({}); diff --git a/dist/src/tools/getCollection.js b/dist/src/tools/getCollection.js index e12f004..e787c9e 100644 --- a/dist/src/tools/getCollection.js +++ b/dist/src/tools/getCollection.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollection'; export const description = "Gets information about a collection. For a complete list of this endpoint's possible values, refer to the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html)."; export const parameters = z.object({ diff --git a/dist/src/tools/getCollectionComments.js b/dist/src/tools/getCollectionComments.js index f1ea692..264566c 100644 --- a/dist/src/tools/getCollectionComments.js +++ b/dist/src/tools/getCollectionComments.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionComments'; export const description = 'Gets all comments left by users in a collection.'; export const parameters = z.object({ diff --git a/dist/src/tools/getCollectionFolder.js b/dist/src/tools/getCollectionFolder.js index 5dc4c1f..4d23a74 100644 --- a/dist/src/tools/getCollectionFolder.js +++ b/dist/src/tools/getCollectionFolder.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionFolder'; export const description = 'Gets information about a folder in a collection.'; export const parameters = z.object({ diff --git a/dist/src/tools/getCollectionForks.js b/dist/src/tools/getCollectionForks.js index 48943a1..c3f34ab 100644 --- a/dist/src/tools/getCollectionForks.js +++ b/dist/src/tools/getCollectionForks.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionForks'; export const description = "Gets a collection's forked collections. The response returns data for each fork, such as the fork's ID, the user who forked it, and the fork's creation date."; export const parameters = z.object({ diff --git a/dist/src/tools/getCollectionRequest.js b/dist/src/tools/getCollectionRequest.js index 6ce2622..4125fe5 100644 --- a/dist/src/tools/getCollectionRequest.js +++ b/dist/src/tools/getCollectionRequest.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionRequest'; export const description = 'Gets information about a request in a collection.'; export const parameters = z.object({ diff --git a/dist/src/tools/getCollectionResponse.js b/dist/src/tools/getCollectionResponse.js index f266664..58a20ca 100644 --- a/dist/src/tools/getCollectionResponse.js +++ b/dist/src/tools/getCollectionResponse.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionResponse'; export const description = 'Gets information about a response in a collection.'; export const parameters = z.object({ diff --git a/dist/src/tools/getCollectionTags.js b/dist/src/tools/getCollectionTags.js index d31b47c..8cc4c50 100644 --- a/dist/src/tools/getCollectionTags.js +++ b/dist/src/tools/getCollectionTags.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionTags'; export const description = 'Gets all the tags associated with a collection.'; export const parameters = z.object({ diff --git a/dist/src/tools/getCollectionUpdatesTasks.js b/dist/src/tools/getCollectionUpdatesTasks.js index 59af186..bfb9947 100644 --- a/dist/src/tools/getCollectionUpdatesTasks.js +++ b/dist/src/tools/getCollectionUpdatesTasks.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionUpdatesTasks'; export const description = 'Gets the status of an asynchronous collection update task.'; export const parameters = z.object({ taskId: z.string().describe("The task's ID.") }); diff --git a/dist/src/tools/getCollections.js b/dist/src/tools/getCollections.js index 0adef41..9c58c1d 100644 --- a/dist/src/tools/getCollections.js +++ b/dist/src/tools/getCollections.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollections'; export const description = 'The workspace ID query is required for this endpoint. If not provided, the LLM should ask the user to provide it.'; export const parameters = z.object({ diff --git a/dist/src/tools/getCollectionsForkedByUser.js b/dist/src/tools/getCollectionsForkedByUser.js index a40b679..6333b18 100644 --- a/dist/src/tools/getCollectionsForkedByUser.js +++ b/dist/src/tools/getCollectionsForkedByUser.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionsForkedByUser'; export const description = "Gets a list of all the authenticated user's forked collections."; export const parameters = z.object({ diff --git a/dist/src/tools/getDuplicateCollectionTaskStatus.js b/dist/src/tools/getDuplicateCollectionTaskStatus.js index 2902e36..938304e 100644 --- a/dist/src/tools/getDuplicateCollectionTaskStatus.js +++ b/dist/src/tools/getDuplicateCollectionTaskStatus.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getDuplicateCollectionTaskStatus'; export const description = 'Gets the status of a collection duplication task.'; export const parameters = z.object({ taskId: z.string().describe("The task's unique ID.") }); diff --git a/dist/src/tools/getEnabledTools.js b/dist/src/tools/getEnabledTools.js new file mode 100644 index 0000000..5292766 --- /dev/null +++ b/dist/src/tools/getEnabledTools.js @@ -0,0 +1,51 @@ +import { z } from 'zod'; +import { enabledResources } from '../enabledResources.js'; +import { asMcpError, McpError } from './utils/toolHelpers.js'; +export const method = 'getEnabledTools'; +export const description = 'IMPORTANT: Run this tool first when a requested tool is unavailable. Returns information about which tools are enabled in the full and minimal tool sets, helping you identify available alternatives.'; +export const parameters = z.object({}); +export const annotations = { + title: 'Get Enabled Tools', + readOnlyHint: true, + destructiveHint: false, + idempotentHint: true, +}; +export async function handler(_args, extra) { + try { + return { + content: [ + { + type: 'text', + text: JSON.stringify({ + serverInfo: extra.serverContext + ? { + serverType: extra.serverContext.serverType, + currentServerTools: extra.serverContext.availableTools, + currentServerToolCount: extra.serverContext.availableTools.length, + } + : { + serverType: 'unknown', + note: 'Server context not available', + }, + enabledTools: { + full: Array.from(enabledResources.full), + minimal: Array.from(enabledResources.minimal), + excludedFromGeneration: Array.from(enabledResources.excludedFromGeneration), + }, + stats: { + totalFull: enabledResources.full.length, + totalMinimal: enabledResources.minimal.length, + totalExcludedFromGeneration: enabledResources.excludedFromGeneration.length, + }, + }, null, 2), + }, + ], + }; + } + catch (e) { + if (e instanceof McpError) { + throw e; + } + throw asMcpError(e); + } +} diff --git a/dist/src/tools/getEnvironment.js b/dist/src/tools/getEnvironment.js index f8bbec3..7a21583 100644 --- a/dist/src/tools/getEnvironment.js +++ b/dist/src/tools/getEnvironment.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getEnvironment'; export const description = 'Gets information about an environment.'; export const parameters = z.object({ environmentId: z.string().describe("The environment's ID.") }); diff --git a/dist/src/tools/getEnvironments.js b/dist/src/tools/getEnvironments.js index b5f174d..dc3c975 100644 --- a/dist/src/tools/getEnvironments.js +++ b/dist/src/tools/getEnvironments.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getEnvironments'; export const description = 'Gets information about all of your [environments](https://learning.postman.com/docs/sending-requests/managing-environments/).'; export const parameters = z.object({ diff --git a/dist/src/tools/getFolderComments.js b/dist/src/tools/getFolderComments.js index 175e202..b2c75c4 100644 --- a/dist/src/tools/getFolderComments.js +++ b/dist/src/tools/getFolderComments.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getFolderComments'; export const description = 'Gets all comments left by users in a folder.'; export const parameters = z.object({ diff --git a/dist/src/tools/getGeneratedCollectionSpecs.js b/dist/src/tools/getGeneratedCollectionSpecs.js index 2256ce0..9f7eaa5 100644 --- a/dist/src/tools/getGeneratedCollectionSpecs.js +++ b/dist/src/tools/getGeneratedCollectionSpecs.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getGeneratedCollectionSpecs'; export const description = 'Gets the API specification generated for the given collection.'; export const parameters = z.object({ diff --git a/dist/src/tools/getMock.js b/dist/src/tools/getMock.js index 518cde9..b7037bf 100644 --- a/dist/src/tools/getMock.js +++ b/dist/src/tools/getMock.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getMock'; export const description = 'Gets information about a mock server.\n- Resource: Mock server entity. Response includes the associated \\`collection\\` UID and \\`mockUrl\\`.\n- Use the \\`collection\\` UID to navigate back to the source collection.\n'; export const parameters = z.object({ mockId: z.string().describe("The mock's ID.") }); diff --git a/dist/src/tools/getMocks.js b/dist/src/tools/getMocks.js index f637603..c739147 100644 --- a/dist/src/tools/getMocks.js +++ b/dist/src/tools/getMocks.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getMocks'; export const description = 'Gets all active mock servers. By default, returns only mock servers you created across all workspaces.\n\n- Always pass either the \\`workspace\\` or \\`teamId\\` query to scope results. Prefer \\`workspace\\` when known.\n- If you need team-scoped results, set \\`teamId\\` from the current user: call GET \\`/me\\` and use \\`me.teamId\\`.\n- If both \\`teamId\\` and \\`workspace\\` are passed, only \\`workspace\\` is used.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/getMonitor.js b/dist/src/tools/getMonitor.js index a948472..202ae97 100644 --- a/dist/src/tools/getMonitor.js +++ b/dist/src/tools/getMonitor.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getMonitor'; export const description = 'Gets information about a monitor.'; export const parameters = z.object({ monitorId: z.string().describe("The monitor's ID.") }); diff --git a/dist/src/tools/getMonitors.js b/dist/src/tools/getMonitors.js index f8688d8..06fa968 100644 --- a/dist/src/tools/getMonitors.js +++ b/dist/src/tools/getMonitors.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getMonitors'; export const description = 'Gets all monitors.'; export const parameters = z.object({ diff --git a/dist/src/tools/getRequestComments.js b/dist/src/tools/getRequestComments.js index 0e6c430..2b4f81a 100644 --- a/dist/src/tools/getRequestComments.js +++ b/dist/src/tools/getRequestComments.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getRequestComments'; export const description = 'Gets all comments left by users in a request.'; export const parameters = z.object({ diff --git a/dist/src/tools/getResponseComments.js b/dist/src/tools/getResponseComments.js index 153a172..6808877 100644 --- a/dist/src/tools/getResponseComments.js +++ b/dist/src/tools/getResponseComments.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getResponseComments'; export const description = 'Gets all comments left by users in a response.'; export const parameters = z.object({ diff --git a/dist/src/tools/getSourceCollectionStatus.js b/dist/src/tools/getSourceCollectionStatus.js index 330baa0..bd27001 100644 --- a/dist/src/tools/getSourceCollectionStatus.js +++ b/dist/src/tools/getSourceCollectionStatus.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSourceCollectionStatus'; export const description = 'Checks whether there is a change between the forked collection and its parent (source) collection.\n\nIf the value of the \\`isSourceAhead\\` property is \\`true\\` in the response, then there is a difference between the forked collection and its source collection.\n\n**Note:**\n\nThis endpoint may take a few minutes to return an updated \\`isSourceAhead\\` status.\n'; export const parameters = z.object({ collectionId: z.string().describe("The collection's ID.") }); diff --git a/dist/src/tools/getSpec.js b/dist/src/tools/getSpec.js index 20d650f..0b97128 100644 --- a/dist/src/tools/getSpec.js +++ b/dist/src/tools/getSpec.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSpec'; export const description = 'Gets information about an API specification.'; export const parameters = z.object({ specId: z.string().describe("The spec's ID.") }); diff --git a/dist/src/tools/getSpecCollections.js b/dist/src/tools/getSpecCollections.js index fa9b7fa..63c7487 100644 --- a/dist/src/tools/getSpecCollections.js +++ b/dist/src/tools/getSpecCollections.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSpecCollections'; export const description = "Gets all of an API specification's generated collections."; export const parameters = z.object({ diff --git a/dist/src/tools/getSpecDefinition.js b/dist/src/tools/getSpecDefinition.js index cc65ebe..87bbf9d 100644 --- a/dist/src/tools/getSpecDefinition.js +++ b/dist/src/tools/getSpecDefinition.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSpecDefinition'; export const description = "Gets the complete contents of an API specification's definition."; export const parameters = z.object({ specId: z.string().describe("The spec's ID.") }); diff --git a/dist/src/tools/getSpecFile.js b/dist/src/tools/getSpecFile.js index f7a3870..129bf39 100644 --- a/dist/src/tools/getSpecFile.js +++ b/dist/src/tools/getSpecFile.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSpecFile'; export const description = "Gets the contents of an API specification's file."; export const parameters = z.object({ diff --git a/dist/src/tools/getSpecFiles.js b/dist/src/tools/getSpecFiles.js index 72c11a0..fbc03b0 100644 --- a/dist/src/tools/getSpecFiles.js +++ b/dist/src/tools/getSpecFiles.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSpecFiles'; export const description = 'Gets all the files in an API specification.'; export const parameters = z.object({ specId: z.string().describe("The spec's ID.") }); diff --git a/dist/src/tools/getStatusOfAnAsyncApiTask.js b/dist/src/tools/getStatusOfAnAsyncApiTask.js index b44356b..2861be7 100644 --- a/dist/src/tools/getStatusOfAnAsyncApiTask.js +++ b/dist/src/tools/getStatusOfAnAsyncApiTask.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getStatusOfAnAsyncApiTask'; export const description = 'Gets the status of an asynchronous task.'; export const parameters = z.object({ diff --git a/dist/src/tools/getTaggedEntities.js b/dist/src/tools/getTaggedEntities.js index c3d46b5..868e805 100644 --- a/dist/src/tools/getTaggedEntities.js +++ b/dist/src/tools/getTaggedEntities.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getTaggedEntities'; export const description = 'Gets Postman elements (entities) by a given tag. Tags enable you to organize and search [workspaces](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/managing-workspaces/#tagging-a-workspace), [APIs](https://learning.postman.com/docs/designing-and-developing-your-api/managing-apis/#tagging-apis), and [collections](https://learning.postman.com/docs/collections/using-collections/#tagging-a-collection) that contain shared tags.\n\n**Note:**\n\nTagging is available on Postman [**Enterprise** plans](https://www.postman.com/pricing/).\n'; export const parameters = z.object({ diff --git a/dist/src/tools/getWorkspace.js b/dist/src/tools/getWorkspace.js index bc3eacd..7df143b 100644 --- a/dist/src/tools/getWorkspace.js +++ b/dist/src/tools/getWorkspace.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getWorkspace'; export const description = "Gets information about a workspace.\n\n**Note:**\n\nThis endpoint's response contains the \\`visibility\\` field. [Visibility](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/managing-workspaces/#changing-workspace-visibility) determines who can access the workspace:\n- \\`personal\\` — Only you can access the workspace.\n- \\`team\\` — All team members can access the workspace.\n- \\`private\\` — Only invited team members can access the workspace ([**Professional** and **Enterprise** plans only](https://www.postman.com/pricing)).\n- \\`public\\` — Everyone can access the workspace.\n- \\`partner\\` — Only invited team members and [partners](https://learning.postman.com/docs/collaborating-in-postman/using-workspaces/partner-workspaces/) can access the workspace ([**Professional** and **Enterprise** plans only](https://www.postman.com/pricing)).\n\n### Important\n\nWe have deprecated the \\`name\\` and \\`uid\\` responses in the following array of objects:\n- \\`collections\\`\n- \\`environments\\`\n- \\`mocks\\`\n- \\`monitors\\`\n- \\`apis\\`\n"; export const parameters = z.object({ diff --git a/dist/src/tools/getWorkspaceGlobalVariables.js b/dist/src/tools/getWorkspaceGlobalVariables.js index 473f53e..10953b1 100644 --- a/dist/src/tools/getWorkspaceGlobalVariables.js +++ b/dist/src/tools/getWorkspaceGlobalVariables.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getWorkspaceGlobalVariables'; export const description = "Gets a workspace's global [variables](https://learning.postman.com/docs/sending-requests/variables/#variable-scopes). Global variables enable you to access data between collections, requests, scripts, and environments and are available throughout a workspace."; export const parameters = z.object({ workspaceId: z.string().describe("The workspace's ID.") }); diff --git a/dist/src/tools/getWorkspaceTags.js b/dist/src/tools/getWorkspaceTags.js index 4cf844d..013983f 100644 --- a/dist/src/tools/getWorkspaceTags.js +++ b/dist/src/tools/getWorkspaceTags.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getWorkspaceTags'; export const description = 'Gets all the tags associated with a workspace.'; export const parameters = z.object({ workspaceId: z.string().describe("The workspace's ID.") }); diff --git a/dist/src/tools/getWorkspaces.js b/dist/src/tools/getWorkspaces.js index caea1f6..f1ac72c 100644 --- a/dist/src/tools/getWorkspaces.js +++ b/dist/src/tools/getWorkspaces.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getWorkspaces'; export const description = "Gets all workspaces you have access to.\n- For “my …” requests, first call GET \\`/me\\` and pass \\`createdBy={me.user.id}\\`.\n- This endpoint's response contains the visibility field. Visibility determines who can access the workspace:\n - \\`personal\\` — Only you can access the workspace.\n - \\`team\\` — All team members can access the workspace.\n - \\`private\\` — Only invited team members can access the workspace (Professional and Enterprise).\n - \\`public\\` — Everyone can access the workspace.\n - \\`partner\\` — Invited team members and partners (Professional and Enterprise).\n- For tools that require the workspace ID, and no workspace ID is provided, ask the user to provide the workspace ID. If the user does not provide the workspace ID, call this first with the createdBy parameter to use the first workspace.\n- Examples:\n - “List my workspaces” → GET \\`/me\\`, then GET \\`/workspaces?createdBy={me.user.id}\\`\n - “List my personal workspaces” → GET \\`/me\\`, then GET \\`/workspaces?type=personal&createdBy={me.user.id}\\`\n - “List all public workspaces” → GET \\`/workspaces?type=public\\`\n"; export const parameters = z.object({ diff --git a/dist/src/tools/mergeCollectionFork.js b/dist/src/tools/mergeCollectionFork.js index 59cf83e..fa8a72d 100644 --- a/dist/src/tools/mergeCollectionFork.js +++ b/dist/src/tools/mergeCollectionFork.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; 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({ diff --git a/dist/src/tools/patchCollection.js b/dist/src/tools/patchCollection.js index e911b2f..855d8ac 100644 --- a/dist/src/tools/patchCollection.js +++ b/dist/src/tools/patchCollection.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'patchCollection'; 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({ @@ -64,7 +60,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -80,7 +76,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -96,7 +92,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -112,7 +108,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -128,7 +124,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -144,7 +140,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -160,7 +156,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -176,7 +172,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -192,7 +188,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -208,7 +204,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -224,7 +220,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -240,7 +236,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z diff --git a/dist/src/tools/patchEnvironment.js b/dist/src/tools/patchEnvironment.js index be54466..a3c085d 100644 --- a/dist/src/tools/patchEnvironment.js +++ b/dist/src/tools/patchEnvironment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'patchEnvironment'; 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({ diff --git a/dist/src/tools/postPanElementOrFolder.js b/dist/src/tools/postPanElementOrFolder.js index 3038bbb..2680d53 100644 --- a/dist/src/tools/postPanElementOrFolder.js +++ b/dist/src/tools/postPanElementOrFolder.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'postPanElementOrFolder'; export const description = "Publishes a element or creates a folder in your team's [Private API Network](https://learning.postman.com/docs/collaborating-in-postman/adding-private-network/). An element is a Postman API, collection, or workspace.\n\n**Note:**\n\nYou can only pass one element object type per call. For example, you cannot pass both \\`api\\` and \\`collection\\` in a single request.\n"; export const parameters = z.object({ diff --git a/dist/src/tools/publishDocumentation.js b/dist/src/tools/publishDocumentation.js index 7c6e7c8..3c3ce7a 100644 --- a/dist/src/tools/publishDocumentation.js +++ b/dist/src/tools/publishDocumentation.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'publishDocumentation'; export const description = "Publishes a collection's documentation. This makes it publicly available to anyone with the link to the documentation.\n\n**Note:**\n\n- Your [Postman plan](https://www.postman.com/pricing/) impacts your use of these endpoints:\n - For **Free** and **Basic** users, you must have permissions to edit the collection.\n - If [API Governance and Security](https://learning.postman.com/docs/api-governance/configurable-rules/configurable-rules-overview/) is enabled for your [**Enterprise**](https://www.postman.com/pricing/) team, only users with the [Community Manager role](https://learning.postman.com/docs/collaborating-in-postman/roles-and-permissions/#team-roles) can publish documentation.\n- Publishing is only supported for collections with HTTP requests.\n- You cannot publish a collection added to an API.\n"; export const parameters = z.object({ diff --git a/dist/src/tools/publishMock.js b/dist/src/tools/publishMock.js index 7110c87..ba7e0dc 100644 --- a/dist/src/tools/publishMock.js +++ b/dist/src/tools/publishMock.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'publishMock'; export const description = 'Publishes a mock server. Publishing a mock server sets its **Access Control** configuration setting to public.'; export const parameters = z.object({ mockId: z.string().describe("The mock's ID.") }); diff --git a/dist/src/tools/pullCollectionChanges.js b/dist/src/tools/pullCollectionChanges.js index b1bb131..cad156b 100644 --- a/dist/src/tools/pullCollectionChanges.js +++ b/dist/src/tools/pullCollectionChanges.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'pullCollectionChanges'; export const description = "Pulls the changes from a parent (source) collection into the forked collection. In the endpoint's response:\n\n- The \\`destinationId\\` is the ID of the forked collection.\n- The \\`sourceId\\` is the ID of the source collection.\n"; export const parameters = z.object({ collectionId: z.string().describe("The collection's ID.") }); diff --git a/dist/src/tools/putCollection.js b/dist/src/tools/putCollection.js index 6e71887..4979209 100644 --- a/dist/src/tools/putCollection.js +++ b/dist/src/tools/putCollection.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'putCollection'; export const description = "Replaces the contents of a collection using the [Postman Collection v2.1.0 schema format](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html). Include the collection's ID values in the request body. If you do not, the endpoint removes the existing items and creates new items.\n\nTo perform an update asynchronously, use the \\`Prefer\\` header with the \\`respond-async\\` value. When performing an async update, this endpoint returns a HTTP \\`202 Accepted\\` response.\n\n**Note:**\n\n- The maximum collection size this endpoint accepts cannot exceed 100 MB.\n- If you don't include the collection items' ID values from the request body, the endpoint **removes** the existing items and recreates the items with new ID values.\n- To copy another collection's contents to the given collection, remove all ID values before you pass it in this endpoint. If you do not, this endpoint returns an error. These values include the \\`id\\`, \\`uid\\`, and \\`postman_id\\` values.\n- For protocol profile behavior, refer to Postman's [Protocol Profile Behavior documentation](https://github.com/postmanlabs/postman-runtime/blob/develop/docs/protocol-profile-behavior.md).\n"; export const parameters = z.object({ @@ -164,7 +160,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -180,7 +176,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -196,7 +192,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -212,7 +208,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -228,7 +224,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -244,7 +240,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -260,7 +256,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -276,7 +272,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -292,7 +288,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -308,7 +304,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -324,7 +320,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -340,7 +336,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -399,7 +395,7 @@ export const parameters = z.object({ .describe('A list of x-www-form-encoded key/value pairs.') .optional(), formdata: z - .array(z.record(z.any()).and(z.union([ + .array(z.record(z.string(), z.unknown()).and(z.union([ z.object({ key: z.string().describe('The key value.').optional(), value: z.string().describe("The key's value.").optional(), @@ -417,7 +413,7 @@ export const parameters = z.object({ z.object({ key: z.string().describe('The key value.').optional(), src: z - .any() + .unknown() .superRefine((x, ctx) => { const schemas = [z.string().nullable(), z.array(z.string())]; const errors = schemas.reduce((errors, schema) => ((result) => result.error ? [...errors, result.error] : errors)(schema.safeParse(x)), []); @@ -467,7 +463,7 @@ export const parameters = z.object({ .describe('If the `mode` value is `graphql`, an object containing the GraphQL request information.') .optional(), options: z - .record(z.any()) + .record(z.string(), z.unknown()) .describe('Additional configurations and options set for various modes.') .optional(), }) @@ -476,6 +472,10 @@ export const parameters = z.object({ }) .describe('Information about the collection request.') .optional(), + response: z + .array(z.unknown().describe("Information about the request's response.")) + .describe("A list of the collection's responses.") + .optional(), protocolProfileBehavior: z .object({ strictSSL: z @@ -617,7 +617,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -633,7 +633,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -649,7 +649,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -665,7 +665,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -681,7 +681,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -697,7 +697,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -713,7 +713,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -729,7 +729,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -745,7 +745,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -761,7 +761,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -777,7 +777,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -793,7 +793,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -882,14 +882,14 @@ export const annotations = { destructiveHint: false, idempotentHint: true, }; -export async function handler(params, extra) { +export async function handler(args, extra) { try { - const endpoint = `/collections/${params.collectionId}`; + const endpoint = `/collections/${args.collectionId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload = {}; - if (params.collection !== undefined) - bodyPayload.collection = params.collection; + if (args.collection !== undefined) + bodyPayload.collection = args.collection; const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, diff --git a/dist/src/tools/putEnvironment.js b/dist/src/tools/putEnvironment.js index 69acdc4..5909b3f 100644 --- a/dist/src/tools/putEnvironment.js +++ b/dist/src/tools/putEnvironment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'putEnvironment'; export const description = 'Replaces all the contents of an environment with the given information.\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 parameters = z.object({ diff --git a/dist/src/tools/resolveCommentThread.js b/dist/src/tools/resolveCommentThread.js index cd2baf0..5dc9979 100644 --- a/dist/src/tools/resolveCommentThread.js +++ b/dist/src/tools/resolveCommentThread.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'resolveCommentThread'; export const description = 'Resolves a comment and any associated replies. On success, this returns an HTTP \\`204 No Content\\` response.\n\nComment thread IDs return in the GET comments response for [APIs](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-2103ea20-f7de-4628-90e6-b823b3084a52), [collections](https://www.postman.com/postman/workspace/postman-public-workspace/request/12959542-a6582e0a-9382-4760-8b91-53a8aa6cb8d7), and [collection items](https://www.postman.com/postman/workspace/postman-public-workspace/folder/12959542-efeda219-66e1-474c-a83b-253d15723bf7).\n'; export const parameters = z.object({ diff --git a/dist/src/tools/runCollection.js b/dist/src/tools/runCollection.js index 58c3857..3a28d1b 100644 --- a/dist/src/tools/runCollection.js +++ b/dist/src/tools/runCollection.js @@ -1,11 +1,7 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; import newman from 'newman'; import { TestTracker, OutputBuilder, buildNewmanOptions } from './utils/runner.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'runCollection'; export const description = 'Runs a Postman collection by ID with detailed test results and execution statistics. Supports optional environment for variable substitution. Note: Advanced parameters like custom delays and other runtime options are not yet available.'; export const parameters = z.object({ diff --git a/dist/src/tools/runMonitor.js b/dist/src/tools/runMonitor.js index f30df28..78993ca 100644 --- a/dist/src/tools/runMonitor.js +++ b/dist/src/tools/runMonitor.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'runMonitor'; 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({ diff --git a/dist/src/tools/syncCollectionWithSpec.js b/dist/src/tools/syncCollectionWithSpec.js index de2dae5..bed4c84 100644 --- a/dist/src/tools/syncCollectionWithSpec.js +++ b/dist/src/tools/syncCollectionWithSpec.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'syncCollectionWithSpec'; export const description = 'Syncs a collection generated from an API specification. This is an asynchronous endpoint that returns an HTTP \\`202 Accepted\\` response.\n\n**Note:**\n\n- This endpoint only supports the OpenAPI 3.0 specification type.\n- You can only sync collections generated from the given spec ID.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/syncSpecWithCollection.js b/dist/src/tools/syncSpecWithCollection.js index d8ac942..e582b9e 100644 --- a/dist/src/tools/syncSpecWithCollection.js +++ b/dist/src/tools/syncSpecWithCollection.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'syncSpecWithCollection'; export const description = 'Syncs an API specification linked to a collection. This is an asynchronous endpoint that returns an HTTP \\`202 Accepted\\` response.\n\n**Note:**\n\n- This endpoint only supports the OpenAPI 3.0 specification type.\n- You can only sync specs generated from the given collection ID.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/transferCollectionFolders.js b/dist/src/tools/transferCollectionFolders.js index b8bcdbb..bd7a6d2 100644 --- a/dist/src/tools/transferCollectionFolders.js +++ b/dist/src/tools/transferCollectionFolders.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'transferCollectionFolders'; export const description = 'Copies or moves folders into a collection or folder.'; export const parameters = z.object({ diff --git a/dist/src/tools/transferCollectionRequests.js b/dist/src/tools/transferCollectionRequests.js index adec36e..c291109 100644 --- a/dist/src/tools/transferCollectionRequests.js +++ b/dist/src/tools/transferCollectionRequests.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'transferCollectionRequests'; export const description = 'Copies or moves requests into a collection or folder.'; export const parameters = z.object({ diff --git a/dist/src/tools/transferCollectionResponses.js b/dist/src/tools/transferCollectionResponses.js index 3edd677..8576476 100644 --- a/dist/src/tools/transferCollectionResponses.js +++ b/dist/src/tools/transferCollectionResponses.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'transferCollectionResponses'; export const description = 'Copies or moves responses into a request.'; export const parameters = z.object({ diff --git a/dist/src/tools/unpublishDocumentation.js b/dist/src/tools/unpublishDocumentation.js index 995e6b9..0446619 100644 --- a/dist/src/tools/unpublishDocumentation.js +++ b/dist/src/tools/unpublishDocumentation.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'unpublishDocumentation'; export const description = "Unpublishes a collection's documentation. On success, this returns an HTTP \\`204 No Content\\` response."; export const parameters = z.object({ diff --git a/dist/src/tools/unpublishMock.js b/dist/src/tools/unpublishMock.js index 9d75ffd..9451075 100644 --- a/dist/src/tools/unpublishMock.js +++ b/dist/src/tools/unpublishMock.js @@ -1,9 +1,5 @@ import { z } from 'zod'; -import { McpError, ErrorCode, } from '@modelcontextprotocol/sdk/types.js'; -function asMcpError(error) { - const cause = error?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'unpublishMock'; export const description = 'Unpublishes a mock server. Unpublishing a mock server sets its **Access Control** configuration setting to private.'; export const parameters = z.object({ mockId: z.string().describe("The mock's ID.") }); diff --git a/dist/src/tools/updateApiCollectionComment.js b/dist/src/tools/updateApiCollectionComment.js index e958cb0..150a515 100644 --- a/dist/src/tools/updateApiCollectionComment.js +++ b/dist/src/tools/updateApiCollectionComment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateApiCollectionComment'; export const description = "Updates a comment on an API's collection.\n\n**Note:**\n\nThis endpoint accepts a max of 10,000 characters.\n"; export const parameters = z.object({ diff --git a/dist/src/tools/updateCollectionComment.js b/dist/src/tools/updateCollectionComment.js index deb221c..2f4020c 100644 --- a/dist/src/tools/updateCollectionComment.js +++ b/dist/src/tools/updateCollectionComment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateCollectionComment'; export const description = 'Updates a comment on a collection.\n\n**Note:**\n\nThis endpoint accepts a max of 10,000 characters.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/updateCollectionFolder.js b/dist/src/tools/updateCollectionFolder.js index 30b4865..8c9c0ee 100644 --- a/dist/src/tools/updateCollectionFolder.js +++ b/dist/src/tools/updateCollectionFolder.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateCollectionFolder'; export const description = 'Updates a folder in a collection. For a complete list of properties, refer to the **Folder** entry in the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).\n\n**Note:**\n\nThis endpoint acts like a PATCH method. It only updates the values that you pass in the request body (for example, the \\`name\\` property). The endpoint does not update the entire resource.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/updateCollectionRequest.js b/dist/src/tools/updateCollectionRequest.js index 53f69d1..6fffd09 100644 --- a/dist/src/tools/updateCollectionRequest.js +++ b/dist/src/tools/updateCollectionRequest.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateCollectionRequest'; export const description = 'Updates a request in a collection. For a complete list of properties, refer to the **Request** entry in the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).\n\n**Note:**\n\n- You must pass a collection ID (\\`12ece9e1-2abf-4edc-8e34-de66e74114d2\\`), not a collection(\\`12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\\`), in this endpoint.\n- This endpoint does not support changing the folder of a request.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/updateCollectionResponse.js b/dist/src/tools/updateCollectionResponse.js index ea21648..a2065e7 100644 --- a/dist/src/tools/updateCollectionResponse.js +++ b/dist/src/tools/updateCollectionResponse.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateCollectionResponse'; export const description = 'Updates a response in a collection. For a complete list of properties, see the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).\n\n**Note:**\n\n- You must pass a collection ID (\\`12ece9e1-2abf-4edc-8e34-de66e74114d2\\`), not a collection UID (\\`12345678-12ece9e1-2abf-4edc-8e34-de66e74114d2\\`), in this endpoint.\n- This endpoint acts like a PATCH method. It only updates the values that you pass in the request body (for example, the \\`name\\` property). The endpoint does not update the entire resource.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/updateCollectionTags.js b/dist/src/tools/updateCollectionTags.js index 67f81f6..022d694 100644 --- a/dist/src/tools/updateCollectionTags.js +++ b/dist/src/tools/updateCollectionTags.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateCollectionTags'; export const description = "Updates a collection's associated tags. This endpoint replaces all existing tags with those you pass in the request body."; export const parameters = z.object({ diff --git a/dist/src/tools/updateFolderComment.js b/dist/src/tools/updateFolderComment.js index 54650a6..d08cc41 100644 --- a/dist/src/tools/updateFolderComment.js +++ b/dist/src/tools/updateFolderComment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateFolderComment'; export const description = 'Updates a comment on a folder.\n\n**Note:**\n\nThis endpoint accepts a max of 10,000 characters.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/updateMock.js b/dist/src/tools/updateMock.js index ed3736a..d82f829 100644 --- a/dist/src/tools/updateMock.js +++ b/dist/src/tools/updateMock.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateMock'; export const description = 'Updates a mock server.\n- Resource: Mock server entity associated with a collection UID.\n- Use this to change name, environment, privacy, or default server response.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/updateMonitor.js b/dist/src/tools/updateMonitor.js index 1feeb3b..069c24f 100644 --- a/dist/src/tools/updateMonitor.js +++ b/dist/src/tools/updateMonitor.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateMonitor'; export const description = "Updates a monitor's [configurations](https://learning.postman.com/docs/monitoring-your-api/setting-up-monitor/#configure-a-monitor)."; export const parameters = z.object({ diff --git a/dist/src/tools/updatePanElementOrFolder.js b/dist/src/tools/updatePanElementOrFolder.js index 59510fd..9742d44 100644 --- a/dist/src/tools/updatePanElementOrFolder.js +++ b/dist/src/tools/updatePanElementOrFolder.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updatePanElementOrFolder'; export const description = "Updates an element or folder in your team's [Private API Network](https://learning.postman.com/docs/collaborating-in-postman/adding-private-network/).\n\n**Note:**\n\nYou can only pass one element object type per call. For example, you cannot pass both \\`api\\` and \\`collection\\` in a single request.\n"; export const parameters = z.object({ diff --git a/dist/src/tools/updateRequestComment.js b/dist/src/tools/updateRequestComment.js index 05b26bc..9b75f50 100644 --- a/dist/src/tools/updateRequestComment.js +++ b/dist/src/tools/updateRequestComment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateRequestComment'; export const description = 'Updates a comment on a request.\n\n**Note:**\n\nThis endpoint accepts a max of 10,000 characters.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/updateResponseComment.js b/dist/src/tools/updateResponseComment.js index 4dd2b30..367a7d6 100644 --- a/dist/src/tools/updateResponseComment.js +++ b/dist/src/tools/updateResponseComment.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateResponseComment'; export const description = 'Updates a comment on a response.\n\n**Note:**\n\nThis endpoint accepts a max of 10,000 characters.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/updateSpecFile.js b/dist/src/tools/updateSpecFile.js index 4a8f9b2..155392a 100644 --- a/dist/src/tools/updateSpecFile.js +++ b/dist/src/tools/updateSpecFile.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateSpecFile'; export const description = "Updates an API specification's file.\n\n**Note:**\n\n- This endpoint does not accept an empty request body. You must pass one of the accepted values.\n- This endpoint does not accept multiple request body properties in a single call. For example, you cannot pass both the \\`content\\` and \\`type\\` property at the same time.\n- Multi-file specifications can only have one root file.\n- When updating a file type to \\`ROOT\\`, the previous root file is updated to the \\`DEFAULT\\` file type.\n- Files cannot exceed a maximum of 10 MB in size.\n"; export const parameters = z.object({ diff --git a/dist/src/tools/updateSpecProperties.js b/dist/src/tools/updateSpecProperties.js index 36b190e..ba6d525 100644 --- a/dist/src/tools/updateSpecProperties.js +++ b/dist/src/tools/updateSpecProperties.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateSpecProperties'; export const description = "Updates an API specification's properties, such as its name."; export const parameters = z.object({ diff --git a/dist/src/tools/updateWorkspace.js b/dist/src/tools/updateWorkspace.js index 16113d7..0169f44 100644 --- a/dist/src/tools/updateWorkspace.js +++ b/dist/src/tools/updateWorkspace.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateWorkspace'; export const description = 'Updates a workspace.\n\n**Note:**\n\n- There are rate limits when publishing public workspaces.\n- Public team workspace names must be unique.\n\n### Important\n\nWe deprecated linking collections or environments between workspaces. We do not recommend that you do this.\n\nIf you have a linked collection or environment, note the following:\n- The endpoint does not create a clone of a collection or environment.\n- Any changes you make to a linked collection or environment changes them in all workspaces.\n- If you delete a collection or environment linked between workspaces, the system deletes it in all the workspaces.\n'; export const parameters = z.object({ diff --git a/dist/src/tools/updateWorkspaceGlobalVariables.js b/dist/src/tools/updateWorkspaceGlobalVariables.js index f87b035..7b9981b 100644 --- a/dist/src/tools/updateWorkspaceGlobalVariables.js +++ b/dist/src/tools/updateWorkspaceGlobalVariables.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateWorkspaceGlobalVariables'; export const description = "Updates and replaces a workspace's global [variables](https://learning.postman.com/docs/sending-requests/variables/#variable-scopes). This endpoint replaces all existing global variables with the variables you pass in the request body."; export const parameters = z.object({ diff --git a/dist/src/tools/updateWorkspaceTags.js b/dist/src/tools/updateWorkspaceTags.js index 2b51901..b5b281d 100644 --- a/dist/src/tools/updateWorkspaceTags.js +++ b/dist/src/tools/updateWorkspaceTags.js @@ -1,10 +1,6 @@ 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); -} +import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateWorkspaceTags'; export const description = "Updates a workspace's associated tags. This endpoint replaces all existing tags with those you pass in the request body."; export const parameters = z.object({ diff --git a/dist/src/tools/utils/toolHelpers.js b/dist/src/tools/utils/toolHelpers.js new file mode 100644 index 0000000..f6e5fd8 --- /dev/null +++ b/dist/src/tools/utils/toolHelpers.js @@ -0,0 +1,6 @@ +import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; +export { McpError }; +export function asMcpError(error) { + const cause = error?.cause ?? String(error); + return new McpError(ErrorCode.InternalError, cause); +} diff --git a/src/clients/postman.ts b/src/clients/postman.ts index 79913e2..c53cbff 100644 --- a/src/clients/postman.ts +++ b/src/clients/postman.ts @@ -1,5 +1,5 @@ import { IsomorphicHeaders, McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; -import packageJson from '../../package.json' with { type: 'json' }; +import { USER_AGENT } from '../constants.js'; export enum ContentType { Json = 'application/json', @@ -109,9 +109,7 @@ export class PostmanAPIClient implements IPostmanAPIClient { ); const userAgentValue = userAgentKey ? options.headers?.[userAgentKey] : undefined; - const userAgentHeader = userAgentValue - ? `${userAgentValue}/${packageJson.name}/${packageJson.version}` - : `${packageJson.name}/${packageJson.version}`; + const userAgentHeader = userAgentValue ? `${userAgentValue}/${USER_AGENT}` : USER_AGENT; const disallowed = new Set([ 'content-length', diff --git a/src/constants.ts b/src/constants.ts new file mode 100644 index 0000000..934617f --- /dev/null +++ b/src/constants.ts @@ -0,0 +1,9 @@ +import packageJson from '../package.json' with { type: 'json' }; + +/** + * Shared constants for the Postman MCP Server + */ + +export const SERVER_NAME = packageJson.name; +export const APP_VERSION = packageJson.version; +export const USER_AGENT = `${packageJson.name}/${packageJson.version}`; diff --git a/src/enabledResources.ts b/src/enabledResources.ts index 379182b..389fce7 100644 --- a/src/enabledResources.ts +++ b/src/enabledResources.ts @@ -145,7 +145,7 @@ const full = [ 'getDuplicateCollectionTaskStatus', 'deleteApiCollectionComment', 'deleteSpecFile', - 'runCollection', + 'getEnabledTools', ] as const; const minimal = [ @@ -188,9 +188,13 @@ const minimal = [ 'duplicateCollection', 'getStatusOfAnAsyncApiTask', 'runCollection', + 'getEnabledTools', ] as const; -const excludedFromGeneration = ['createCollection', 'putCollection'] as const; +const excludedFromGeneration = [ + 'runCollection', + 'getEnabledTools', +] as const; export const enabledResources = { full, diff --git a/src/index.ts b/src/index.ts index baabd47..89e14e9 100644 --- a/src/index.ts +++ b/src/index.ts @@ -12,13 +12,14 @@ import { CallToolResult, } from '@modelcontextprotocol/sdk/types.js'; -import packageJson from '../package.json' with { type: 'json' }; import { readdir } from 'node:fs/promises'; 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'; +import { SERVER_NAME, APP_VERSION } from './constants.js'; +import { ServerContext } from './tools/utils/toolHelpers.js'; const SUPPORTED_REGIONS = { us: 'https://api.postman.com', @@ -81,6 +82,7 @@ interface ToolModule { extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; + serverContext?: ServerContext; } ) => Promise; } @@ -149,10 +151,6 @@ if (dotEnvOutput.error) { ); } -const SERVER_NAME = packageJson.name; -const APP_VERSION = packageJson.version; -export const USER_AGENT = `${SERVER_NAME}/${APP_VERSION}`; - let clientInfo: InitializeRequest['params']['clientInfo'] | undefined = undefined; async function run() { @@ -213,6 +211,12 @@ async function run() { // Create a client instance with the API key for STDIO mode const client = new PostmanAPIClient(apiKey); + // Create server context that will be passed to all tools + const serverContext: ServerContext = { + serverType: useFull ? 'full' : 'minimal', + availableTools: tools.map((t) => t.method), + }; + log('info', 'Registering tools with McpServer'); // Register all tools using the McpServer .tool() method @@ -236,6 +240,7 @@ async function run() { ...extra?.requestInfo?.headers, 'user-agent': clientInfo?.name, }, + serverContext, }); const durationMs = Date.now() - start; diff --git a/src/tests/integration/direct.test.ts b/src/tests/integration/direct.test.ts index 337217b..78345ee 100644 --- a/src/tests/integration/direct.test.ts +++ b/src/tests/integration/direct.test.ts @@ -9,6 +9,8 @@ import { TestEnvironment, SpecDataFactory, TestSpec, + CollectionDataFactory, + TestCollection, } from './factories/dataFactory.js'; import { PostmanAPIClient } from '../../clients/postman.js'; import packageJson from '../../../package.json' assert { type: 'json' }; @@ -19,6 +21,7 @@ describe('Postman MCP - Direct Integration Tests', () => { let createdWorkspaceIds: string[] = []; let createdEnvironmentIds: string[] = []; let createdSpecIds: string[] = []; + let createdCollectionIds: string[] = []; beforeAll(async () => { console.log('🚀 Starting Postman MCP server for integration tests...'); @@ -75,15 +78,18 @@ describe('Postman MCP - Direct Integration Tests', () => { beforeEach(() => { createdWorkspaceIds = []; createdEnvironmentIds = []; + createdCollectionIds = []; }); afterEach(async () => { + await cleanupTestCollections(createdCollectionIds); await cleanupTestWorkspaces(createdWorkspaceIds); await cleanupTestEnvironments(createdEnvironmentIds); await cleanupTestSpecs(createdSpecIds); createdWorkspaceIds = []; createdEnvironmentIds = []; createdSpecIds = []; + createdCollectionIds = []; }); describe('User-Agent Header Tests', () => { @@ -255,9 +261,7 @@ describe('Postman MCP - Direct Integration Tests', () => { try { await client.get('/test-endpoint'); - expect(capturedHeaders['user-agent']).toBe( - `${expectedPackageName}/${expectedPackageVersion}` - ); + expect(capturedHeaders['user-agent']).toBe(`${expectedPackageName}/${expectedPackageVersion}`); expect(capturedHeaders['x-api-key']).toBe('test-api-key'); } finally { global.fetch = originalFetch; @@ -523,6 +527,197 @@ describe('Postman MCP - Direct Integration Tests', () => { }); }); + describe('Collection Workflow', () => { + it('should create, list, get, update, and delete a single collection', async () => { + const workspace = WorkspaceDataFactory.createWorkspace({ + name: '[Integration Test] Collection Workspace', + }); + const workspaceId = await createWorkspace(workspace); + createdWorkspaceIds.push(workspaceId); + + const collectionData = CollectionDataFactory.createCollection(); + const collectionId = await createCollection(collectionData, workspaceId); + createdCollectionIds.push(collectionId); + + expect(createdCollectionIds).toHaveLength(1); + expect(createdCollectionIds[0]).toBe(collectionId); + + const listResult = await client.callTool( + { + name: 'getCollections', + arguments: { + workspace: workspaceId, + }, + }, + undefined, + { timeout: 100000 } + ); + expect(CollectionDataFactory.validateResponse(listResult)).toBe(true); + expect((listResult.content as any)[0].text).toContain(collectionId); + + const getResult = await client.callTool( + { + name: 'getCollection', + arguments: { collectionId }, + }, + undefined, + { timeout: 100000 } + ); + expect(CollectionDataFactory.validateResponse(getResult)).toBe(true); + expect((getResult.content as any)[0].text).toContain(collectionData.info.name); + + const collection = CollectionDataFactory.extractCollectionFromResponse(getResult); + expect(collection).toBeDefined(); + + const updatedName = '[Integration Test] Updated Collection'; + const updatedCollection = { + ...collection, + info: { + ...collection.info, + name: updatedName, + }, + }; + + const updateResult = await client.callTool( + { + name: 'putCollection', + arguments: { + collectionId, + collection: updatedCollection, + }, + }, + undefined, + { timeout: 100000 } + ); + expect(CollectionDataFactory.validateResponse(updateResult)).toBe(true); + + const verifyUpdateResult = await client.callTool( + { + name: 'getCollection', + arguments: { + collectionId, + }, + }, + undefined, + { timeout: 100000 } + ); + expect(CollectionDataFactory.validateResponse(verifyUpdateResult)).toBe(true); + expect((verifyUpdateResult.content as any)[0].text).toContain(updatedName); + }); + + it('should create and delete a minimal collection', async () => { + const workspace = WorkspaceDataFactory.createWorkspace({ + name: '[Integration Test] Minimal Collection Workspace', + }); + const workspaceId = await createWorkspace(workspace); + createdWorkspaceIds.push(workspaceId); + + const collectionData = CollectionDataFactory.createMinimalCollection(); + const collectionId = await createCollection(collectionData, workspaceId); + createdCollectionIds.push(collectionId); + + const getResult = await client.callTool( + { + name: 'getCollection', + arguments: { collectionId }, + }, + undefined, + { timeout: 100000 } + ); + expect(CollectionDataFactory.validateResponse(getResult)).toBe(true); + expect((getResult.content as any)[0].text).toContain(collectionData.info.name); + }); + + it('should filter collections by name', async () => { + const workspace = WorkspaceDataFactory.createWorkspace({ + name: '[Integration Test] Collection Filter Workspace', + }); + const workspaceId = await createWorkspace(workspace); + createdWorkspaceIds.push(workspaceId); + + const collection1 = CollectionDataFactory.createCollection({ + info: { + name: '[Integration Test] Filter Collection Alpha', + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json', + }, + }); + const collection2 = CollectionDataFactory.createCollection({ + info: { + name: '[Integration Test] Filter Collection Beta', + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json', + }, + }); + + const collectionId1 = await createCollection(collection1, workspaceId); + const collectionId2 = await createCollection(collection2, workspaceId); + createdCollectionIds.push(collectionId1, collectionId2); + + const filterResult = await client.callTool( + { + name: 'getCollections', + arguments: { + workspace: workspaceId, + name: '[Integration Test] Filter Collection Alpha', + }, + }, + undefined, + { timeout: 100000 } + ); + expect(CollectionDataFactory.validateResponse(filterResult)).toBe(true); + const responseText = (filterResult.content as any)[0].text; + expect(responseText).toContain('Alpha'); + }); + + it('should paginate collections list', async () => { + const workspace = WorkspaceDataFactory.createWorkspace({ + name: '[Integration Test] Collection Pagination Workspace', + }); + const workspaceId = await createWorkspace(workspace); + createdWorkspaceIds.push(workspaceId); + + const collections: string[] = []; + for (let i = 0; i < 3; i++) { + const collection = CollectionDataFactory.createCollection({ + info: { + name: `[Integration Test] Pagination Collection ${i}`, + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json', + }, + }); + const collectionId = await createCollection(collection, workspaceId); + collections.push(collectionId); + createdCollectionIds.push(collectionId); + } + + const firstPageResult = await client.callTool( + { + name: 'getCollections', + arguments: { + workspace: workspaceId, + limit: 2, + offset: 0, + }, + }, + undefined, + { timeout: 100000 } + ); + expect(CollectionDataFactory.validateResponse(firstPageResult)).toBe(true); + + const secondPageResult = await client.callTool( + { + name: 'getCollections', + arguments: { + workspace: workspaceId, + limit: 2, + offset: 2, + }, + }, + undefined, + { timeout: 100000 } + ); + expect(CollectionDataFactory.validateResponse(secondPageResult)).toBe(true); + }); + }); + async function createWorkspace(workspaceData: TestWorkspace): Promise { const result = await client.callTool( { @@ -597,6 +792,51 @@ describe('Postman MCP - Direct Integration Tests', () => { return specId; } + async function createCollection( + collectionData: TestCollection, + workspaceId: string + ): Promise { + const result = await client.callTool( + { + name: 'createCollection', + arguments: { + workspace: workspaceId, + collection: collectionData, + }, + }, + undefined, + { timeout: 100000 } + ); + if (result.isError) { + throw new Error((result.content as any)[0].text); + } + expect(CollectionDataFactory.validateResponse(result)).toBe(true); + const collectionId = CollectionDataFactory.extractIdFromResponse(result); + if (!collectionId) { + throw new Error(`Collection ID not found in response: ${JSON.stringify(result)}`); + } + return collectionId; + } + + async function cleanupTestCollections(collectionIds: string[]): Promise { + for (const collectionId of collectionIds) { + try { + await client.callTool( + { + name: 'deleteCollection', + arguments: { + collectionId, + }, + }, + undefined, + { timeout: 100000 } + ); + } catch (error) { + console.warn(`Failed to cleanup collection ${collectionId}:`, String(error)); + } + } + } + async function cleanupTestWorkspaces(workspaceIds: string[]): Promise { for (const workspaceId of workspaceIds) { try { @@ -656,7 +896,9 @@ describe('Postman MCP - Direct Integration Tests', () => { async function cleanupAllTestResources(): Promise { console.log('Cleaning up all test resources...'); + await cleanupTestCollections(createdCollectionIds); await cleanupTestWorkspaces(createdWorkspaceIds); await cleanupTestEnvironments(createdEnvironmentIds); + await cleanupTestSpecs(createdSpecIds); } }); diff --git a/src/tests/integration/factories/dataFactory.ts b/src/tests/integration/factories/dataFactory.ts index befb36b..bd2d9f4 100644 --- a/src/tests/integration/factories/dataFactory.ts +++ b/src/tests/integration/factories/dataFactory.ts @@ -151,7 +151,7 @@ export class SpecDataFactory extends TestDataFactory { return { path: 'index.yaml', content: - "openapi: 3.0.0\ninfo:\n title: My API\n version: 1.0.0\npaths:\n /:\n get:\n summary: My Endpoint\n responses:\n '200':\n description: OK", + 'openapi: 3.0.0\ninfo:\n title: My API\n version: 1.0.0\npaths:\n /:\n get:\n summary: My Endpoint\n responses:\n \'200\':\n description: OK', ...overrides, }; } @@ -208,3 +208,112 @@ export class SpecDataFactory extends TestDataFactory { } } } + +export interface TestCollection { + info: { + name: string; + description?: string; + schema: string; + }; + item: Array<{ + name: string; + request?: { + url?: string; + method?: string; + header?: Array<{ key: string; value: string }>; + body?: { + mode?: string; + raw?: string; + }; + }; + }>; +} + +export class CollectionDataFactory extends TestDataFactory { + public static createCollection(overrides: Partial = {}): TestCollection { + return { + info: { + name: '[Integration Test] Test Collection', + description: 'Created by integration test suite', + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json', + }, + item: [ + { + name: 'Sample Request', + request: { + url: 'https://postman-echo.com/get', + method: 'GET', + }, + }, + ], + ...overrides, + }; + } + + public static createMinimalCollection( + overrides: Partial = {} + ): TestCollection { + return { + info: { + name: '[Integration Test] Minimal Collection', + schema: 'https://schema.getpostman.com/json/collection/v2.1.0/collection.json', + }, + item: [], + ...overrides, + }; + } + + static validateResponse(response: any): boolean { + if (!response || !response.content || !Array.isArray(response.content)) { + return false; + } + const text = response.content[0]?.text; + return typeof text === 'string'; + } + + static extractIdFromResponse(response: any): string | null { + const text = response.content[0]?.text; + if (!text) return null; + + try { + const parsed = JSON.parse(text); + if (parsed.collection?.id) { + return parsed.collection.id; + } else if (parsed.collection?.uid) { + return parsed.collection.uid; + } else if (parsed.id) { + return parsed.id; + } else if (parsed.uid) { + return parsed.uid; + } + + // Try to extract uid pattern (owner-id) + const uidPattern = /"uid":\s*"([^"]+)"/; + const uidMatch = text.match(uidPattern); + if (uidMatch) return uidMatch[1]; + + const idPattern = /"id":\s*"([a-zA-Z0-9_-]+)"/; + const idMatch = text.match(idPattern); + return idMatch ? idMatch[1] : null; + } catch { + const uidPattern = /"uid":\s*"([^"]+)"/; + const uidMatch = text.match(uidPattern); + if (uidMatch) return uidMatch[1]; + + const idPattern = /"id":\s*"([a-zA-Z0-9_-]+)"/; + const idMatch = text.match(idPattern); + return idMatch ? idMatch[1] : null; + } + } + + static extractCollectionFromResponse(response: any): any | null { + const text = response.content[0]?.text; + if (!text) return null; + try { + const parsed = JSON.parse(text); + return parsed.collection || parsed; + } catch { + return null; + } + } +} diff --git a/src/tools/createCollection.ts b/src/tools/createCollection.ts index 7cdd714..f03aa45 100644 --- a/src/tools/createCollection.ts +++ b/src/tools/createCollection.ts @@ -1,11 +1,7 @@ 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); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollection'; export const description = @@ -152,14 +148,14 @@ export const parameters = z.object({ 'edgegrid', ]) .describe('The authorization type.'), - noauth: z.any().optional(), + noauth: z.unknown().optional(), apikey: z .array( z .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -179,7 +175,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -201,7 +197,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -223,7 +219,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -245,7 +241,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -267,7 +263,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -289,7 +285,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -311,7 +307,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -333,7 +329,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -355,7 +351,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -434,7 +430,7 @@ export const parameters = z.object({ .optional(), formdata: z .array( - z.record(z.any()).and( + z.record(z.string(), z.unknown()).and( z.union([ z.object({ key: z.string().describe('The key value.').optional(), @@ -453,7 +449,7 @@ export const parameters = z.object({ z.object({ key: z.string().describe('The key value.').optional(), src: z - .any() + .unknown() .superRefine((x, ctx) => { const schemas = [z.string().nullable(), z.array(z.string())]; const errors = schemas.reduce( @@ -520,7 +516,7 @@ export const parameters = z.object({ ) .optional(), options: z - .record(z.any()) + .record(z.string(), z.unknown()) .describe('Additional configurations and options set for various modes.') .optional(), }) @@ -531,10 +527,10 @@ export const parameters = z.object({ }) .describe('Information about the collection request.') .optional(), - // response: z - // .array(z.any().describe("Information about the request's response.")) - // .describe("A list of the collection's responses.") - // .optional(), + response: z + .array(z.unknown().describe("Information about the request's response.")) + .describe("A list of the collection's responses.") + .optional(), protocolProfileBehavior: z .object({ strictSSL: z @@ -696,14 +692,14 @@ export const parameters = z.object({ 'edgegrid', ]) .describe('The authorization type.'), - noauth: z.any().optional(), + noauth: z.unknown().optional(), apikey: z .array( z .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -723,7 +719,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -745,7 +741,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -767,7 +763,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -789,7 +785,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -811,7 +807,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -833,7 +829,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -855,7 +851,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -877,7 +873,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -899,7 +895,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -1014,16 +1010,16 @@ export const annotations = { }; export async function handler( - params: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } -): Promise<{ content: Array<{ type: string; text: string } & Record> }> { + args: z.infer, + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } +): Promise { try { const endpoint = `/collections`; const query = new URLSearchParams(); - if (params.workspace !== undefined) query.set('workspace', String(params.workspace)); + if (args.workspace !== undefined) query.set('workspace', String(args.workspace)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; - if (params.collection !== undefined) bodyPayload.collection = params.collection; + if (args.collection !== undefined) bodyPayload.collection = args.collection; const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, diff --git a/src/tools/createCollectionComment.ts b/src/tools/createCollectionComment.ts index 2db0eb4..60ba636 100644 --- a/src/tools/createCollectionComment.ts +++ b/src/tools/createCollectionComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollectionComment'; export const description = @@ -50,7 +41,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/comments`; diff --git a/src/tools/createCollectionFolder.ts b/src/tools/createCollectionFolder.ts index e26e91f..b488677 100644 --- a/src/tools/createCollectionFolder.ts +++ b/src/tools/createCollectionFolder.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollectionFolder'; export const description = @@ -35,7 +26,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/folders`; diff --git a/src/tools/createCollectionFork.ts b/src/tools/createCollectionFork.ts index efa72d2..cf8062f 100644 --- a/src/tools/createCollectionFork.ts +++ b/src/tools/createCollectionFork.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollectionFork'; export const description = @@ -30,7 +21,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/fork/${args.collectionId}`; diff --git a/src/tools/createCollectionRequest.ts b/src/tools/createCollectionRequest.ts index bd31c49..bb01672 100644 --- a/src/tools/createCollectionRequest.ts +++ b/src/tools/createCollectionRequest.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollectionRequest'; export const description = @@ -40,7 +31,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/requests`; diff --git a/src/tools/createCollectionResponse.ts b/src/tools/createCollectionResponse.ts index 890f3d6..0aa87ef 100644 --- a/src/tools/createCollectionResponse.ts +++ b/src/tools/createCollectionResponse.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createCollectionResponse'; export const description = @@ -35,7 +26,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/responses`; diff --git a/src/tools/createEnvironment.ts b/src/tools/createEnvironment.ts index 03e9282..86db9cc 100644 --- a/src/tools/createEnvironment.ts +++ b/src/tools/createEnvironment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createEnvironment'; export const description = @@ -53,7 +44,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/environments`; diff --git a/src/tools/createFolderComment.ts b/src/tools/createFolderComment.ts index 10c06ca..bcd2d75 100644 --- a/src/tools/createFolderComment.ts +++ b/src/tools/createFolderComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createFolderComment'; export const description = @@ -51,7 +42,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/folders/${args.folderId}/comments`; diff --git a/src/tools/createMock.ts b/src/tools/createMock.ts index c3655bc..3071d69 100644 --- a/src/tools/createMock.ts +++ b/src/tools/createMock.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createMock'; export const description = @@ -44,7 +35,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/mocks`; diff --git a/src/tools/createMonitor.ts b/src/tools/createMonitor.ts index 5f8aa02..724a65a 100644 --- a/src/tools/createMonitor.ts +++ b/src/tools/createMonitor.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createMonitor'; export const description = @@ -147,7 +138,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/monitors`; diff --git a/src/tools/createRequestComment.ts b/src/tools/createRequestComment.ts index cca4be4..e12a2ee 100644 --- a/src/tools/createRequestComment.ts +++ b/src/tools/createRequestComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createRequestComment'; export const description = @@ -55,7 +46,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/requests/${args.requestId}/comments`; diff --git a/src/tools/createResponseComment.ts b/src/tools/createResponseComment.ts index e6ba571..e08ed6a 100644 --- a/src/tools/createResponseComment.ts +++ b/src/tools/createResponseComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createResponseComment'; export const description = @@ -51,7 +42,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/responses/${args.responseId}/comments`; diff --git a/src/tools/createSpec.ts b/src/tools/createSpec.ts index 179c7fa..d22a2c5 100644 --- a/src/tools/createSpec.ts +++ b/src/tools/createSpec.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createSpec'; export const description = @@ -49,7 +40,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs`; diff --git a/src/tools/createSpecFile.ts b/src/tools/createSpecFile.ts index b9071fa..0ec88d0 100644 --- a/src/tools/createSpecFile.ts +++ b/src/tools/createSpecFile.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createSpecFile'; export const description = @@ -30,7 +21,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}/files`; diff --git a/src/tools/createWorkspace.ts b/src/tools/createWorkspace.ts index 74cc0d5..7781faf 100644 --- a/src/tools/createWorkspace.ts +++ b/src/tools/createWorkspace.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createWorkspace'; export const description = @@ -40,7 +31,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/workspaces`; diff --git a/src/tools/deleteApiCollectionComment.ts b/src/tools/deleteApiCollectionComment.ts index eccfb80..ae11fae 100644 --- a/src/tools/deleteApiCollectionComment.ts +++ b/src/tools/deleteApiCollectionComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteApiCollectionComment'; export const description = @@ -30,7 +21,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/apis/${args.apiId}/collections/${args.collectionId}/comments/${args.commentId}`; diff --git a/src/tools/deleteCollection.ts b/src/tools/deleteCollection.ts index fb5af2b..4be1801 100644 --- a/src/tools/deleteCollection.ts +++ b/src/tools/deleteCollection.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteCollection'; export const description = 'Deletes a collection.'; @@ -30,7 +21,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}`; diff --git a/src/tools/deleteCollectionComment.ts b/src/tools/deleteCollectionComment.ts index df282f8..f521c0c 100644 --- a/src/tools/deleteCollectionComment.ts +++ b/src/tools/deleteCollectionComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteCollectionComment'; export const description = @@ -29,7 +20,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/comments/${args.commentId}`; diff --git a/src/tools/deleteCollectionFolder.ts b/src/tools/deleteCollectionFolder.ts index 3de3561..60b91cb 100644 --- a/src/tools/deleteCollectionFolder.ts +++ b/src/tools/deleteCollectionFolder.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteCollectionFolder'; export const description = 'Deletes a folder in a collection.'; @@ -27,7 +18,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/folders/${args.folderId}`; diff --git a/src/tools/deleteCollectionRequest.ts b/src/tools/deleteCollectionRequest.ts index b78e0e5..82a3919 100644 --- a/src/tools/deleteCollectionRequest.ts +++ b/src/tools/deleteCollectionRequest.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteCollectionRequest'; export const description = 'Deletes a request in a collection.'; @@ -27,7 +18,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/requests/${args.requestId}`; diff --git a/src/tools/deleteCollectionResponse.ts b/src/tools/deleteCollectionResponse.ts index bfd2beb..0d4b9c8 100644 --- a/src/tools/deleteCollectionResponse.ts +++ b/src/tools/deleteCollectionResponse.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteCollectionResponse'; export const description = 'Deletes a response in a collection.'; @@ -27,7 +18,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/responses/${args.responseId}`; diff --git a/src/tools/deleteEnvironment.ts b/src/tools/deleteEnvironment.ts index d054f21..40d3197 100644 --- a/src/tools/deleteEnvironment.ts +++ b/src/tools/deleteEnvironment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteEnvironment'; export const description = 'Deletes an environment.'; @@ -24,7 +15,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/environments/${args.environmentId}`; diff --git a/src/tools/deleteFolderComment.ts b/src/tools/deleteFolderComment.ts index 13e2119..4f600ef 100644 --- a/src/tools/deleteFolderComment.ts +++ b/src/tools/deleteFolderComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteFolderComment'; export const description = @@ -30,7 +21,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/folders/${args.folderId}/comments/${args.commentId}`; diff --git a/src/tools/deleteMock.ts b/src/tools/deleteMock.ts index 8692cb8..e06c901 100644 --- a/src/tools/deleteMock.ts +++ b/src/tools/deleteMock.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteMock'; export const description = @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/mocks/${args.mockId}`; diff --git a/src/tools/deleteMonitor.ts b/src/tools/deleteMonitor.ts index 49a6f1e..8a5ea65 100644 --- a/src/tools/deleteMonitor.ts +++ b/src/tools/deleteMonitor.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteMonitor'; export const description = 'Deletes a monitor.'; @@ -24,7 +15,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/monitors/${args.monitorId}`; diff --git a/src/tools/deletePanElementOrFolder.ts b/src/tools/deletePanElementOrFolder.ts index ebe17b4..b7ea2ee 100644 --- a/src/tools/deletePanElementOrFolder.ts +++ b/src/tools/deletePanElementOrFolder.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deletePanElementOrFolder'; export const description = @@ -33,7 +24,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/network/private/${args.elementType}/${args.elementId}`; diff --git a/src/tools/deleteRequestComment.ts b/src/tools/deleteRequestComment.ts index 88fae2f..223bfce 100644 --- a/src/tools/deleteRequestComment.ts +++ b/src/tools/deleteRequestComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteRequestComment'; export const description = @@ -30,7 +21,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/requests/${args.requestId}/comments/${args.commentId}`; diff --git a/src/tools/deleteResponseComment.ts b/src/tools/deleteResponseComment.ts index 069995c..aa74c41 100644 --- a/src/tools/deleteResponseComment.ts +++ b/src/tools/deleteResponseComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteResponseComment'; export const description = @@ -30,7 +21,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/responses/${args.responseId}/comments/${args.commentId}`; diff --git a/src/tools/deleteSpec.ts b/src/tools/deleteSpec.ts index 9580a12..509ea07 100644 --- a/src/tools/deleteSpec.ts +++ b/src/tools/deleteSpec.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteSpec'; export const description = @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}`; diff --git a/src/tools/deleteSpecFile.ts b/src/tools/deleteSpecFile.ts index 5c04d23..3c17abf 100644 --- a/src/tools/deleteSpecFile.ts +++ b/src/tools/deleteSpecFile.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteSpecFile'; export const description = @@ -29,7 +20,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}/files/${args.filePath}`; diff --git a/src/tools/deleteWorkspace.ts b/src/tools/deleteWorkspace.ts index 6f71b1a..5b4bc31 100644 --- a/src/tools/deleteWorkspace.ts +++ b/src/tools/deleteWorkspace.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'deleteWorkspace'; export const description = @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/workspaces/${args.workspaceId}`; diff --git a/src/tools/duplicateCollection.ts b/src/tools/duplicateCollection.ts index b028eac..07a6f32 100644 --- a/src/tools/duplicateCollection.ts +++ b/src/tools/duplicateCollection.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'duplicateCollection'; export const description = @@ -33,7 +24,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/duplicates`; diff --git a/src/tools/generateCollection.ts b/src/tools/generateCollection.ts index ff04884..79e2070 100644 --- a/src/tools/generateCollection.ts +++ b/src/tools/generateCollection.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'generateCollection'; export const description = @@ -91,7 +82,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}/generations/${args.elementType}`; diff --git a/src/tools/generateSpecFromCollection.ts b/src/tools/generateSpecFromCollection.ts index 4150672..083cd92 100644 --- a/src/tools/generateSpecFromCollection.ts +++ b/src/tools/generateSpecFromCollection.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'generateSpecFromCollection'; export const description = @@ -32,7 +23,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionUid}/generations/${args.elementType}`; diff --git a/src/tools/getAllElementsAndFolders.ts b/src/tools/getAllElementsAndFolders.ts index 24137c2..b92a4ff 100644 --- a/src/tools/getAllElementsAndFolders.ts +++ b/src/tools/getAllElementsAndFolders.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getAllElementsAndFolders'; export const description = @@ -104,7 +95,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/network/private`; diff --git a/src/tools/getAllPanAddElementRequests.ts b/src/tools/getAllPanAddElementRequests.ts index a0e686f..5f9b2e1 100644 --- a/src/tools/getAllPanAddElementRequests.ts +++ b/src/tools/getAllPanAddElementRequests.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getAllPanAddElementRequests'; export const description = @@ -81,7 +72,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/network/private/network-entity/request/all`; diff --git a/src/tools/getAllSpecs.ts b/src/tools/getAllSpecs.ts index 3f0a127..f5a09d4 100644 --- a/src/tools/getAllSpecs.ts +++ b/src/tools/getAllSpecs.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getAllSpecs'; export const description = 'Gets all API specifications in a workspace.'; @@ -37,7 +28,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs`; diff --git a/src/tools/getAsyncSpecTaskStatus.ts b/src/tools/getAsyncSpecTaskStatus.ts index f2c40ab..973d83c 100644 --- a/src/tools/getAsyncSpecTaskStatus.ts +++ b/src/tools/getAsyncSpecTaskStatus.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getAsyncSpecTaskStatus'; export const description = 'Gets the status of an asynchronous API specification creation task.'; @@ -28,7 +19,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/${args.elementType}/${args.elementId}/tasks/${args.taskId}`; diff --git a/src/tools/getAuthenticatedUser.ts b/src/tools/getAuthenticatedUser.ts index ad91e23..c072dcd 100644 --- a/src/tools/getAuthenticatedUser.ts +++ b/src/tools/getAuthenticatedUser.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getAuthenticatedUser'; export const description = @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/me`; diff --git a/src/tools/getCollection.ts b/src/tools/getCollection.ts index e9a3651..957b9c5 100644 --- a/src/tools/getCollection.ts +++ b/src/tools/getCollection.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollection'; export const description = @@ -44,7 +35,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}`; diff --git a/src/tools/getCollectionComments.ts b/src/tools/getCollectionComments.ts index 1c0a4f1..e1d2ffa 100644 --- a/src/tools/getCollectionComments.ts +++ b/src/tools/getCollectionComments.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionComments'; export const description = 'Gets all comments left by users in a collection.'; @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/comments`; diff --git a/src/tools/getCollectionFolder.ts b/src/tools/getCollectionFolder.ts index 8dec8bf..dc01925 100644 --- a/src/tools/getCollectionFolder.ts +++ b/src/tools/getCollectionFolder.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionFolder'; export const description = 'Gets information about a folder in a collection.'; @@ -36,7 +27,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/folders/${args.folderId}`; diff --git a/src/tools/getCollectionForks.ts b/src/tools/getCollectionForks.ts index 60b876a..4184ebd 100644 --- a/src/tools/getCollectionForks.ts +++ b/src/tools/getCollectionForks.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionForks'; export const description = @@ -45,7 +36,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/forks`; diff --git a/src/tools/getCollectionRequest.ts b/src/tools/getCollectionRequest.ts index 16cc677..bbb5b17 100644 --- a/src/tools/getCollectionRequest.ts +++ b/src/tools/getCollectionRequest.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionRequest'; export const description = 'Gets information about a request in a collection.'; @@ -36,7 +27,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/requests/${args.requestId}`; diff --git a/src/tools/getCollectionResponse.ts b/src/tools/getCollectionResponse.ts index bf711b7..005fd08 100644 --- a/src/tools/getCollectionResponse.ts +++ b/src/tools/getCollectionResponse.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionResponse'; export const description = 'Gets information about a response in a collection.'; @@ -36,7 +27,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/responses/${args.responseId}`; diff --git a/src/tools/getCollectionTags.ts b/src/tools/getCollectionTags.ts index 3415abf..f865f48 100644 --- a/src/tools/getCollectionTags.ts +++ b/src/tools/getCollectionTags.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionTags'; export const description = 'Gets all the tags associated with a collection.'; @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/tags`; diff --git a/src/tools/getCollectionUpdatesTasks.ts b/src/tools/getCollectionUpdatesTasks.ts index 8988c5e..59f9164 100644 --- a/src/tools/getCollectionUpdatesTasks.ts +++ b/src/tools/getCollectionUpdatesTasks.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionUpdatesTasks'; export const description = 'Gets the status of an asynchronous collection update task.'; @@ -24,7 +15,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collection-updates-tasks/${args.taskId}`; diff --git a/src/tools/getCollections.ts b/src/tools/getCollections.ts index 8771054..a7faf98 100644 --- a/src/tools/getCollections.ts +++ b/src/tools/getCollections.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollections'; export const description = @@ -41,7 +32,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections`; diff --git a/src/tools/getCollectionsForkedByUser.ts b/src/tools/getCollectionsForkedByUser.ts index 006b77e..ad60d22 100644 --- a/src/tools/getCollectionsForkedByUser.ts +++ b/src/tools/getCollectionsForkedByUser.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionsForkedByUser'; export const description = "Gets a list of all the authenticated user's forked collections."; @@ -42,7 +33,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/collection-forks`; diff --git a/src/tools/getDuplicateCollectionTaskStatus.ts b/src/tools/getDuplicateCollectionTaskStatus.ts index aefc06c..a6b802a 100644 --- a/src/tools/getDuplicateCollectionTaskStatus.ts +++ b/src/tools/getDuplicateCollectionTaskStatus.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getDuplicateCollectionTaskStatus'; export const description = 'Gets the status of a collection duplication task.'; @@ -24,7 +15,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collection-duplicate-tasks/${args.taskId}`; diff --git a/src/tools/getEnabledTools.ts b/src/tools/getEnabledTools.ts new file mode 100644 index 0000000..79d84cc --- /dev/null +++ b/src/tools/getEnabledTools.ts @@ -0,0 +1,64 @@ +import { z } from 'zod'; +import { PostmanAPIClient } from '../clients/postman.js'; +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { enabledResources } from '../enabledResources.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; + +export const method = 'getEnabledTools'; +export const description = + 'IMPORTANT: Run this tool first when a requested tool is unavailable. Returns information about which tools are enabled in the full and minimal tool sets, helping you identify available alternatives.'; + +export const parameters = z.object({}); + +export const annotations = { + title: 'Get Enabled Tools', + readOnlyHint: true, + destructiveHint: false, + idempotentHint: true, +}; + +export async function handler( + _args: z.infer, + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } +): Promise { + try { + return { + content: [ + { + type: 'text', + text: JSON.stringify( + { + serverInfo: extra.serverContext + ? { + serverType: extra.serverContext.serverType, + currentServerTools: extra.serverContext.availableTools, + currentServerToolCount: extra.serverContext.availableTools.length, + } + : { + serverType: 'unknown', + note: 'Server context not available', + }, + enabledTools: { + full: Array.from(enabledResources.full), + minimal: Array.from(enabledResources.minimal), + excludedFromGeneration: Array.from(enabledResources.excludedFromGeneration), + }, + stats: { + totalFull: enabledResources.full.length, + totalMinimal: enabledResources.minimal.length, + totalExcludedFromGeneration: enabledResources.excludedFromGeneration.length, + }, + }, + null, + 2 + ), + }, + ], + }; + } catch (e: unknown) { + if (e instanceof McpError) { + throw e; + } + throw asMcpError(e); + } +} diff --git a/src/tools/getEnvironment.ts b/src/tools/getEnvironment.ts index 77c36c6..e308634 100644 --- a/src/tools/getEnvironment.ts +++ b/src/tools/getEnvironment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getEnvironment'; export const description = 'Gets information about an environment.'; @@ -24,7 +15,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/environments/${args.environmentId}`; diff --git a/src/tools/getEnvironments.ts b/src/tools/getEnvironments.ts index 1ba9485..aa325f8 100644 --- a/src/tools/getEnvironments.ts +++ b/src/tools/getEnvironments.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getEnvironments'; export const description = @@ -28,7 +19,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/environments`; diff --git a/src/tools/getFolderComments.ts b/src/tools/getFolderComments.ts index 56a8d3c..54805e8 100644 --- a/src/tools/getFolderComments.ts +++ b/src/tools/getFolderComments.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getFolderComments'; export const description = 'Gets all comments left by users in a folder.'; @@ -27,7 +18,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/folders/${args.folderId}/comments`; diff --git a/src/tools/getGeneratedCollectionSpecs.ts b/src/tools/getGeneratedCollectionSpecs.ts index 3a41abb..489e1fd 100644 --- a/src/tools/getGeneratedCollectionSpecs.ts +++ b/src/tools/getGeneratedCollectionSpecs.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getGeneratedCollectionSpecs'; export const description = 'Gets the API specification generated for the given collection.'; @@ -27,7 +18,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionUid}/generations/${args.elementType}`; diff --git a/src/tools/getMock.ts b/src/tools/getMock.ts index 26a9e48..8c677b7 100644 --- a/src/tools/getMock.ts +++ b/src/tools/getMock.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getMock'; export const description = @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/mocks/${args.mockId}`; diff --git a/src/tools/getMocks.ts b/src/tools/getMocks.ts index 64b76c7..8d888bb 100644 --- a/src/tools/getMocks.ts +++ b/src/tools/getMocks.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getMocks'; export const description = @@ -39,7 +30,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/mocks`; diff --git a/src/tools/getMonitor.ts b/src/tools/getMonitor.ts index 4132a9f..28aa1a2 100644 --- a/src/tools/getMonitor.ts +++ b/src/tools/getMonitor.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getMonitor'; export const description = 'Gets information about a monitor.'; @@ -24,7 +15,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/monitors/${args.monitorId}`; diff --git a/src/tools/getMonitors.ts b/src/tools/getMonitors.ts index 751f4f9..a8f9cbd 100644 --- a/src/tools/getMonitors.ts +++ b/src/tools/getMonitors.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getMonitors'; export const description = 'Gets all monitors.'; @@ -50,7 +41,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/monitors`; diff --git a/src/tools/getRequestComments.ts b/src/tools/getRequestComments.ts index 3e29099..8cf39d5 100644 --- a/src/tools/getRequestComments.ts +++ b/src/tools/getRequestComments.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getRequestComments'; export const description = 'Gets all comments left by users in a request.'; @@ -31,7 +22,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/requests/${args.requestId}/comments`; diff --git a/src/tools/getResponseComments.ts b/src/tools/getResponseComments.ts index d404472..f9882d5 100644 --- a/src/tools/getResponseComments.ts +++ b/src/tools/getResponseComments.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getResponseComments'; export const description = 'Gets all comments left by users in a response.'; @@ -27,7 +18,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/responses/${args.responseId}/comments`; diff --git a/src/tools/getSourceCollectionStatus.ts b/src/tools/getSourceCollectionStatus.ts index f43ba28..7cd2b3c 100644 --- a/src/tools/getSourceCollectionStatus.ts +++ b/src/tools/getSourceCollectionStatus.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSourceCollectionStatus'; export const description = @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/source-status`; diff --git a/src/tools/getSpec.ts b/src/tools/getSpec.ts index 2cb8741..2887705 100644 --- a/src/tools/getSpec.ts +++ b/src/tools/getSpec.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSpec'; export const description = 'Gets information about an API specification.'; @@ -24,7 +15,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}`; diff --git a/src/tools/getSpecCollections.ts b/src/tools/getSpecCollections.ts index 9857da7..b53f067 100644 --- a/src/tools/getSpecCollections.ts +++ b/src/tools/getSpecCollections.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSpecCollections'; export const description = "Gets all of an API specification's generated collections."; @@ -38,7 +29,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}/generations/${args.elementType}`; diff --git a/src/tools/getSpecDefinition.ts b/src/tools/getSpecDefinition.ts index d410554..da98daa 100644 --- a/src/tools/getSpecDefinition.ts +++ b/src/tools/getSpecDefinition.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSpecDefinition'; export const description = "Gets the complete contents of an API specification's definition."; @@ -24,7 +15,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}/definitions`; diff --git a/src/tools/getSpecFile.ts b/src/tools/getSpecFile.ts index 33ad4d1..21d6623 100644 --- a/src/tools/getSpecFile.ts +++ b/src/tools/getSpecFile.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSpecFile'; export const description = "Gets the contents of an API specification's file."; @@ -27,7 +18,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}/files/${args.filePath}`; diff --git a/src/tools/getSpecFiles.ts b/src/tools/getSpecFiles.ts index c6c2dec..03a1116 100644 --- a/src/tools/getSpecFiles.ts +++ b/src/tools/getSpecFiles.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getSpecFiles'; export const description = 'Gets all the files in an API specification.'; @@ -24,7 +15,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}/files`; diff --git a/src/tools/getStatusOfAnAsyncApiTask.ts b/src/tools/getStatusOfAnAsyncApiTask.ts index 2307cc4..a889a60 100644 --- a/src/tools/getStatusOfAnAsyncApiTask.ts +++ b/src/tools/getStatusOfAnAsyncApiTask.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getStatusOfAnAsyncApiTask'; export const description = 'Gets the status of an asynchronous task.'; @@ -30,7 +21,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/apis/${args.apiId}/tasks/${args.taskId}`; diff --git a/src/tools/getTaggedEntities.ts b/src/tools/getTaggedEntities.ts index f373734..91c03f3 100644 --- a/src/tools/getTaggedEntities.ts +++ b/src/tools/getTaggedEntities.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getTaggedEntities'; export const description = @@ -55,7 +46,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/tags/${args.slug}/entities`; diff --git a/src/tools/getWorkspace.ts b/src/tools/getWorkspace.ts index 4aabe2d..abaf66d 100644 --- a/src/tools/getWorkspace.ts +++ b/src/tools/getWorkspace.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getWorkspace'; export const description = @@ -34,7 +25,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/workspaces/${args.workspaceId}`; diff --git a/src/tools/getWorkspaceGlobalVariables.ts b/src/tools/getWorkspaceGlobalVariables.ts index f1a7b64..61a9157 100644 --- a/src/tools/getWorkspaceGlobalVariables.ts +++ b/src/tools/getWorkspaceGlobalVariables.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getWorkspaceGlobalVariables'; export const description = @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/workspaces/${args.workspaceId}/global-variables`; diff --git a/src/tools/getWorkspaceTags.ts b/src/tools/getWorkspaceTags.ts index d782d8b..fc8d363 100644 --- a/src/tools/getWorkspaceTags.ts +++ b/src/tools/getWorkspaceTags.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getWorkspaceTags'; export const description = 'Gets all the tags associated with a workspace.'; @@ -24,7 +15,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/workspaces/${args.workspaceId}/tags`; diff --git a/src/tools/getWorkspaces.ts b/src/tools/getWorkspaces.ts index 0747db8..4257e67 100644 --- a/src/tools/getWorkspaces.ts +++ b/src/tools/getWorkspaces.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getWorkspaces'; export const description = @@ -46,7 +37,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/workspaces`; diff --git a/src/tools/mergeCollectionFork.ts b/src/tools/mergeCollectionFork.ts index 2b61172..c316735 100644 --- a/src/tools/mergeCollectionFork.ts +++ b/src/tools/mergeCollectionFork.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'mergeCollectionFork'; export const description = @@ -35,7 +26,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/merge`; diff --git a/src/tools/patchCollection.ts b/src/tools/patchCollection.ts index 84ecf6c..4c5b25f 100644 --- a/src/tools/patchCollection.ts +++ b/src/tools/patchCollection.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'patchCollection'; export const description = @@ -81,7 +72,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -101,7 +92,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -123,7 +114,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -145,7 +136,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -167,7 +158,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -189,7 +180,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -211,7 +202,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -233,7 +224,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -255,7 +246,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -277,7 +268,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -299,7 +290,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -321,7 +312,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -388,7 +379,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}`; diff --git a/src/tools/patchEnvironment.ts b/src/tools/patchEnvironment.ts index 23e37eb..2d3e5ee 100644 --- a/src/tools/patchEnvironment.ts +++ b/src/tools/patchEnvironment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'patchEnvironment'; export const description = @@ -84,7 +75,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/environments/${args.environmentId}`; diff --git a/src/tools/postPanElementOrFolder.ts b/src/tools/postPanElementOrFolder.ts index 2521258..efc03ee 100644 --- a/src/tools/postPanElementOrFolder.ts +++ b/src/tools/postPanElementOrFolder.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'postPanElementOrFolder'; export const description = @@ -74,7 +65,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/network/private`; diff --git a/src/tools/publishDocumentation.ts b/src/tools/publishDocumentation.ts index 9224d80..94b940b 100644 --- a/src/tools/publishDocumentation.ts +++ b/src/tools/publishDocumentation.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'publishDocumentation'; export const description = @@ -124,7 +115,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/public-documentations`; diff --git a/src/tools/publishMock.ts b/src/tools/publishMock.ts index e9f1c87..2819d78 100644 --- a/src/tools/publishMock.ts +++ b/src/tools/publishMock.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'publishMock'; export const description = @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/mocks/${args.mockId}/publish`; diff --git a/src/tools/pullCollectionChanges.ts b/src/tools/pullCollectionChanges.ts index e9d114f..8f2f69c 100644 --- a/src/tools/pullCollectionChanges.ts +++ b/src/tools/pullCollectionChanges.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'pullCollectionChanges'; export const description = @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/pulls`; diff --git a/src/tools/putCollection.ts b/src/tools/putCollection.ts index e14f7e1..20eaa0e 100644 --- a/src/tools/putCollection.ts +++ b/src/tools/putCollection.ts @@ -1,11 +1,7 @@ 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); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'putCollection'; export const description = @@ -195,7 +191,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -215,7 +211,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -237,7 +233,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -259,7 +255,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -281,7 +277,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -303,7 +299,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -325,7 +321,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -347,7 +343,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -369,7 +365,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -391,7 +387,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -413,7 +409,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -435,7 +431,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -510,7 +506,7 @@ export const parameters = z.object({ .optional(), formdata: z .array( - z.record(z.any()).and( + z.record(z.string(), z.unknown()).and( z.union([ z.object({ key: z.string().describe('The key value.').optional(), @@ -529,7 +525,7 @@ export const parameters = z.object({ z.object({ key: z.string().describe('The key value.').optional(), src: z - .any() + .unknown() .superRefine((x, ctx) => { const schemas = [z.string().nullable(), z.array(z.string())]; const errors = schemas.reduce( @@ -596,7 +592,7 @@ export const parameters = z.object({ ) .optional(), options: z - .record(z.any()) + .record(z.string(), z.unknown()) .describe('Additional configurations and options set for various modes.') .optional(), }) @@ -605,10 +601,10 @@ export const parameters = z.object({ }) .describe('Information about the collection request.') .optional(), - // response: z - // .array(z.any().describe("Information about the request's response.")) - // .describe("A list of the collection's responses.") - // .optional(), + response: z + .array(z.unknown().describe("Information about the request's response.")) + .describe("A list of the collection's responses.") + .optional(), protocolProfileBehavior: z .object({ strictSSL: z @@ -784,7 +780,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -804,7 +800,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -826,7 +822,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -848,7 +844,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -870,7 +866,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -892,7 +888,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -914,7 +910,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -936,7 +932,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -958,7 +954,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -980,7 +976,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -1002,7 +998,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -1024,7 +1020,7 @@ export const parameters = z.object({ .object({ key: z.string().describe("The auth method's key value."), value: z - .union([z.string(), z.array(z.record(z.any()))]) + .union([z.string(), z.array(z.record(z.string(), z.unknown()))]) .describe("The key's value.") .optional(), type: z @@ -1139,15 +1135,15 @@ export const annotations = { }; export async function handler( - params: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } -): Promise<{ content: Array<{ type: string; text: string } & Record> }> { + args: z.infer, + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } +): Promise { try { - const endpoint = `/collections/${params.collectionId}`; + const endpoint = `/collections/${args.collectionId}`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload: any = {}; - if (params.collection !== undefined) bodyPayload.collection = params.collection; + if (args.collection !== undefined) bodyPayload.collection = args.collection; const options: any = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, diff --git a/src/tools/putEnvironment.ts b/src/tools/putEnvironment.ts index cc67771..c8659a2 100644 --- a/src/tools/putEnvironment.ts +++ b/src/tools/putEnvironment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'putEnvironment'; export const description = @@ -53,7 +44,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/environments/${args.environmentId}`; diff --git a/src/tools/resolveCommentThread.ts b/src/tools/resolveCommentThread.ts index 969119f..0fced51 100644 --- a/src/tools/resolveCommentThread.ts +++ b/src/tools/resolveCommentThread.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'resolveCommentThread'; export const description = @@ -28,7 +19,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/comments-resolutions/${args.threadId}`; diff --git a/src/tools/runCollection.ts b/src/tools/runCollection.ts index b239762..68ea851 100644 --- a/src/tools/runCollection.ts +++ b/src/tools/runCollection.ts @@ -1,18 +1,9 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; import newman from 'newman'; import { TestTracker, OutputBuilder, buildNewmanOptions } from './utils/runner.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'runCollection'; export const description = @@ -55,7 +46,7 @@ export const annotations = { export async function handler( params: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const tracker = new TestTracker(); diff --git a/src/tools/runMonitor.ts b/src/tools/runMonitor.ts index 1074659..702ba29 100644 --- a/src/tools/runMonitor.ts +++ b/src/tools/runMonitor.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'runMonitor'; export const description = @@ -34,7 +25,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/monitors/${args.monitorId}/run`; diff --git a/src/tools/syncCollectionWithSpec.ts b/src/tools/syncCollectionWithSpec.ts index be56b42..6d32ddd 100644 --- a/src/tools/syncCollectionWithSpec.ts +++ b/src/tools/syncCollectionWithSpec.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'syncCollectionWithSpec'; export const description = @@ -29,7 +20,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionUid}/synchronizations`; diff --git a/src/tools/syncSpecWithCollection.ts b/src/tools/syncSpecWithCollection.ts index 55455e6..9e9fd89 100644 --- a/src/tools/syncSpecWithCollection.ts +++ b/src/tools/syncSpecWithCollection.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'syncSpecWithCollection'; export const description = @@ -29,7 +20,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}/synchronizations`; diff --git a/src/tools/transferCollectionFolders.ts b/src/tools/transferCollectionFolders.ts index ecfa201..56f368c 100644 --- a/src/tools/transferCollectionFolders.ts +++ b/src/tools/transferCollectionFolders.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'transferCollectionFolders'; export const description = 'Copies or moves folders into a collection or folder.'; @@ -61,7 +52,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collection-folders-transfers`; diff --git a/src/tools/transferCollectionRequests.ts b/src/tools/transferCollectionRequests.ts index deb87c0..758f067 100644 --- a/src/tools/transferCollectionRequests.ts +++ b/src/tools/transferCollectionRequests.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'transferCollectionRequests'; export const description = 'Copies or moves requests into a collection or folder.'; @@ -61,7 +52,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collection-requests-transfers`; diff --git a/src/tools/transferCollectionResponses.ts b/src/tools/transferCollectionResponses.ts index f5ee01f..59d458a 100644 --- a/src/tools/transferCollectionResponses.ts +++ b/src/tools/transferCollectionResponses.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'transferCollectionResponses'; export const description = 'Copies or moves responses into a request.'; @@ -61,7 +52,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collection-responses-transfers`; diff --git a/src/tools/unpublishDocumentation.ts b/src/tools/unpublishDocumentation.ts index ec3d128..da506e8 100644 --- a/src/tools/unpublishDocumentation.ts +++ b/src/tools/unpublishDocumentation.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'unpublishDocumentation'; export const description = @@ -28,7 +19,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/public-documentations`; diff --git a/src/tools/unpublishMock.ts b/src/tools/unpublishMock.ts index d83ec50..00d533e 100644 --- a/src/tools/unpublishMock.ts +++ b/src/tools/unpublishMock.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'unpublishMock'; export const description = @@ -26,7 +17,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/mocks/${args.mockId}/unpublish`; diff --git a/src/tools/updateApiCollectionComment.ts b/src/tools/updateApiCollectionComment.ts index 2912607..36bf33a 100644 --- a/src/tools/updateApiCollectionComment.ts +++ b/src/tools/updateApiCollectionComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateApiCollectionComment'; export const description = @@ -45,7 +36,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/apis/${args.apiId}/collections/${args.collectionId}/comments/${args.commentId}`; diff --git a/src/tools/updateCollectionComment.ts b/src/tools/updateCollectionComment.ts index 852c22b..ce2dbf3 100644 --- a/src/tools/updateCollectionComment.ts +++ b/src/tools/updateCollectionComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateCollectionComment'; export const description = @@ -44,7 +35,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/comments/${args.commentId}`; diff --git a/src/tools/updateCollectionFolder.ts b/src/tools/updateCollectionFolder.ts index 088a35c..f929ab0 100644 --- a/src/tools/updateCollectionFolder.ts +++ b/src/tools/updateCollectionFolder.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateCollectionFolder'; export const description = @@ -31,7 +22,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/folders/${args.folderId}`; diff --git a/src/tools/updateCollectionRequest.ts b/src/tools/updateCollectionRequest.ts index 1830a6f..07ebe23 100644 --- a/src/tools/updateCollectionRequest.ts +++ b/src/tools/updateCollectionRequest.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateCollectionRequest'; export const description = @@ -50,7 +41,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/requests/${args.requestId}`; diff --git a/src/tools/updateCollectionResponse.ts b/src/tools/updateCollectionResponse.ts index 30dada7..0290e8d 100644 --- a/src/tools/updateCollectionResponse.ts +++ b/src/tools/updateCollectionResponse.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateCollectionResponse'; export const description = @@ -37,7 +28,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/responses/${args.responseId}`; diff --git a/src/tools/updateCollectionTags.ts b/src/tools/updateCollectionTags.ts index 0b04c55..b37b230 100644 --- a/src/tools/updateCollectionTags.ts +++ b/src/tools/updateCollectionTags.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateCollectionTags'; export const description = @@ -44,7 +35,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/tags`; diff --git a/src/tools/updateFolderComment.ts b/src/tools/updateFolderComment.ts index dd3a442..70df244 100644 --- a/src/tools/updateFolderComment.ts +++ b/src/tools/updateFolderComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateFolderComment'; export const description = @@ -45,7 +36,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/folders/${args.folderId}/comments/${args.commentId}`; diff --git a/src/tools/updateMock.ts b/src/tools/updateMock.ts index d40173e..d4851ab 100644 --- a/src/tools/updateMock.ts +++ b/src/tools/updateMock.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateMock'; export const description = @@ -57,7 +48,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/mocks/${args.mockId}`; diff --git a/src/tools/updateMonitor.ts b/src/tools/updateMonitor.ts index 4437304..06c0dcb 100644 --- a/src/tools/updateMonitor.ts +++ b/src/tools/updateMonitor.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateMonitor'; export const description = @@ -143,7 +134,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/monitors/${args.monitorId}`; diff --git a/src/tools/updatePanElementOrFolder.ts b/src/tools/updatePanElementOrFolder.ts index 1ddd2b7..cd13f9e 100644 --- a/src/tools/updatePanElementOrFolder.ts +++ b/src/tools/updatePanElementOrFolder.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updatePanElementOrFolder'; export const description = @@ -88,7 +79,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/network/private/${args.elementType}/${args.elementId}`; diff --git a/src/tools/updateRequestComment.ts b/src/tools/updateRequestComment.ts index 54dcd4c..3146c78 100644 --- a/src/tools/updateRequestComment.ts +++ b/src/tools/updateRequestComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateRequestComment'; export const description = @@ -45,7 +36,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/requests/${args.requestId}/comments/${args.commentId}`; diff --git a/src/tools/updateResponseComment.ts b/src/tools/updateResponseComment.ts index 97099aa..90ee51e 100644 --- a/src/tools/updateResponseComment.ts +++ b/src/tools/updateResponseComment.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateResponseComment'; export const description = @@ -45,7 +36,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/collections/${args.collectionId}/responses/${args.responseId}/comments/${args.commentId}`; diff --git a/src/tools/updateSpecFile.ts b/src/tools/updateSpecFile.ts index 25381ab..97eacae 100644 --- a/src/tools/updateSpecFile.ts +++ b/src/tools/updateSpecFile.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateSpecFile'; export const description = @@ -37,7 +28,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}/files/${args.filePath}`; diff --git a/src/tools/updateSpecProperties.ts b/src/tools/updateSpecProperties.ts index 3b00b34..01e99e2 100644 --- a/src/tools/updateSpecProperties.ts +++ b/src/tools/updateSpecProperties.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateSpecProperties'; export const description = "Updates an API specification's properties, such as its name."; @@ -27,7 +18,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/specs/${args.specId}`; diff --git a/src/tools/updateWorkspace.ts b/src/tools/updateWorkspace.ts index d6db549..ad02024 100644 --- a/src/tools/updateWorkspace.ts +++ b/src/tools/updateWorkspace.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateWorkspace'; export const description = @@ -41,7 +32,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/workspaces/${args.workspaceId}`; diff --git a/src/tools/updateWorkspaceGlobalVariables.ts b/src/tools/updateWorkspaceGlobalVariables.ts index 523e132..1275dd5 100644 --- a/src/tools/updateWorkspaceGlobalVariables.ts +++ b/src/tools/updateWorkspaceGlobalVariables.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateWorkspaceGlobalVariables'; export const description = @@ -47,7 +38,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/workspaces/${args.workspaceId}/global-variables`; diff --git a/src/tools/updateWorkspaceTags.ts b/src/tools/updateWorkspaceTags.ts index efc228c..19b90f9 100644 --- a/src/tools/updateWorkspaceTags.ts +++ b/src/tools/updateWorkspaceTags.ts @@ -1,16 +1,7 @@ import { z } from 'zod'; import { PostmanAPIClient, ContentType } from '../clients/postman.js'; -import { - IsomorphicHeaders, - McpError, - ErrorCode, - CallToolResult, -} from '@modelcontextprotocol/sdk/types.js'; - -function asMcpError(error: unknown): McpError { - const cause = (error as any)?.cause ?? String(error); - return new McpError(ErrorCode.InternalError, cause); -} +import { IsomorphicHeaders, CallToolResult } from '@modelcontextprotocol/sdk/types.js'; +import { ServerContext, asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'updateWorkspaceTags'; export const description = @@ -44,7 +35,7 @@ export const annotations = { export async function handler( args: z.infer, - extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders } + extra: { client: PostmanAPIClient; headers?: IsomorphicHeaders; serverContext?: ServerContext } ): Promise { try { const endpoint = `/workspaces/${args.workspaceId}/tags`; diff --git a/src/tools/utils/toolHelpers.ts b/src/tools/utils/toolHelpers.ts new file mode 100644 index 0000000..41843c0 --- /dev/null +++ b/src/tools/utils/toolHelpers.ts @@ -0,0 +1,14 @@ +import { McpError, ErrorCode } from '@modelcontextprotocol/sdk/types.js'; + +// Re-export McpError for use in tool handlers +export { McpError }; + +export interface ServerContext { + serverType: 'full' | 'minimal'; + availableTools: string[]; +} + +export function asMcpError(error: unknown): McpError { + const cause = (error as any)?.cause ?? String(error); + return new McpError(ErrorCode.InternalError, cause); +}