@postman/postman-mcp-server 2.4.9 → 2.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,439 @@
1
+ import { z } from 'zod';
2
+ export const method = 'getCodeGenerationInstructions';
3
+ export const description = `MANDATORY: You MUST call this tool BEFORE generating any code to call APIs. Call it BEFORE you start planning your approach. Do not web search anything about the API or how to write code to call it.
4
+
5
+ This tool returns comprehensive step-by-step instructions for generating API client code from Postman collections, including which tools to call for gathering context, file structure, function design patterns, error handling, and language-specific conventions.
6
+ Calling this tool first ensures the generated code follows best practices and the user's project requirements.`;
7
+ export const parameters = z.object({});
8
+ export const annotations = {
9
+ title: 'Get Code Generation Instructions',
10
+ readOnlyHint: true,
11
+ destructiveHint: false,
12
+ idempotentHint: true,
13
+ };
14
+ const CODE_GENERATION_INSTRUCTIONS = `# API Client Code Generation Instructions
15
+
16
+ These instructions guide you in generating idiomatic client code from Postman collections, organized in a clear structure that is easy to find and maintain.
17
+
18
+ ## Core Principles
19
+
20
+ **Generate code for specific requests only:** Only generate client code for the individual requests the user indicates. Do not automatically generate code for an entire folder or collection—wait for the user to specify which requests they want client code for, or ask them.
21
+
22
+ **Match the target project's language and style:** This is critical. Analyze the project's language, framework, structure, and conventions before generating any code. The examples in this document use JavaScript/TypeScript and Python, but you must generate code in whatever language the project uses and try to match the style and conventions of the project. Do not generate code in a different language than the project uses, regardless of examples shown, unless explicitly requested.
23
+
24
+ **Follow an ordered workflow:** The instructions below provide a step-by-step process. Follow these steps in order.
25
+
26
+ ---
27
+
28
+ ## Workflow Overview
29
+
30
+ When the user requests code generation for a Postman request, or code generation for something that depends on a Postman request, follow this sequence:
31
+
32
+ 1. **Gather Context** - Fetch all necessary Postman data (collection, folders, request, responses, environments)
33
+ 2. **Determine Base Directory** - Find or choose where generated code should live
34
+ 3. **Plan File Structure** - Calculate slugs and file paths
35
+ 4. **Set Up Variables** - Generate a variables file for collection and environment variables
36
+ 5. **Generate Client Code** - Create the client function with proper structure
37
+ 6. **Deduplicate and Extract Shared Code** - Consolidate common code into shared utilities
38
+ 7. **Verify Quality** - Ensure code meets quality standards
39
+
40
+ ---
41
+
42
+ ## Step 1: Gather Context
43
+
44
+ Before generating code, gather all appropriate context. Use these MCP tools to fetch the necessary data IF it has not already been fetched:
45
+
46
+ IMPORTANT: for ALL tools that accept an id, **use the full uid**.
47
+ The uid format is <ownerId>-<id> and an example uid is 34229158-378697c9-3044-44b1-9a0e-1417194cee44, where
48
+ 34229158 is the ownerId and 378697c9-3044-44b1-9a0e-1417194cee44 is the id.
49
+ When you encounter an id that has no ownerId, prepend the ownerId from the collection before using
50
+ it as a tool call argument.
51
+
52
+ **Required:**
53
+
54
+ - \`getCollectionRequest\` - Fetch the request you're generating code for
55
+ - \`getCollectionFolder\` - Fetch all parent folders recursively (they may contain docs and instructions that apply to the request)
56
+ - \`getCollectionMap\` - Fetch the collection map, which includes collection-level docs that may apply to the request
57
+ - \`getCollectionResponse\` - If the request has response examples, fetch each one to understand request/response permutations and shapes. Use this for:
58
+ - Creating response types in typed languages
59
+ - Adding response schema comments in untyped languages
60
+ - Understanding both success and error cases
61
+ - \`getEnvironments\` - Fetch all environments for the workspace
62
+ - \`getEnvironment\` - For each environment, fetch the full details to see what variables have been defined and have values
63
+
64
+ **Important:** If you've already fetched this information earlier in the conversation, reuse it. Only make additional tool calls to fill gaps in context.
65
+
66
+ **Important: Do not skip any required steps. Gather ALL required information
67
+ in Step 1 before moving to Step 2. Missing information will result in
68
+ incomplete code generation.**
69
+
70
+ ---
71
+
72
+ ## Step 2: Determine Base Directory
73
+
74
+ The base directory (\`baseDir\`) is where all generated API client code will be placed.
75
+
76
+ **Discovery process:**
77
+
78
+ 1. Search the project for existing generated client code by looking for opening comments containing the words "postman code"
79
+
80
+ 2. If found, extract the base directory path from the location of these existing files to determine the established \`baseDir\`
81
+
82
+ 3. If no existing generated code is found, choose a new \`baseDir\` based on project conventions for where API client functions should live
83
+ - The leaf directory name should be \`postman\`
84
+ - Examples: \`src/postman\`, \`lib/postman\`, \`app/postman\`
85
+
86
+ ---
87
+
88
+ ## Step 3: Plan File Structure
89
+
90
+ ### Directory Structure
91
+
92
+ Organize generated code following this hierarchy:
93
+
94
+ \`\`\`
95
+ <baseDir>/
96
+ <collection-slug>/
97
+ <folder-slug>/
98
+ <request-slug>/
99
+ client.<ext>
100
+ <request-slug>/
101
+ client.<ext>
102
+ shared/
103
+ (extracted types and utilities)
104
+ \`\`\`
105
+
106
+ ### File Path Per Request
107
+
108
+ - Path pattern: \`<baseDir>/<collection-slug>/<folder-slug?>/<request-slug>/client.<ext>\`
109
+ - Do not use the request name in the filename; always use \`client.ts\`, \`client.js\`, \`client.py\`, etc.
110
+ - Each request gets its own directory named with its slug
111
+ - Export following existing project conventions
112
+
113
+ ### Slugification
114
+
115
+ Convert any Postman object name into a filesystem and git-safe string:
116
+
117
+ \`\`\`javascript
118
+ function createSlug(name) {
119
+ return name
120
+ .toLowerCase()
121
+ .replace(/[^a-z0-9]+/g, '-')
122
+ .replace(/^-+|-+$/g, '');
123
+ }
124
+ \`\`\`
125
+
126
+ ### Collision Handling
127
+
128
+ If two sibling requests resolve to the same slug, append an index: \`-1\`, \`-2\`, \`-3\`, etc.
129
+
130
+ ---
131
+
132
+ ## Step 4: Set Up Variables
133
+
134
+ If variables exist at the collection level or in any environment, generate a variables file in the shared folder.
135
+
136
+ ### Variables File Location
137
+
138
+ Place the variables file at: \`<baseDir>/<collection-slug>/shared/variables.<ext>\`
139
+
140
+ Use the appropriate extension for the target language (\`.ts\`, \`.js\`, \`.py\`, etc.).
141
+
142
+ ### Variables File Structure
143
+
144
+ Export a single object named \`variables\` that contains:
145
+
146
+ - A \`collection\` key for collection-level variables
147
+ - A key for each environment (using the exact environment name from Postman)
148
+
149
+ **Important:**
150
+ - Environment names can be anything and are used exactly as they appear in Postman
151
+ - Do not modify or normalize environment names
152
+ - Do not bind variables to environment variables here—this file reflects what's on Postman
153
+ - The caller of the generated API client is responsible for preparing variables to pass to the API clients, using data from the variables file or whatever it deems appropriate
154
+
155
+ **Example (TypeScript):**
156
+
157
+ \`\`\`typescript
158
+ export const variables = {
159
+ collection: {
160
+ apiVersion: 'v2',
161
+ retryAttempts: 3,
162
+ },
163
+ "Production Environment": {
164
+ baseUrl: 'https://api.example.com',
165
+ apiKey: '',
166
+ },
167
+ "Staging Environment": {
168
+ baseUrl: 'https://api-staging.example.com',
169
+ apiKey: '',
170
+ },
171
+ };
172
+ \`\`\`
173
+
174
+ **Example (Python):**
175
+
176
+ \`\`\`python
177
+ variables = {
178
+ 'collection': {
179
+ 'api_version': 'v2',
180
+ 'retry_attempts': 3,
181
+ },
182
+ 'Production Environment': {
183
+ 'base_url': 'https://api.example.com',
184
+ 'api_key': '',
185
+ },
186
+ 'Staging Environment': {
187
+ 'base_url': 'https://api-staging.example.com',
188
+ 'api_key': '',
189
+ },
190
+ }
191
+ \`\`\`
192
+
193
+ ---
194
+
195
+ ## Step 5: Generate Client Code
196
+
197
+ For each request, generate a client file with the following components:
198
+
199
+ ### Opening Comment (Required)
200
+
201
+ Every generated client file must include an opening comment at the top using language-appropriate comment syntax.
202
+
203
+ **Required fields:**
204
+
205
+ - The phrase "Generated by Postman Code" (for discovery)
206
+ - Collection name and Collection UID (grouped together)
207
+ - Full path showing folders and request name (e.g., "Folder1 > Subfolder > Request Name")
208
+ - Request UID
209
+ - Modified timestamp from the Postman request object (serves as a version indicator)
210
+
211
+ **Example formats:**
212
+
213
+ JavaScript/TypeScript:
214
+
215
+ \`\`\`javascript
216
+ /**
217
+ * Generated by Postman Code
218
+ *
219
+ * Collection: Stripe API
220
+ * Collection UID: 12345678-1234-1234-1234-123456789abc
221
+ *
222
+ * Request: Payment Intents > Create Payment Intent
223
+ * Request UID: 87654321-4321-4321-4321-cba987654321
224
+ * Request modified at: 2024-11-10T15:45:30.000Z
225
+ */
226
+ \`\`\`
227
+
228
+ Python:
229
+
230
+ \`\`\`python
231
+ """
232
+ Generated by Postman Code
233
+ Collection: Stripe API
234
+ Collection UID: 12345678-1234-1234-1234-123456789abc
235
+ Request: Payment Intents > Create Payment Intent
236
+ Request UID: 87654321-4321-4321-4321-cba987654321
237
+ Request modified at: 2024-11-10T15:45:30.000Z
238
+ """
239
+ \`\`\`
240
+
241
+ ### Client Function Implementation
242
+
243
+ Generate a client function that implements these components:
244
+
245
+ **Variable handling:**
246
+
247
+ - Client functions should accept all variables they will use as specific function parameters
248
+ - Do not hardcode variable values in client functions
249
+ - The caller is responsible for:
250
+ - Selecting which environment to use from the variables object
251
+ - Merging collection-level and environment-level variables
252
+ - Binding any variables to environment variables or secrets
253
+ - Passing the merged variables to client functions
254
+
255
+ **URL construction:**
256
+
257
+ - Accept base URL and other URL-related variables as function parameters
258
+ - Substitute path parameters with function arguments
259
+ - Encode query parameters properly
260
+ - Build the complete URL from the base URL and path
261
+
262
+ **Headers:**
263
+
264
+ - Set headers per specification
265
+ - Never hardcode secrets; use environment variables or project secret helpers
266
+ - Follow project conventions for auth token handling
267
+
268
+ **Request body:**
269
+
270
+ - Serialize according to content type (JSON, form-data, urlencoded, etc.)
271
+ - Type appropriately in typed languages
272
+
273
+ **Authentication:**
274
+
275
+ - Implement exactly as defined in the request (bearer token, API key, basic auth, etc.)
276
+ - Always pull credentials from environment variables or project secret management
277
+ - Never hardcode credentials
278
+
279
+ **Response handling:**
280
+
281
+ - Parse and shape the payload if response information exists
282
+ - In typed languages, generate or reuse types for request/response shapes
283
+ - Implement explicit error handling for each response example in the Postman request
284
+ - If the request has a 404 response example, include specific handling for 404
285
+ - Each documented error case should be explicitly caught and logged with appropriate context
286
+ - Follow project and any existing API client code conventions for error handling patterns around logging, exception classes, error codes, etc.
287
+
288
+ **Error handling example:**
289
+
290
+ \`\`\`javascript
291
+ // If Postman request has examples for 200, 404, 401, and 422 responses:
292
+ const response = await fetch(url, options);
293
+
294
+ if (response.ok) {
295
+ return await response.json();
296
+ }
297
+
298
+ // Explicit handling for each documented error response
299
+ switch (response.status) {
300
+ case 404:
301
+ console.error('Resource not found');
302
+ throw new NotFoundError(await response.json());
303
+
304
+ case 401:
305
+ console.error('Authentication failed');
306
+ throw new UnauthorizedError(await response.json());
307
+
308
+ case 422:
309
+ console.error('Validation failed');
310
+ throw new ValidationError(await response.json());
311
+
312
+ default:
313
+ console.error('Unexpected error');
314
+ throw new Error(await response.text());
315
+ }
316
+ \`\`\`
317
+
318
+ **Documentation:**
319
+
320
+ - Add standard docstrings (JSDoc, TSDoc, Python docstrings, etc.)
321
+ - Include description from Postman request
322
+ - Document all parameters, return types, and possible errors
323
+
324
+ ### Follow Existing Patterns
325
+
326
+ **Match project conventions:**
327
+
328
+ - Mirror the Postman workspace structure: collection → folders → requests
329
+ - Follow existing naming conventions in the \`baseDir\`
330
+ - Match casing style (camelCase, PascalCase, snake_case)
331
+ - Match export style (named exports, default exports, module.exports)
332
+ - Match directory layout conventions
333
+ - Use existing HTTP helpers if present in the project
334
+ - Follow existing error handling patterns
335
+ - Match existing auth implementation patterns
336
+ - Use environment variables consistently with project conventions
337
+ - Match documentation style already present
338
+
339
+ **Only deviate from existing patterns if explicitly requested by the user.**
340
+
341
+ ### Language-Specific Guidelines
342
+
343
+ **JavaScript/TypeScript:**
344
+
345
+ - Use modern async/await syntax unless the project conventions dictate otherwise
346
+ - Use \`fetch\` or existing HTTP client in the project
347
+ - If TS, proper TypeScript types for all functions, parameters, and return values
348
+ - If JS, proper JSDoc comments that contain request and response shapes
349
+ - Use JSDoc or TSDoc comments in general for all functions, parameters, and return values
350
+
351
+ **Python:**
352
+
353
+ - Use \`requests\` library or existing HTTP client
354
+ - Type hints for all functions
355
+ - Proper docstrings (Google, NumPy, or project style)
356
+ - Follow PEP 8 conventions
357
+
358
+ **Other languages:**
359
+
360
+ - Follow idiomatic patterns for the language
361
+ - Use standard HTTP libraries
362
+ - Apply language-specific naming conventions
363
+ - Use appropriate documentation format; follow guidelines above for TS/JS and adapt to the language
364
+
365
+ ---
366
+
367
+ ## Step 6: Deduplicate and Extract Shared Code
368
+
369
+ After generating all requested client files, consolidate duplicated code within each collection.
370
+
371
+ ### Detection
372
+
373
+ Identify duplicated types, interfaces, and utility functions within the same collection.
374
+
375
+ ### Extraction Location
376
+
377
+ Extract shared code to: \`<baseDir>/<collection-slug>/shared/\`
378
+
379
+ This location is used for:
380
+
381
+ - Common types and interfaces
382
+ - Shared utility functions
383
+ - Common authentication helpers
384
+ - Reusable validation logic
385
+
386
+ ### Update Imports
387
+
388
+ After extracting shared code:
389
+
390
+ - Modify generated clients to import from shared locations
391
+ - Maintain correct relative paths
392
+ - Ensure all imports resolve correctly
393
+
394
+ ### Cross-Collection Sharing
395
+
396
+ - Keep helpers within a collection by default (e.g., Stripe and Slack collections stay separate)
397
+ - Only share code across collections when explicitly requested by the user
398
+
399
+ ### Example Structure
400
+
401
+ \`\`\`
402
+ <baseDir>/
403
+ github-api/
404
+ shared/
405
+ types.ts
406
+ auth.ts
407
+ users/
408
+ get-user/
409
+ client.ts
410
+ list-users/
411
+ client.ts
412
+ repos/
413
+ get-repo/
414
+ client.ts
415
+ list-repos/
416
+ client.ts
417
+ \`\`\`
418
+
419
+ ---
420
+
421
+ ## Step 7: Verify Quality Standards
422
+
423
+ Ensure all generated code meets these standards:
424
+
425
+ - All generated code must be lintable and follow project linting rules
426
+ - Code should be production-ready, not placeholder or example code
427
+ - Error handling should be robust and informative
428
+ - Type safety should be maintained in typed languages
429
+ - Security best practices must be followed (no hardcoded secrets, proper input validation)`;
430
+ export async function handler(_args, _extra) {
431
+ return {
432
+ content: [
433
+ {
434
+ type: 'text',
435
+ text: CODE_GENERATION_INSTRUCTIONS,
436
+ },
437
+ ],
438
+ };
439
+ }
@@ -0,0 +1,52 @@
1
+ import { z } from 'zod';
2
+ import { asMcpError, McpError } from '../utils/toolHelpers.js';
3
+ export const method = 'getCollection';
4
+ export const description = "Gets information about a collection. For a complete list of this endpoint's possible values, refer to the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).";
5
+ export const parameters = z.object({
6
+ collectionId: z
7
+ .string()
8
+ .describe('The collection ID must be in the form <OWNER_ID>-<UUID> (e.g. 12345-33823532ab9e41c9b6fd12d0fd459b8b).'),
9
+ access_key: z
10
+ .string()
11
+ .describe("A collection's read-only access key. Using this query parameter does not require an API key to call the endpoint.")
12
+ .optional(),
13
+ model: z
14
+ .literal('minimal')
15
+ .describe("Return a list of only the collection's root-level request (`rootLevelRequests`) and folder (`rootLevelFolders`) IDs instead of the full collection element data.")
16
+ .optional(),
17
+ });
18
+ export const annotations = {
19
+ title: "Gets information about a collection. For a complete list of this endpoint's possible values, refer to the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).",
20
+ readOnlyHint: true,
21
+ destructiveHint: false,
22
+ idempotentHint: true,
23
+ };
24
+ export async function handler(args, extra) {
25
+ try {
26
+ const endpoint = `/collections/${args.collectionId}`;
27
+ const query = new URLSearchParams();
28
+ if (args.access_key !== undefined)
29
+ query.set('access_key', String(args.access_key));
30
+ if (args.model !== undefined)
31
+ query.set('model', String(args.model));
32
+ const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint;
33
+ const options = {
34
+ headers: extra.headers,
35
+ };
36
+ const result = await extra.client.get(url, options);
37
+ return {
38
+ content: [
39
+ {
40
+ type: 'text',
41
+ text: `${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}`,
42
+ },
43
+ ],
44
+ };
45
+ }
46
+ catch (e) {
47
+ if (e instanceof McpError) {
48
+ throw e;
49
+ }
50
+ throw asMcpError(e);
51
+ }
52
+ }
@@ -0,0 +1,101 @@
1
+ import { z } from 'zod';
2
+ import { asMcpError, McpError } from '../utils/toolHelpers.js';
3
+ export const method = 'getCollectionMap';
4
+ export const description = `Get a Postman collection map with metadata and a complete recursive index of all folders and requests. Response includes collection metadata and description. Response includes itemRefs property (name and id only) instead of the full item array. After calling, present the collection summary and ask the user where they\'d like to explore next, calling getCollectionFolder and/or getCollectionRequest tools in parallel to get more data quickly.
5
+ Once you've called this tool, DO NOT call searchPostmanElements to find items in or related to this collection. Instead, use the map in itemRefs.
6
+ Only use searchPostmanElements to find the collection where a request may be. Then, stay in the collection and don't use the search.
7
+ When using the getCollectionRequest tool to look up request data, omit the populate parameter to avoid getting all response examples
8
+ back at once (can be very large). Instead, use the response ids from the return value and call getCollectionResponse for each one.
9
+ Prepend the collection's ownerId to the front of each response id when passing it to getCollectionResponse. This is the first part of the collection uid.
10
+ Infer the response schema from that information and remember it. Omit the raw response examples from the conversation going forward.`;
11
+ export const parameters = z.object({
12
+ collectionId: z
13
+ .string()
14
+ .describe('The collection ID must be in the form <OWNER_ID>-<UUID> (e.g. 12345-33823532ab9e41c9b6fd12d0fd459b8b).'),
15
+ access_key: z
16
+ .string()
17
+ .describe("A collection's read-only access key. Using this query parameter does not require an API key to call the endpoint.")
18
+ .optional(),
19
+ });
20
+ export const annotations = {
21
+ title: 'Get Postman Collection Map',
22
+ readOnlyHint: true,
23
+ destructiveHint: false,
24
+ idempotentHint: true,
25
+ };
26
+ function buildItemRefs(items) {
27
+ if (!Array.isArray(items) || items.length === 0) {
28
+ return undefined;
29
+ }
30
+ return items.map((item) => {
31
+ const itemId = item.uid || item.id || '';
32
+ const itemRef = {
33
+ name: item.name || '',
34
+ id: itemId,
35
+ };
36
+ if (item.item && Array.isArray(item.item)) {
37
+ const nestedRefs = buildItemRefs(item.item);
38
+ if (nestedRefs) {
39
+ itemRef.itemRefs = nestedRefs;
40
+ }
41
+ }
42
+ return itemRef;
43
+ });
44
+ }
45
+ export async function handler(args, extra) {
46
+ try {
47
+ const endpoint = `/collections/${args.collectionId}`;
48
+ const query = new URLSearchParams();
49
+ if (args.access_key !== undefined)
50
+ query.set('access_key', String(args.access_key));
51
+ const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint;
52
+ const options = {
53
+ headers: extra.headers,
54
+ };
55
+ const result = await extra.client.get(url, options);
56
+ if (typeof result === 'string') {
57
+ return {
58
+ content: [
59
+ {
60
+ type: 'text',
61
+ text: result,
62
+ },
63
+ ],
64
+ };
65
+ }
66
+ const response = result;
67
+ if (response.collection) {
68
+ const { item, ...collectionWithoutItems } = response.collection;
69
+ const itemRefs = buildItemRefs(item);
70
+ const processedResponse = {
71
+ ...response,
72
+ collection: {
73
+ ...collectionWithoutItems,
74
+ ...(itemRefs && { itemRefs }),
75
+ },
76
+ };
77
+ return {
78
+ content: [
79
+ {
80
+ type: 'text',
81
+ text: JSON.stringify(processedResponse, null, 2),
82
+ },
83
+ ],
84
+ };
85
+ }
86
+ return {
87
+ content: [
88
+ {
89
+ type: 'text',
90
+ text: JSON.stringify(result, null, 2),
91
+ },
92
+ ],
93
+ };
94
+ }
95
+ catch (e) {
96
+ if (e instanceof McpError) {
97
+ throw e;
98
+ }
99
+ throw asMcpError(e);
100
+ }
101
+ }
@@ -0,0 +1,46 @@
1
+ import { z } from 'zod';
2
+ import { McpError, asMcpError } from '../utils/toolHelpers.js';
3
+ import { handler as getCollectionApiHandler, parameters as getCollectionApiParameters, } from './getCollection.js';
4
+ import { handler as getCollectionMapHandler } from './getCollectionMap.js';
5
+ export const method = 'getCollection';
6
+ export const description = `Get information about a collection. By default this tool returns the lightweight collection map (metadata + recursive itemRefs).
7
+ Use the model parameter to opt in to Postman's full API responses:
8
+ - model=minimal — root-level folder/request IDs only
9
+ - model=full — full Postman collection payload.`;
10
+ const baseParameters = getCollectionApiParameters.pick({
11
+ collectionId: true,
12
+ access_key: true,
13
+ });
14
+ export const parameters = baseParameters.extend({
15
+ model: z
16
+ .enum(['minimal', 'full'])
17
+ .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.')
18
+ .optional(),
19
+ });
20
+ export const annotations = {
21
+ title: 'Get Collection (map by default)',
22
+ readOnlyHint: true,
23
+ destructiveHint: false,
24
+ idempotentHint: true,
25
+ };
26
+ function omitModel(args) {
27
+ const { model: _ignored, ...rest } = args;
28
+ return rest;
29
+ }
30
+ export async function handler(args, extra) {
31
+ try {
32
+ if (!args.model) {
33
+ return await getCollectionMapHandler(omitModel(args), extra);
34
+ }
35
+ if (args.model === 'minimal') {
36
+ return await getCollectionApiHandler({ ...args, model: 'minimal' }, extra);
37
+ }
38
+ return await getCollectionApiHandler(omitModel(args), extra);
39
+ }
40
+ catch (e) {
41
+ if (e instanceof McpError) {
42
+ throw e;
43
+ }
44
+ throw asMcpError(e);
45
+ }
46
+ }
@@ -1,52 +1 @@
1
- import { z } from 'zod';
2
- import { asMcpError, McpError } from './utils/toolHelpers.js';
3
- export const method = 'getCollection';
4
- export const description = "Gets information about a collection. For a complete list of this endpoint's possible values, refer to the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).";
5
- export const parameters = z.object({
6
- collectionId: z
7
- .string()
8
- .describe('The collection ID must be in the form <OWNER_ID>-<UUID> (e.g. 12345-33823532ab9e41c9b6fd12d0fd459b8b).'),
9
- access_key: z
10
- .string()
11
- .describe("A collection's read-only access key. Using this query parameter does not require an API key to call the endpoint.")
12
- .optional(),
13
- model: z
14
- .literal('minimal')
15
- .describe("Return a list of only the collection's root-level request (`rootLevelRequests`) and folder (`rootLevelFolders`) IDs instead of the full collection element data.")
16
- .optional(),
17
- });
18
- export const annotations = {
19
- title: "Gets information about a collection. For a complete list of this endpoint's possible values, refer to the [Postman Collection Format documentation](https://schema.postman.com/collection/json/v2.1.0/draft-07/docs/index.html).",
20
- readOnlyHint: true,
21
- destructiveHint: false,
22
- idempotentHint: true,
23
- };
24
- export async function handler(args, extra) {
25
- try {
26
- const endpoint = `/collections/${args.collectionId}`;
27
- const query = new URLSearchParams();
28
- if (args.access_key !== undefined)
29
- query.set('access_key', String(args.access_key));
30
- if (args.model !== undefined)
31
- query.set('model', String(args.model));
32
- const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint;
33
- const options = {
34
- headers: extra.headers,
35
- };
36
- const result = await extra.client.get(url, options);
37
- return {
38
- content: [
39
- {
40
- type: 'text',
41
- text: `${typeof result === 'string' ? result : JSON.stringify(result, null, 2)}`,
42
- },
43
- ],
44
- };
45
- }
46
- catch (e) {
47
- if (e instanceof McpError) {
48
- throw e;
49
- }
50
- throw asMcpError(e);
51
- }
52
- }
1
+ export { method, description, parameters, annotations, handler } from './getCollection/index.js';