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)

57 lines (56 loc) • 2.08 kB
import { z } from 'zod'; import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'getCollectionRequest'; export const title = 'Get a collection request'; export const description = 'Gets information about a request in a collection.'; export const parameters = z.object({ requestId: z.string().describe("The request's ID."), collectionId: z.string().describe("The collection's ID."), ids: z .boolean() .describe('If true, returns only properties that contain ID values in the response.') .optional(), uid: z.boolean().describe('If true, returns all IDs in UID format (`userId`-`id`).').optional(), populate: z .boolean() .describe("If true, returns all of the collection item's contents.") .optional(), }); export const annotations = { title: 'Get a collection request', readOnlyHint: true, openWorldHint: false, destructiveHint: false, idempotentHint: true, }; export async function handler(args, extra) { try { const endpoint = `/collections/${encodeURIComponent(String(args.collectionId))}/requests/${encodeURIComponent(String(args.requestId))}`; const query = new URLSearchParams(); if (args.ids !== undefined) query.set('ids', String(args.ids)); if (args.uid !== undefined) query.set('uid', String(args.uid)); if (args.populate !== undefined) query.set('populate', String(args.populate)); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const options = { headers: extra.headers, }; const result = await extra.client.get(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); } }