-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathcreateCollectionFork.js
More file actions
50 lines (50 loc) · 1.86 KB
/
Copy pathcreateCollectionFork.js
File metadata and controls
50 lines (50 loc) · 1.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { z } from 'zod';
import { ContentType } from '../clients/postman.js';
import { asMcpError, McpError } from './utils/toolHelpers.js';
export const method = 'createCollectionFork';
export const title = 'Create a fork';
export const description = 'Creates a [fork](https://learning.postman.com/docs/collaborating-in-postman/version-control/#creating-a-fork) from an existing collection into a workspace.';
export const parameters = z.object({
collectionId: z.string().describe("The collection's ID."),
workspace: z.string().describe('The workspace ID in which to create the fork.'),
label: z.string().describe("The fork's label."),
});
export const annotations = {
title: 'Create a fork',
readOnlyHint: false,
openWorldHint: true,
destructiveHint: false,
idempotentHint: false,
};
export async function handler(args, extra) {
try {
const endpoint = `/collections/fork/${encodeURIComponent(String(args.collectionId))}`;
const query = new URLSearchParams();
if (args.workspace !== undefined)
query.set('workspace', String(args.workspace));
const url = query.toString() ? `${endpoint}?${query.toString()}` : endpoint;
const bodyPayload = {};
if (args.label !== undefined)
bodyPayload.label = args.label;
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);
}
}