-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmcp-server.ts
More file actions
358 lines (339 loc) · 9.79 KB
/
mcp-server.ts
File metadata and controls
358 lines (339 loc) · 9.79 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
import { z } from "zod";
const BASE_URL = process.env.PLANBOARD_URL || "http://localhost:3000";
async function api(path: string, options?: RequestInit) {
const res = await fetch(`${BASE_URL}${path}`, {
...options,
headers: { "Content-Type": "application/json", ...options?.headers },
});
if (!res.ok) {
const body = await res.text();
throw new Error(`API error ${res.status}: ${body}`);
}
return res.json();
}
const server = new McpServer({
name: "planboard",
version: "0.1.0",
});
server.tool("list_spaces", "List all spaces", {}, async () => {
const spaces = await api("/api/spaces");
return { content: [{ type: "text", text: JSON.stringify(spaces, null, 2) }] };
});
server.tool(
"list_projects",
"List all projects in a space",
{ space: z.string().describe("Space name") },
async ({ space }) => {
const projects = await api(`/api/spaces/${space}/projects`);
return {
content: [{ type: "text", text: JSON.stringify(projects, null, 2) }],
};
},
);
server.tool(
"list_plans",
"List all plans in a project",
{
space: z.string().describe("Space name"),
project: z.string().describe("Project slug"),
},
async ({ space, project }) => {
const plans = await api(
`/api/spaces/${space}/projects/${project}/plans`,
);
return {
content: [{ type: "text", text: JSON.stringify(plans, null, 2) }],
};
},
);
server.tool(
"read_plan",
"Read a plan's content",
{
space: z.string().describe("Space name"),
project: z.string().describe("Project slug"),
slug: z.string().describe("Plan slug"),
},
async ({ space, project, slug }) => {
const plan = await api(
`/api/spaces/${space}/projects/${project}/plans/${slug}`,
);
const comments = await api(`/api/plans/${plan.id}/comments`);
const parts = [plan.content];
if (Array.isArray(comments) && comments.length > 0) {
parts.push("\n\n---\n## Kommentarer\n");
for (const c of comments) {
const author = c.author?.name || "Anonym";
const date = new Date(c.createdAt).toLocaleString("sv");
parts.push(`**${author}** (${date}):\n${c.content}\n`);
}
}
return {
content: [{ type: "text", text: parts.join("\n") }],
};
},
);
server.tool(
"write_plan",
"Create or update a plan",
{
space: z.string().describe("Space name"),
project: z.string().describe("Project slug"),
slug: z.string().optional().describe("Plan slug (omit to create new)"),
content: z.string().describe("Markdown content"),
title: z.string().optional().describe("Plan title (optional)"),
},
async ({ space, project, slug, content, title }) => {
let plan;
if (slug) {
// Update existing
plan = await api(
`/api/spaces/${space}/projects/${project}/plans/${slug}`,
{
method: "PUT",
body: JSON.stringify({ content, title }),
},
);
} else {
// Create new
plan = await api(
`/api/spaces/${space}/projects/${project}/plans`,
{
method: "POST",
body: JSON.stringify({ content, title: title || "Namnlös plan" }),
},
);
}
return {
content: [
{
type: "text",
text: `Plan saved: ${space}/${project}/${plan.slug} (${plan.title})`,
},
],
};
},
);
server.tool(
"delete_plan",
"Delete a plan",
{
space: z.string().describe("Space name"),
project: z.string().describe("Project slug"),
slug: z.string().describe("Plan slug"),
},
async ({ space, project, slug }) => {
await api(
`/api/spaces/${space}/projects/${project}/plans/${slug}`,
{ method: "DELETE" },
);
return {
content: [
{ type: "text", text: `Plan deleted: ${space}/${project}/${slug}` },
],
};
},
);
// --- Findings ---
server.tool(
"list_findings",
"List findings in a project, optionally filtered by status",
{
space: z.string().describe("Space name"),
project: z.string().describe("Project slug"),
status: z
.enum(["draft", "open", "in_progress", "resolved", "dismissed"])
.optional()
.describe("Filter by status"),
},
async ({ space, project, status }) => {
const query = status ? `?status=${status}` : "";
const list = await api(
`/api/spaces/${space}/projects/${project}/findings${query}`,
);
return {
content: [{ type: "text", text: JSON.stringify(list, null, 2) }],
};
},
);
server.tool(
"read_finding",
"Read a finding with its comments",
{
id: z.string().describe("Finding ID"),
},
async ({ id }) => {
const finding = await api(`/api/findings/${id}`);
const comments = await api(`/api/findings/${id}/comments`);
const parts = [
`# ${finding.title}`,
`**Status:** ${finding.status} | **Prioritet:** ${finding.priority}`,
finding.assignee ? `**Tilldelad:** ${finding.assignee.name}` : "",
finding.tags?.length ? `**Taggar:** ${finding.tags.join(", ")}` : "",
"",
finding.description || "*Ingen beskrivning*",
];
if (Array.isArray(comments) && comments.length > 0) {
parts.push("\n---\n## Kommentarer\n");
for (const c of comments) {
const author = c.author?.name || "Anonym";
const date = new Date(c.createdAt).toLocaleString("sv");
parts.push(`**${author}** (${date}):\n${c.content}\n`);
}
}
return {
content: [{ type: "text", text: parts.filter(Boolean).join("\n") }],
};
},
);
server.tool(
"comment_on_finding",
"Add a comment to a finding",
{
id: z.string().describe("Finding ID"),
content: z.string().describe("Comment content (markdown)"),
authorId: z.string().optional().describe("Profile ID of the author"),
},
async ({ id, content, authorId }) => {
const comment = await api(`/api/findings/${id}/comments`, {
method: "POST",
body: JSON.stringify({ content, authorId }),
});
const author = comment.author?.name || "Anonym";
return {
content: [
{
type: "text",
text: `Comment added by ${author} on finding ${id}`,
},
],
};
},
);
server.tool(
"comment_on_plan",
"Add a comment to a plan",
{
space: z.string().describe("Space name"),
project: z.string().describe("Project slug"),
slug: z.string().describe("Plan slug"),
content: z.string().describe("Comment content (markdown)"),
authorId: z.string().optional().describe("Profile ID of the author"),
},
async ({ space, project, slug, content, authorId }) => {
// Get plan ID from slug
const plan = await api(
`/api/spaces/${space}/projects/${project}/plans/${slug}`,
);
const comment = await api(`/api/plans/${plan.id}/comments`, {
method: "POST",
body: JSON.stringify({ content, authorId }),
});
const author = comment.author?.name || "Anonym";
return {
content: [
{
type: "text",
text: `Comment added by ${author} on plan ${space}/${project}/${slug}`,
},
],
};
},
);
server.tool(
"create_finding",
"Create a new finding (discovery, issue, note) in a project",
{
space: z.string().describe("Space name"),
project: z.string().describe("Project slug"),
title: z.string().describe("Finding title"),
description: z.string().optional().describe("Detailed description"),
priority: z
.enum(["low", "medium", "high", "critical"])
.optional()
.describe("Priority level (default: medium)"),
tags: z
.array(z.string())
.optional()
.describe("Tags for categorization"),
},
async ({ space, project, title, description, priority, tags }) => {
const finding = await api(
`/api/spaces/${space}/projects/${project}/findings`,
{
method: "POST",
body: JSON.stringify({ title, description, priority, tags }),
},
);
return {
content: [
{
type: "text",
text: `Finding created: "${finding.title}" [${finding.priority}] (${finding.id})`,
},
],
};
},
);
server.tool(
"update_finding",
"Update a finding's status, priority, or details",
{
space: z.string().describe("Space name"),
project: z.string().describe("Project slug"),
id: z.string().describe("Finding ID"),
title: z.string().optional().describe("New title"),
description: z.string().optional().describe("New description"),
status: z
.enum(["draft", "open", "in_progress", "resolved", "dismissed"])
.optional()
.describe("New status"),
priority: z
.enum(["low", "medium", "high", "critical"])
.optional()
.describe("New priority"),
tags: z.array(z.string()).optional().describe("New tags"),
},
async ({ space, project, id, ...updates }) => {
const finding = await api(
`/api/spaces/${space}/projects/${project}/findings/${id}`,
{
method: "PUT",
body: JSON.stringify(updates),
},
);
return {
content: [
{
type: "text",
text: `Finding updated: "${finding.title}" → ${finding.status} [${finding.priority}]`,
},
],
};
},
);
server.tool(
"delete_finding",
"Delete a finding",
{
space: z.string().describe("Space name"),
project: z.string().describe("Project slug"),
id: z.string().describe("Finding ID"),
},
async ({ space, project, id }) => {
await api(
`/api/spaces/${space}/projects/${project}/findings/${id}`,
{ method: "DELETE" },
);
return {
content: [{ type: "text", text: `Finding deleted: ${id}` }],
};
},
);
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
}
main().catch(console.error);