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)

49 lines (48 loc) • 1.96 kB
import { z } from 'zod'; import { McpError, asMcpError, defineToolAnnotations, } from '../utils/toolHelpers.js'; import { handler as getCollectionApiHandler, parameters as getCollectionApiParameters, } from './getCollection.js'; import { handler as getCollectionMapHandler } from './getCollectionMap.js'; export const method = 'getCollection'; export const title = 'Get a collection (map by default)'; export const description = `Get information about a collection. By default this tool returns the lightweight collection map (metadata + recursive itemRefs). Use the model parameter to opt in to Postman's full API responses: - model=minimal — root-level folder/request IDs only - model=full — full Postman collection payload.`; const baseParameters = getCollectionApiParameters.pick({ collectionId: true, access_key: true, }); export const parameters = baseParameters.extend({ model: z .enum(['minimal', 'full']) .describe('Optional response shape override. Omit to receive the lightweight collection map. Set to `minimal` for the Postman minimal model or `full` for the complete collection payload.') .optional(), }); export const annotations = defineToolAnnotations({ title: 'Get a collection (map by default)', readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }); function omitModel(args) { const { model: _ignored, ...rest } = args; return rest; } export async function handler(args, extra) { try { if (!args.model) { return await getCollectionMapHandler(omitModel(args), extra); } if (args.model === 'minimal') { return await getCollectionApiHandler({ ...args, model: 'minimal' }, extra); } return await getCollectionApiHandler(omitModel(args), extra); } catch (e) { if (e instanceof McpError) { throw e; } throw asMcpError(e); } }