@denvermullets/jait 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api-client.d.ts +1 -0
- package/dist/api-client.js +5 -3
- package/dist/attachments.d.ts +16 -0
- package/dist/attachments.js +64 -0
- package/dist/tools/comments.js +17 -8
- package/dist/tools/issues.d.ts +2 -0
- package/dist/tools/issues.js +37 -26
- package/package.json +5 -5
package/dist/api-client.d.ts
CHANGED
package/dist/api-client.js
CHANGED
|
@@ -13,7 +13,7 @@ function getConfig() {
|
|
|
13
13
|
}
|
|
14
14
|
export async function apiRequest(path, options = {}) {
|
|
15
15
|
const { baseUrl, token } = getConfig();
|
|
16
|
-
const { method = "GET", body, params } = options;
|
|
16
|
+
const { method = "GET", body, form, params } = options;
|
|
17
17
|
const url = new URL(`${baseUrl}${path}`);
|
|
18
18
|
if (params) {
|
|
19
19
|
for (const [key, value] of Object.entries(params)) {
|
|
@@ -24,13 +24,15 @@ export async function apiRequest(path, options = {}) {
|
|
|
24
24
|
}
|
|
25
25
|
const headers = {
|
|
26
26
|
Authorization: `Bearer ${token}`,
|
|
27
|
-
"Content-Type": "application/json",
|
|
28
27
|
Accept: "application/json",
|
|
29
28
|
};
|
|
29
|
+
// For multipart, fetch sets Content-Type itself so it can include the boundary.
|
|
30
|
+
if (!form)
|
|
31
|
+
headers["Content-Type"] = "application/json";
|
|
30
32
|
const response = await fetch(url.toString(), {
|
|
31
33
|
method,
|
|
32
34
|
headers,
|
|
33
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
35
|
+
body: form ?? (body ? JSON.stringify(body) : undefined),
|
|
34
36
|
});
|
|
35
37
|
if (!response.ok) {
|
|
36
38
|
const errorBody = await response.text();
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const filePathsSchema: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
3
|
+
export interface LocalFile {
|
|
4
|
+
filename: string;
|
|
5
|
+
data: Uint8Array<ArrayBuffer>;
|
|
6
|
+
}
|
|
7
|
+
export interface Attachment {
|
|
8
|
+
id: number;
|
|
9
|
+
filename: string;
|
|
10
|
+
content_type: string;
|
|
11
|
+
byte_size: number;
|
|
12
|
+
url: string;
|
|
13
|
+
}
|
|
14
|
+
export declare function readLocalFiles(paths: string[]): Promise<LocalFile[]>;
|
|
15
|
+
export declare function buildMultipart(root: string, fields: Record<string, unknown>, files: LocalFile[]): FormData;
|
|
16
|
+
export declare function formatAttachments(attachments: Attachment[]): string;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { readFile, stat } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { basename, resolve } from "node:path";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
export const filePathsSchema = z
|
|
6
|
+
.array(z.string())
|
|
7
|
+
.optional()
|
|
8
|
+
.describe("Local file paths to attach (absolute, or ~/...). Uploaded to the issue alongside any other changes; existing attachments are kept.");
|
|
9
|
+
function expandPath(path) {
|
|
10
|
+
if (path === "~" || path.startsWith("~/")) {
|
|
11
|
+
return resolve(homedir(), path.slice(2));
|
|
12
|
+
}
|
|
13
|
+
return resolve(path);
|
|
14
|
+
}
|
|
15
|
+
// Reads every file up front so a bad path fails the call before anything is
|
|
16
|
+
// written, rather than leaving a half-created issue behind.
|
|
17
|
+
export async function readLocalFiles(paths) {
|
|
18
|
+
return Promise.all(paths.map(async (path) => {
|
|
19
|
+
const fullPath = expandPath(path);
|
|
20
|
+
const info = await stat(fullPath).catch(() => null);
|
|
21
|
+
if (!info?.isFile()) {
|
|
22
|
+
throw new Error(`Attachment not found or not a file: ${path}`);
|
|
23
|
+
}
|
|
24
|
+
const buffer = await readFile(fullPath);
|
|
25
|
+
return { filename: basename(fullPath), data: new Uint8Array(buffer) };
|
|
26
|
+
}));
|
|
27
|
+
}
|
|
28
|
+
// Encodes { root: fields, files } the way Rails parses multipart params:
|
|
29
|
+
// root[key]=value, root[key][]=each array item, root[files][]=each upload.
|
|
30
|
+
// An empty array is sent as a single blank item so it still clears the
|
|
31
|
+
// association (Rails drops blank ids), matching `label_ids: []` over JSON.
|
|
32
|
+
export function buildMultipart(root, fields, files) {
|
|
33
|
+
const form = new FormData();
|
|
34
|
+
for (const [key, value] of Object.entries(fields)) {
|
|
35
|
+
if (value === undefined || value === null)
|
|
36
|
+
continue;
|
|
37
|
+
if (Array.isArray(value)) {
|
|
38
|
+
if (value.length === 0)
|
|
39
|
+
form.append(`${root}[${key}][]`, "");
|
|
40
|
+
for (const item of value)
|
|
41
|
+
form.append(`${root}[${key}][]`, String(item));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
form.append(`${root}[${key}]`, String(value));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const file of files) {
|
|
48
|
+
// Content type is left to the server, which sniffs it from name + bytes.
|
|
49
|
+
form.append(`${root}[files][]`, new Blob([file.data]), file.filename);
|
|
50
|
+
}
|
|
51
|
+
return form;
|
|
52
|
+
}
|
|
53
|
+
function formatBytes(bytes) {
|
|
54
|
+
if (bytes < 1024)
|
|
55
|
+
return `${bytes} B`;
|
|
56
|
+
if (bytes < 1024 * 1024)
|
|
57
|
+
return `${(bytes / 1024).toFixed(1)} KB`;
|
|
58
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
59
|
+
}
|
|
60
|
+
export function formatAttachments(attachments) {
|
|
61
|
+
return attachments
|
|
62
|
+
.map((a) => `${a.filename} (${a.content_type}, ${formatBytes(a.byte_size)})`)
|
|
63
|
+
.join(", ");
|
|
64
|
+
}
|
package/dist/tools/comments.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { apiRequest } from "../api-client.js";
|
|
3
|
+
import { buildMultipart, filePathsSchema, formatAttachments, readLocalFiles, } from "../attachments.js";
|
|
3
4
|
function formatComment(comment, indent = 0) {
|
|
4
5
|
const pad = " ".repeat(indent);
|
|
5
6
|
const author = comment.user ? comment.user.name : "Unknown";
|
|
6
7
|
const lines = [
|
|
7
8
|
`${pad}#${comment.id} by ${author} at ${comment.created_at}`,
|
|
8
|
-
`${pad} ${comment.body}`,
|
|
9
|
+
`${pad} ${comment.body ?? ""}`,
|
|
9
10
|
];
|
|
11
|
+
if (comment.attachments && comment.attachments.length > 0) {
|
|
12
|
+
lines.push(`${pad} Attachments: ${formatAttachments(comment.attachments)}`);
|
|
13
|
+
}
|
|
10
14
|
if (comment.replies && comment.replies.length > 0) {
|
|
11
15
|
for (const reply of comment.replies) {
|
|
12
16
|
lines.push(formatComment(reply, indent + 1));
|
|
@@ -25,19 +29,24 @@ export function registerCommentTools(server) {
|
|
|
25
29
|
content: [{ type: "text", text: text || "No comments on this issue." }],
|
|
26
30
|
};
|
|
27
31
|
});
|
|
28
|
-
server.tool("create_comment", "Post a new comment on an issue. The author is derived from the API token. Pass parent_id to reply to an existing comment.", {
|
|
32
|
+
server.tool("create_comment", "Post a new comment on an issue. The author is derived from the API token. Pass parent_id to reply to an existing comment, and file_paths to attach local files.", {
|
|
29
33
|
team_id: z.number().describe("Team ID"),
|
|
30
34
|
issue_id: z.number().describe("Issue ID"),
|
|
31
|
-
body: z
|
|
35
|
+
body: z
|
|
36
|
+
.string()
|
|
37
|
+
.optional()
|
|
38
|
+
.describe("Comment text. May be omitted when file_paths is given."),
|
|
32
39
|
parent_id: z
|
|
33
40
|
.number()
|
|
34
41
|
.optional()
|
|
35
42
|
.describe("Parent comment ID to reply to"),
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
43
|
+
file_paths: filePathsSchema,
|
|
44
|
+
}, async ({ team_id, issue_id, body, parent_id, file_paths }) => {
|
|
45
|
+
const files = await readLocalFiles(file_paths ?? []);
|
|
46
|
+
const fields = { body, parent_id };
|
|
47
|
+
const comment = await apiRequest(`/api/v1/teams/${team_id}/issues/${issue_id}/comments`, files.length > 0
|
|
48
|
+
? { method: "POST", form: buildMultipart("comment", fields, files) }
|
|
49
|
+
: { method: "POST", body: { comment: fields } });
|
|
41
50
|
return {
|
|
42
51
|
content: [
|
|
43
52
|
{
|
package/dist/tools/issues.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { type Attachment } from "../attachments.js";
|
|
2
3
|
interface Issue {
|
|
3
4
|
id: number;
|
|
4
5
|
identifier: string;
|
|
@@ -27,6 +28,7 @@ interface Issue {
|
|
|
27
28
|
id: number;
|
|
28
29
|
name: string;
|
|
29
30
|
}[];
|
|
31
|
+
attachments?: Attachment[];
|
|
30
32
|
milestone?: {
|
|
31
33
|
id: number;
|
|
32
34
|
name: string;
|
package/dist/tools/issues.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
import { apiRequest } from "../api-client.js";
|
|
3
|
+
import { buildMultipart, filePathsSchema, formatAttachments, readLocalFiles, } from "../attachments.js";
|
|
3
4
|
const priorityEnum = z
|
|
4
5
|
.enum(["urgent", "high", "medium", "low", "no_priority"])
|
|
5
6
|
.describe("Issue priority");
|
|
@@ -21,6 +22,8 @@ export function formatIssue(issue, detailed = false) {
|
|
|
21
22
|
if (detailed) {
|
|
22
23
|
if (issue.description)
|
|
23
24
|
lines.push(` Description: ${issue.description}`);
|
|
25
|
+
if (issue.attachments && issue.attachments.length > 0)
|
|
26
|
+
lines.push(` Attachments: ${formatAttachments(issue.attachments)}`);
|
|
24
27
|
if (issue.milestone)
|
|
25
28
|
lines.push(` Milestone: ${issue.milestone.name}`);
|
|
26
29
|
if (issue.parent_issue)
|
|
@@ -46,6 +49,13 @@ export function formatIssue(issue, detailed = false) {
|
|
|
46
49
|
}
|
|
47
50
|
return lines.join("\n");
|
|
48
51
|
}
|
|
52
|
+
// create/update respond with the summary serializer, which omits attachments,
|
|
53
|
+
// so confirm what was uploaded from the request side.
|
|
54
|
+
function attachedNote(files) {
|
|
55
|
+
if (files.length === 0)
|
|
56
|
+
return "";
|
|
57
|
+
return `\n Attached: ${files.map((f) => f.filename).join(", ")}`;
|
|
58
|
+
}
|
|
49
59
|
export function registerIssueTools(server) {
|
|
50
60
|
server.tool("list_issues", "List issues for a team, with optional filters", {
|
|
51
61
|
team_id: z.number().describe("Team ID"),
|
|
@@ -116,7 +126,9 @@ export function registerIssueTools(server) {
|
|
|
116
126
|
estimate: z.number().optional().describe("Estimate value"),
|
|
117
127
|
milestone_id: z.number().optional().describe("Milestone ID"),
|
|
118
128
|
parent_issue_id: z.number().optional().describe("Parent issue ID"),
|
|
119
|
-
|
|
129
|
+
file_paths: filePathsSchema,
|
|
130
|
+
}, async ({ team_id, title, description, priority, lane_id, assignee_id, project_id, label_ids, due_date, estimate, milestone_id, parent_issue_id, file_paths, }) => {
|
|
131
|
+
const files = await readLocalFiles(file_paths ?? []);
|
|
120
132
|
let resolvedLaneId = lane_id;
|
|
121
133
|
if (!resolvedLaneId) {
|
|
122
134
|
const lanes = await apiRequest(`/api/v1/teams/${team_id}/lanes`);
|
|
@@ -133,29 +145,27 @@ export function registerIssueTools(server) {
|
|
|
133
145
|
}
|
|
134
146
|
resolvedLaneId = backlog.id;
|
|
135
147
|
}
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
},
|
|
153
|
-
});
|
|
148
|
+
const fields = {
|
|
149
|
+
title,
|
|
150
|
+
description,
|
|
151
|
+
priority: priority || "no_priority",
|
|
152
|
+
lane_id: resolvedLaneId,
|
|
153
|
+
assignee_id,
|
|
154
|
+
project_id,
|
|
155
|
+
label_ids,
|
|
156
|
+
due_date,
|
|
157
|
+
estimate,
|
|
158
|
+
milestone_id,
|
|
159
|
+
parent_issue_id,
|
|
160
|
+
};
|
|
161
|
+
const issue = await apiRequest(`/api/v1/teams/${team_id}/issues`, files.length > 0
|
|
162
|
+
? { method: "POST", form: buildMultipart("issue", fields, files) }
|
|
163
|
+
: { method: "POST", body: { issue: fields } });
|
|
154
164
|
return {
|
|
155
165
|
content: [
|
|
156
166
|
{
|
|
157
167
|
type: "text",
|
|
158
|
-
text: `Issue created successfully:\n\n${formatIssue(issue, true)}`,
|
|
168
|
+
text: `Issue created successfully:\n\n${formatIssue(issue, true)}${attachedNote(files)}`,
|
|
159
169
|
},
|
|
160
170
|
],
|
|
161
171
|
};
|
|
@@ -172,7 +182,9 @@ export function registerIssueTools(server) {
|
|
|
172
182
|
label_ids: z.array(z.number()).optional().describe("Set label IDs"),
|
|
173
183
|
due_date: z.string().optional().describe("Due date in YYYY-MM-DD format"),
|
|
174
184
|
estimate: z.number().optional().describe("Estimate value"),
|
|
175
|
-
|
|
185
|
+
file_paths: filePathsSchema,
|
|
186
|
+
}, async ({ team_id, issue_id, title, description, priority, lane_id, assignee_id, project_id, label_ids, due_date, estimate, file_paths, }) => {
|
|
187
|
+
const files = await readLocalFiles(file_paths ?? []);
|
|
176
188
|
const fields = {};
|
|
177
189
|
if (title !== undefined)
|
|
178
190
|
fields.title = title;
|
|
@@ -192,15 +204,14 @@ export function registerIssueTools(server) {
|
|
|
192
204
|
fields.due_date = due_date;
|
|
193
205
|
if (estimate !== undefined)
|
|
194
206
|
fields.estimate = estimate;
|
|
195
|
-
const issue = await apiRequest(`/api/v1/teams/${team_id}/issues/${issue_id}`,
|
|
196
|
-
method: "PATCH",
|
|
197
|
-
body: { issue: fields }
|
|
198
|
-
});
|
|
207
|
+
const issue = await apiRequest(`/api/v1/teams/${team_id}/issues/${issue_id}`, files.length > 0
|
|
208
|
+
? { method: "PATCH", form: buildMultipart("issue", fields, files) }
|
|
209
|
+
: { method: "PATCH", body: { issue: fields } });
|
|
199
210
|
return {
|
|
200
211
|
content: [
|
|
201
212
|
{
|
|
202
213
|
type: "text",
|
|
203
|
-
text: `Issue updated successfully:\n\n${formatIssue(issue, true)}`,
|
|
214
|
+
text: `Issue updated successfully:\n\n${formatIssue(issue, true)}${attachedNote(files)}`,
|
|
204
215
|
},
|
|
205
216
|
],
|
|
206
217
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@denvermullets/jait",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "MCP server for Just Another Issue Tracker",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -18,12 +18,12 @@
|
|
|
18
18
|
"prepublishOnly": "yarn build"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@modelcontextprotocol/sdk": "^1.
|
|
22
|
-
"zod": "^4.
|
|
21
|
+
"@modelcontextprotocol/sdk": "^1.30.1",
|
|
22
|
+
"zod": "^4.6.5"
|
|
23
23
|
},
|
|
24
24
|
"devDependencies": {
|
|
25
|
-
"@types/node": "^26.
|
|
26
|
-
"typescript": "^
|
|
25
|
+
"@types/node": "^26.6.3",
|
|
26
|
+
"typescript": "^7.0.2"
|
|
27
27
|
},
|
|
28
28
|
"engines": {
|
|
29
29
|
"node": ">=18.0.0"
|