Skip to content

Commit 7d29621

Browse files
committed
fix: getTicket for Jira uses specific API endpoint for it
1 parent 979eea1 commit 7d29621

File tree

4 files changed

+109
-74
lines changed

4 files changed

+109
-74
lines changed

packages/jira/src/api.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
import type {
88
JiraAttachmentResponse,
99
JiraErrorResponse,
10+
JiraIssue,
1011
JiraProject,
1112
JiraSearchResponse,
1213
JiraStatus,
@@ -84,6 +85,36 @@ export async function queryAssignable(
8485
}
8586
}
8687

88+
/**
89+
* Get a Jira ticket
90+
*/
91+
export async function getTicket(
92+
issueIdOrKey: string,
93+
): Promise<JiraIssue | JiraErrorResponse> {
94+
try {
95+
const response = await fetch(
96+
`${JIRA_URL}/rest/api/3/issue/${issueIdOrKey}`,
97+
{
98+
method: "GET",
99+
headers: getAuthHeaders(),
100+
},
101+
);
102+
103+
if (!response.ok) {
104+
const errorData = await response.json();
105+
return {
106+
error: errorData || `HTTP error: ${response.status}`,
107+
};
108+
}
109+
110+
return await response.json();
111+
} catch (error) {
112+
return {
113+
error: error instanceof Error ? error.message : String(error),
114+
};
115+
}
116+
}
117+
87118
/**
88119
* Create a new Jira ticket
89120
*/

