-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgetTicket.ts
82 lines (75 loc) · 1.79 KB
/
getTicket.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import * as jiraApi from "../api.js";
// Define interfaces for safer type checking
interface TicketDescription {
content?: Array<{
content?: Array<{
text?: string;
}>;
}>;
}
/**
* Register the ticket retrieval tools
*/
export const registerGetTicketTools = (server: McpServer): void => {
// Define schema for ticket retrieval
const getTicketParams = {
issueIdOrKey: z.string().describe("The issue ID or key of the ticket"),
};
// Register all ticket retrieval tools
const getTicketTools = [
"get_only_ticket_name_and_description",
"get_ticket",
"read_ticket",
"get_task",
"read_task",
];
for (const tool of getTicketTools) {
server.tool(tool, getTicketParams, async ({ issueIdOrKey }) => {
try {
const response = await jiraApi.getTicket(issueIdOrKey);
if ("error" in response) {
return {
isError: true,
content: [
{
type: "text",
text: `Error executing JQL: ${JSON.stringify(response.error)}`,
},
],
};
}
const ticket = {
key: response.fields.key,
summary: response.fields.summary,
description: response.fields.description,
attachment: response.fields.attachment?.map((attachment) => ({
id: attachment.id,
filename: attachment.filename,
size: attachment.size,
content: attachment.content,
})),
};
return {
content: [
{
type: "text",
text: `Found ticket: ${JSON.stringify(ticket, null, 2)}`,
},
],
};
} catch (error) {
return {
isError: true,
content: [
{
type: "text",
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
},
],
};
}
});
}
};