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)

72 lines (71 loc) • 3.33 kB
import { z } from 'zod'; import { ContentType } from '../clients/postman.js'; import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'createRequestComment'; export const title = 'Create a request comment'; 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({ collectionId: z.string().describe("The collection's unique ID."), requestId: z .string() .describe("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"), body: z.string().describe('The contents of the comment.'), threadId: z .number() .int() .describe("The comment's thread ID. To create a reply on an existing comment, include this property.") .optional(), tags: z .object({ '{{userName}}': z .object({ type: z.literal('user').describe('The `user` value.'), id: z.string().describe("The user's ID."), }) .describe("An object that contains information about the tagged user. The object's name is the user's Postman username. For example, `@user-postman`.") .optional(), }) .describe('Information about users tagged in the `body` comment.') .optional(), }); export const annotations = { title: 'Create a request comment', readOnlyHint: false, openWorldHint: true, destructiveHint: false, idempotentHint: false, }; export async function handler(args, extra) { try { const endpoint = `/collections/${encodeURIComponent(String(args.collectionId))}/requests/${encodeURIComponent(String(args.requestId))}/comments`; const query = new URLSearchParams(); const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint; const bodyPayload = {}; if (args.body !== undefined) bodyPayload.body = args.body; if (args.threadId !== undefined) bodyPayload.threadId = args.threadId; if (args.tags !== undefined) bodyPayload.tags = args.tags; 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); } }