packages/jira/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ async function main(): Promise<void> {
2222
const server = new McpServer({
2323
name: "jira-mcp-server",
2424
version: "1.0.0",
25+
description: "Talk to Jira - MCP Server",
26+
author: "DX Heroes (https://dxheroes.io)",
2527
});
2628

2729
// Register all tools

packages/jira/src/tools/getTicket.ts

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,7 @@ interface TicketDescription {
1717
export const registerGetTicketTools = (server: McpServer): void => {
1818
// Define schema for ticket retrieval
1919
const getTicketParams = {
20-
jql: z.string().describe("JQL query string"),
21-
maxResults: z
22-
.number()
23-
.optional()
24-
.default(10)
25-
.describe("Maximum number of results to return"),
20+
issueIdOrKey: z.string().describe("The issue ID or key of the ticket"),
2621
};
2722

2823
// Register all ticket retrieval tools
@@ -35,9 +30,9 @@ export const registerGetTicketTools = (server: McpServer): void => {
3530
];
3631

3732
for (const tool of getTicketTools) {
38-
server.tool(tool, getTicketParams, async ({ jql, maxResults }) => {
33+
server.tool(tool, getTicketParams, async ({ issueIdOrKey }) => {
3934
try {
40-
const response = await jiraApi.executeJQL(jql, maxResults);
35+
const response = await jiraApi.getTicket(issueIdOrKey);
4136

4237
if ("error" in response) {
4338
return {
@@ -51,26 +46,23 @@ export const registerGetTicketTools = (server: McpServer): void => {
5146
};
5247
}
5348

54-
// Return only the ticket name and description
55-
const tickets = response.issues.map((issue) => {
56-
const descObj = issue.fields.description as
57-
| TicketDescription
58-
| undefined;
59-
const description =
60-
descObj?.content?.[0]?.content?.[0]?.text || "No description";
61-
62-
return {
63-
key: issue.key,
64-
summary: issue.fields.summary,
65-
description,
66-
};
67-
});
49+
const ticket = {
50+
key: response.fields.key,
51+
summary: response.fields.summary,
52+
description: response.fields.description,
53+
attachment: response.fields.attachment?.map((attachment) => ({
54+
id: attachment.id,
55+
filename: attachment.filename,
56+
size: attachment.size,
57+
content: attachment.content,
58+
})),
59+
};
6860

6961
return {
7062
content: [
7163
{
7264
type: "text",
73-
text: `Found ${tickets.length} tickets: ${JSON.stringify(tickets, null, 2)}`,
65+
text: `Found ticket: ${JSON.stringify(ticket, null, 2)}`,
7466
},
7567
],
7668
};

packages/jira/src/types.ts

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -2,102 +2,112 @@
22
* Error response from Jira API
33
*/
44
export interface JiraErrorResponse {
5-
error: string | object;
5+
error: string | object;
66
}
77

88
/**
99
* Jira attachment
1010
*/
1111
export interface JiraAttachment {
12-
id: string;
13-
title: string;
14-
filename: string;
15-
mimeType: string;
16-
size: number;
17-
content: string;
18-
[key: string]: unknown;
12+
id: string;
13+
title: string;
14+
filename: string;
15+
mimeType: string;
16+
size: number;
17+
content: string;
18+
[key: string]: unknown;
1919
}
2020

2121
/**
2222
* Jira attachment response
2323
*/
2424
export interface JiraAttachmentResponse {
25-
id: string;
26-
self: string;
27-
filename: string;
28-
[key: string]: unknown;
25+
id: string;
26+
self: string;
27+
filename: string;
28+
[key: string]: unknown;
2929
}
3030

3131
/**
3232
* Jira ticket response
3333
*/
3434
export interface JiraTicketResponse {
35-
id: string;
36-
key: string;
37-
self: string;
38-
[key: string]: unknown;
35+
id: string;
36+
key: string;
37+
self: string;
38+
[key: string]: unknown;
3939
}
4040

4141
/**
4242
* Jira user
4343
*/
4444
export interface JiraUser {
45-
accountId: string;
46-
displayName: string;
47-
emailAddress?: string;
48-
active: boolean;
49-
[key: string]: unknown;
45+
accountId: string;
46+
displayName: string;
47+
emailAddress?: string;
48+
active: boolean;
49+
[key: string]: unknown;
5050
}
5151

5252
/**
5353
* Jira project
5454
*/
5555
export interface JiraProject {
56-
id: string;
57-
key: string;
58-
name: string;
59-
[key: string]: unknown;
56+
id: string;
57+
key: string;
58+
name: string;
59+
[key: string]: unknown;
6060
}
6161

6262
/**
6363
* Jira status
6464
*/
6565
export interface JiraStatus {
66-
id: string;
67-
name: string;
68-
statusCategory: {
69-
id: number;
70-
key: string;
71-
name: string;
72-
[key: string]: unknown;
73-
};
74-
[key: string]: unknown;
66+
id: string;
67+
name: string;
68+
statusCategory: {
69+
id: number;
70+
key: string;
71+
name: string;
72+
[key: string]: unknown;
73+
};
74+
[key: string]: unknown;
7575
}
7676

7777
/**
7878
* Jira issue
7979
*/
8080
export interface JiraIssue {
81-
id: string;
82-
key: string;
83-
self: string;
84-
fields: {
85-
summary: string;
86-
description?: unknown;
87-
status?: {
88-
name: string;
89-
[key: string]: unknown;
90-
};
91-
[key: string]: unknown;
92-
};
93-
[key: string]: unknown;
81+
id: string;
82+
key: string;
83+
self: string;
84+
fields: {
85+
summary: string;
86+
description?: {
87+
type: string;
88+
content?: {
89+
type: string;
90+
content?: {
91+
type: string;
92+
text: string;
93+
}[];
94+
}[];
95+
};
96+
status?: {
97+
name: string;
98+
[key: string]: unknown;
99+
};
100+
attachment?: JiraAttachment[];
101+
[key: string]: unknown;
102+
};
103+
[key: string]: unknown;
94104
}
95105

96106
/**
97107
* Jira search response
98108
*/
99109
export interface JiraSearchResponse {
100-
issues: JiraIssue[];
101-
total: number;
102-
[key: string]: unknown;
103-
}
110+
issues: JiraIssue[];
111+
total: number;
112+
[key: string]: unknown;
113+
}

0 commit comments

Comments
 (0)