-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcreateTicket.ts
63 lines (59 loc) · 1.42 KB
/
createTicket.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import * as jiraApi from "../api.js";
/**
* Register the create_ticket tool
*/
export const registerCreateTicketTool = (server: McpServer): void => {
const createTicketParams = {
project: z.string().describe("Project key"),
summary: z.string().describe("Ticket summary"),
description: z.string().describe("Ticket description"),
issuetype: z.string().describe("Issue type name (Bug, Story, etc.)"),
parent: z.string().optional().describe("Parent issue key (for subtasks)"),
};
server.tool(
"create_ticket",
createTicketParams,
async ({ project, summary, description, issuetype, parent }) => {
try {
const response = await jiraApi.createTicket(
project,
summary,
description,
issuetype,
parent,
);
if ("error" in response) {
return {
isError: true,
content: [
{
type: "text",
text: `Error creating ticket: ${JSON.stringify(response.error)}`,
},
],
};
}
return {
content: [
{
type: "text",
text: `Ticket created: ${JSON.stringify(response, null, 2)}`,
},
],
};
} catch (error) {
return {
isError: true,
content: [
{
type: "text",
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
},
],
};
}
},
);
};