UNPKG

@postman/postman-mcp-server

Version:

Postman MCP Server — connect AI agents (Claude Code, Cursor, VS Code Copilot, Gemini CLI) to your Postman collections, specifications, and environments via Model Context Protocol (MCP)

82 lines (81 loc) • 3.29 kB
import { z } from 'zod'; import { ContentType } from '../clients/postman.js'; import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'transferCollectionRequests'; export const title = 'Transfer collection requests'; export const description = 'Copies or moves requests into a collection or folder.'; export const parameters = z.object({ ids: z .array(z.string()) .describe('A list of collection request, response, or folder UIDs to transfer.'), mode: z.enum(['copy', 'move']).describe('The transfer operation to perform.'), target: z .object({ id: z.string().describe('The UID of the destination collection, folder, or request.'), model: z .enum(['collection', 'folder', 'request']) .describe('The collection, folder, or request that the items will be transferred to. For response transfers, use the `request` value.'), }) .describe("Information about the item transfer's destination location."), location: z .object({ id: z .string() .nullable() .describe("For `before` or `after` positions, the model's UID.") .optional(), model: z .string() .nullable() .describe('For `before` or `after` positions, the type of item (model) that the transferred item will be positioned by. One of: `folder`, `request`, or `response.`\n') .optional(), position: z .enum(['start', 'end', 'before', 'after']) .describe("The transferred item's position within the destination object.") .default('end'), }) .describe("The transferred items' placement in the target destination:\n- For `start` or `end` — Do not include the `model` and `id` values.\n- For `before` or `after` — Include the `model` and `id` properties.\n"), }); export const annotations = { title: 'Transfer collection requests', readOnlyHint: false, openWorldHint: true, destructiveHint: false, idempotentHint: false, }; export async function handler(args, extra) { try { const endpoint = `/collection-requests-transfers`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload = {}; if (args.ids !== undefined) bodyPayload.ids = args.ids; if (args.mode !== undefined) bodyPayload.mode = args.mode; if (args.target !== undefined) bodyPayload.target = args.target; if (args.location !== undefined) bodyPayload.location = args.location; const options = { body: JSON.stringify(bodyPayload), contentType: ContentType.Json, headers: extra.headers, }; const result = await extra.client.post(url, options); return { content: [ { type: 'text', text: `${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}`, }, ], }; } catch (e) { if (e instanceof McpError) { throw e; } throw asMcpError(e); } }