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)

95 lines (94 loc) • 4.45 kB
import { z } from 'zod'; import { asMcpError, McpError } from './utils/toolHelpers.js'; export const method = 'listPrivateNetworkAddRequests'; export const title = 'Get Private API Network add requests'; export const description = "Gets all requests to add workspaces to your team's Private API Network.\n\nWARNING: This tool is for Private API Network management, not for general workspace operations. For workspace management use: getWorkspaces, getWorkspace, createWorkspace, updateWorkspace, deleteWorkspace.\n"; export const parameters = z.object({ since: z .string() .datetime({ offset: true }) .describe('Return only results created since the given time, in [ISO 8601](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format. This value cannot be later than the `until` value. To use `time-numoffset` format, you must use `%2B` URL-encoding for the `+` character.') .optional(), until: z .string() .datetime({ offset: true }) .describe('Return only results created until this given time, in [ISO 8601](https://datatracker.ietf.org/doc/html/rfc3339#section-5.6) format. This value cannot be earlier than the `since` value. To use `time-numoffset` format, you must use `%2B` URL-encoding for the `+` character.') .optional(), requestedBy: z.number().int().describe("Return a user's requests by their user ID.").optional(), type: z.literal('workspace').describe('The `workspace` value.').optional(), status: z.enum(['pending', 'denied']).describe('Filter by the request status.').optional(), name: z .string() .describe('Return only workspaces whose name includes the given value. Matching is not case-sensitive.') .optional(), sort: z .enum(['createdAt', 'updatedAt']) .describe('Sort the results by the given value. If you use this query parameter, you must also use the `direction` parameter.') .optional(), direction: z .enum(['asc', 'desc']) .describe('Sort in ascending (`asc`) or descending (`desc`) order. Matching is not case-sensitive. If you use this query parameter, you must also use the `sort` parameter.') .optional(), offset: z .number() .int() .describe('The zero-based offset of the first item to return.') .default(0), limit: z .number() .int() .describe('The maximum number of results to return. If the value exceeds the maximum value of `1000`, then the system uses the `1000` value.') .default(1000), }); export const annotations = { title: 'Get Private API Network add requests', readOnlyHint: true, openWorldHint: false, destructiveHint: false, idempotentHint: true, }; export async function handler(args, extra) { try { const endpoint = `/network/private/network-entity/request/all`; const query = new URLSearchParams(); if (args.since !== undefined) query.set('since', String(args.since)); if (args.until !== undefined) query.set('until', String(args.until)); if (args.requestedBy !== undefined) query.set('requestedBy', String(args.requestedBy)); if (args.type !== undefined) query.set('type', String(args.type)); if (args.status !== undefined) query.set('status', String(args.status)); if (args.name !== undefined) query.set('name', String(args.name)); if (args.sort !== undefined) query.set('sort', String(args.sort)); if (args.direction !== undefined) query.set('direction', String(args.direction)); if (args.offset !== undefined) query.set('offset', String(args.offset)); if (args.limit !== undefined) query.set('limit', String(args.limit)); 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); } }