-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexecuteJql.ts
61 lines (57 loc) · 1.23 KB
/
executeJql.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
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
import * as jiraApi from "../api.js";
/**
* Schema for the execute_jql tool parameters
*/
const executeJqlParams = {
jql: z.string().describe("JQL query string"),
maxResults: z
.number()
.optional()
.default(10)
.describe("Maximum number of results to return"),
};
/**
* Register the execute_jql tool with the server
*/
export const registerExecuteJqlTool = (server: McpServer): void => {
server.tool(
"execute_jql",
executeJqlParams,
async ({ jql, maxResults }, extra) => {
try {
const response = await jiraApi.executeJQL(jql, maxResults);
if ("error" in response) {
return {
isError: true,
content: [
{
type: "text",
text: `Error executing JQL: ${JSON.stringify(response.error)}`,
},
],
};
}
return {
content: [
{
type: "text",
text: `JQL Results: ${JSON.stringify(response, null, 2)}`,
},
],
};
} catch (error) {
return {
isError: true,
content: [
{
type: "text",
text: `Error: ${error instanceof Error ? error.message : String(error)}`,
},
],
};
}
},
);
};