@artyfacts/mcp-server 1.0.3 → 1.0.5

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.
@@ -0,0 +1,579 @@
1
+ // src/server.ts
2
+ import { Server } from "@modelcontextprotocol/sdk/server/index.js";
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import {
5
+ CallToolRequestSchema,
6
+ ListToolsRequestSchema
7
+ } from "@modelcontextprotocol/sdk/types.js";
8
+ var ARTYFACTS_TOOLS = [
9
+ // Organization tools
10
+ {
11
+ name: "get_organization",
12
+ description: "Get details about the current organization",
13
+ inputSchema: {
14
+ type: "object",
15
+ properties: {},
16
+ required: []
17
+ }
18
+ },
19
+ // Project tools
20
+ {
21
+ name: "list_projects",
22
+ description: "List all projects in the organization",
23
+ inputSchema: {
24
+ type: "object",
25
+ properties: {
26
+ limit: { type: "number", description: "Max results (default 50)" },
27
+ offset: { type: "number", description: "Pagination offset" }
28
+ },
29
+ required: []
30
+ }
31
+ },
32
+ {
33
+ name: "get_project",
34
+ description: "Get details about a specific project",
35
+ inputSchema: {
36
+ type: "object",
37
+ properties: {
38
+ project_id: { type: "string", description: "Project ID" }
39
+ },
40
+ required: ["project_id"]
41
+ }
42
+ },
43
+ // Artifact tools
44
+ {
45
+ name: "list_artifacts",
46
+ description: "List artifacts, optionally filtered by project",
47
+ inputSchema: {
48
+ type: "object",
49
+ properties: {
50
+ project_id: { type: "string", description: "Filter by project" },
51
+ type: { type: "string", description: "Filter by type (goal, spec, research, etc.)" },
52
+ status: { type: "string", description: "Filter by status" },
53
+ limit: { type: "number", description: "Max results" }
54
+ },
55
+ required: []
56
+ }
57
+ },
58
+ {
59
+ name: "get_artifact",
60
+ description: "Get a specific artifact by ID",
61
+ inputSchema: {
62
+ type: "object",
63
+ properties: {
64
+ artifact_id: { type: "string", description: "Artifact ID" }
65
+ },
66
+ required: ["artifact_id"]
67
+ }
68
+ },
69
+ {
70
+ name: "create_artifact",
71
+ description: "Create a new artifact (document, goal, spec, etc.)",
72
+ inputSchema: {
73
+ type: "object",
74
+ properties: {
75
+ title: { type: "string", description: "Artifact title" },
76
+ type: { type: "string", description: "Artifact type: goal, spec, research, report, experiment, decision, doc" },
77
+ content: { type: "string", description: "Markdown content" },
78
+ parent_id: { type: "string", description: "Parent artifact ID for nested artifacts" },
79
+ tags: { type: "array", items: { type: "string" }, description: "Tags for categorization" }
80
+ },
81
+ required: ["title", "type"]
82
+ }
83
+ },
84
+ {
85
+ name: "update_artifact",
86
+ description: "Update an existing artifact",
87
+ inputSchema: {
88
+ type: "object",
89
+ properties: {
90
+ artifact_id: { type: "string", description: "Artifact ID" },
91
+ title: { type: "string", description: "New title" },
92
+ content: { type: "string", description: "New content" },
93
+ status: { type: "string", description: "New status" }
94
+ },
95
+ required: ["artifact_id"]
96
+ }
97
+ },
98
+ // Section tools
99
+ {
100
+ name: "list_sections",
101
+ description: "List sections of an artifact",
102
+ inputSchema: {
103
+ type: "object",
104
+ properties: {
105
+ artifact_id: { type: "string", description: "Artifact ID" }
106
+ },
107
+ required: ["artifact_id"]
108
+ }
109
+ },
110
+ {
111
+ name: "get_section",
112
+ description: "Get a specific section",
113
+ inputSchema: {
114
+ type: "object",
115
+ properties: {
116
+ artifact_id: { type: "string", description: "Artifact ID" },
117
+ section_id: { type: "string", description: "Section ID" }
118
+ },
119
+ required: ["artifact_id", "section_id"]
120
+ }
121
+ },
122
+ {
123
+ name: "create_section",
124
+ description: "Create a new section on an artifact",
125
+ inputSchema: {
126
+ type: "object",
127
+ properties: {
128
+ artifact_id: { type: "string", description: "Artifact ID" },
129
+ section_id: { type: "string", description: "Section identifier (slug)" },
130
+ heading: { type: "string", description: "Section heading" },
131
+ content: { type: "string", description: "Markdown content" },
132
+ type: { type: "string", description: "Type: content, task, decision, blocker" },
133
+ position: { type: "number", description: "Order position" }
134
+ },
135
+ required: ["artifact_id", "section_id", "heading", "content"]
136
+ }
137
+ },
138
+ {
139
+ name: "update_section",
140
+ description: "Update an existing section",
141
+ inputSchema: {
142
+ type: "object",
143
+ properties: {
144
+ artifact_id: { type: "string", description: "Artifact ID" },
145
+ section_id: { type: "string", description: "Section ID" },
146
+ heading: { type: "string", description: "New heading" },
147
+ content: { type: "string", description: "New content" },
148
+ task_status: { type: "string", description: "Task status if type=task" }
149
+ },
150
+ required: ["artifact_id", "section_id"]
151
+ }
152
+ },
153
+ {
154
+ name: "delete_section",
155
+ description: "Delete a section",
156
+ inputSchema: {
157
+ type: "object",
158
+ properties: {
159
+ artifact_id: { type: "string", description: "Artifact ID" },
160
+ section_id: { type: "string", description: "Section ID" }
161
+ },
162
+ required: ["artifact_id", "section_id"]
163
+ }
164
+ },
165
+ // Task tools
166
+ {
167
+ name: "list_tasks",
168
+ description: "List tasks (sections with type=task)",
169
+ inputSchema: {
170
+ type: "object",
171
+ properties: {
172
+ artifact_id: { type: "string", description: "Filter by artifact" },
173
+ status: { type: "string", description: "Filter by status: pending, in_progress, done, blocked" },
174
+ assignee: { type: "string", description: "Filter by assignee agent" }
175
+ },
176
+ required: []
177
+ }
178
+ },
179
+ {
180
+ name: "claim_task",
181
+ description: "Claim a task for the current agent",
182
+ inputSchema: {
183
+ type: "object",
184
+ properties: {
185
+ task_id: { type: "string", description: "Task ID (section UUID)" }
186
+ },
187
+ required: ["task_id"]
188
+ }
189
+ },
190
+ {
191
+ name: "complete_task",
192
+ description: "Mark a task as complete",
193
+ inputSchema: {
194
+ type: "object",
195
+ properties: {
196
+ task_id: { type: "string", description: "Task ID" },
197
+ output_url: { type: "string", description: "URL to deliverable (PR, doc, etc.)" },
198
+ summary: { type: "string", description: "Completion summary" }
199
+ },
200
+ required: ["task_id"]
201
+ }
202
+ },
203
+ {
204
+ name: "block_task",
205
+ description: "Mark a task as blocked",
206
+ inputSchema: {
207
+ type: "object",
208
+ properties: {
209
+ task_id: { type: "string", description: "Task ID" },
210
+ reason: { type: "string", description: "Why it is blocked" },
211
+ blocker_type: { type: "string", description: "Type: decision, dependency, resource, external" }
212
+ },
213
+ required: ["task_id", "reason"]
214
+ }
215
+ },
216
+ // Agent tools
217
+ {
218
+ name: "list_agents",
219
+ description: "List all agents in the organization",
220
+ inputSchema: {
221
+ type: "object",
222
+ properties: {
223
+ status: { type: "string", description: "Filter by status: active, inactive" }
224
+ },
225
+ required: []
226
+ }
227
+ },
228
+ {
229
+ name: "get_agent",
230
+ description: "Get details about an agent",
231
+ inputSchema: {
232
+ type: "object",
233
+ properties: {
234
+ agent_id: { type: "string", description: "Agent ID" }
235
+ },
236
+ required: ["agent_id"]
237
+ }
238
+ },
239
+ {
240
+ name: "create_agent",
241
+ description: "Register a new AI agent with role, capabilities, and permissions",
242
+ inputSchema: {
243
+ type: "object",
244
+ properties: {
245
+ agentId: { type: "string", description: 'Unique agent ID (e.g., "engineering-agent", "qa-agent")' },
246
+ name: { type: "string", description: "Agent display name" },
247
+ role: { type: "string", description: "Role: pm, engineering, qa, research, content, design" },
248
+ description: { type: "string", description: "What this agent does - detailed description" },
249
+ capabilities: { type: "array", items: { type: "string" }, description: 'List of capabilities (e.g., ["code-review", "testing", "debugging"])' },
250
+ permissions: {
251
+ type: "object",
252
+ description: "Permission settings",
253
+ properties: {
254
+ write: { type: "boolean", description: "Can create/edit artifacts" },
255
+ delete: { type: "boolean", description: "Can delete artifacts" },
256
+ delegate_tasks: { type: "boolean", description: "Can assign tasks to other agents" }
257
+ }
258
+ },
259
+ systemPrompt: { type: "string", description: "System prompt for the agent" }
260
+ },
261
+ required: ["agentId", "name", "role", "description"]
262
+ }
263
+ },
264
+ {
265
+ name: "update_agent",
266
+ description: "Update an agent",
267
+ inputSchema: {
268
+ type: "object",
269
+ properties: {
270
+ agent_id: { type: "string", description: "Agent ID" },
271
+ name: { type: "string", description: "New name" },
272
+ status: { type: "string", description: "New status" },
273
+ config: { type: "object", description: "Updated config" }
274
+ },
275
+ required: ["agent_id"]
276
+ }
277
+ },
278
+ // Blocker tools
279
+ {
280
+ name: "list_blockers",
281
+ description: "List blockers (decisions, dependencies needing resolution)",
282
+ inputSchema: {
283
+ type: "object",
284
+ properties: {
285
+ artifact_id: { type: "string", description: "Filter by artifact" },
286
+ status: { type: "string", description: "Filter by status: open, resolved" }
287
+ },
288
+ required: []
289
+ }
290
+ },
291
+ {
292
+ name: "create_blocker",
293
+ description: "Create a blocker (decision request, dependency, etc.)",
294
+ inputSchema: {
295
+ type: "object",
296
+ properties: {
297
+ artifact_id: { type: "string", description: "Artifact ID" },
298
+ kind: { type: "string", description: "Kind: decision, dependency, resource, external" },
299
+ title: { type: "string", description: "Blocker title" },
300
+ description: { type: "string", description: "Details" },
301
+ options: { type: "array", description: "Options for decisions" },
302
+ blocked_tasks: { type: "array", items: { type: "string" }, description: "Task IDs blocked by this" }
303
+ },
304
+ required: ["artifact_id", "kind", "title"]
305
+ }
306
+ },
307
+ {
308
+ name: "resolve_blocker",
309
+ description: "Resolve a blocker",
310
+ inputSchema: {
311
+ type: "object",
312
+ properties: {
313
+ blocker_id: { type: "string", description: "Blocker ID" },
314
+ resolution: { type: "string", description: "How it was resolved" },
315
+ selected_option: { type: "string", description: "Selected option (for decisions)" }
316
+ },
317
+ required: ["blocker_id", "resolution"]
318
+ }
319
+ },
320
+ // Search tools
321
+ {
322
+ name: "search_artifacts",
323
+ description: "Search artifacts by text query",
324
+ inputSchema: {
325
+ type: "object",
326
+ properties: {
327
+ query: { type: "string", description: "Search query" },
328
+ type: { type: "string", description: "Filter by type" },
329
+ limit: { type: "number", description: "Max results" }
330
+ },
331
+ required: ["query"]
332
+ }
333
+ },
334
+ // Context tools
335
+ {
336
+ name: "get_task_context",
337
+ description: "Get full context for a task (org, project, artifact, related sections)",
338
+ inputSchema: {
339
+ type: "object",
340
+ properties: {
341
+ task_id: { type: "string", description: "Task ID" }
342
+ },
343
+ required: ["task_id"]
344
+ }
345
+ }
346
+ ];
347
+ var ArtyfactsApiClient = class {
348
+ constructor(baseUrl, apiKey) {
349
+ this.baseUrl = baseUrl;
350
+ this.apiKey = apiKey;
351
+ }
352
+ async request(method, path, body) {
353
+ const url = `${this.baseUrl}${path}`;
354
+ const response = await fetch(url, {
355
+ method,
356
+ headers: {
357
+ "Authorization": `Bearer ${this.apiKey}`,
358
+ "Content-Type": "application/json"
359
+ },
360
+ body: body ? JSON.stringify(body) : void 0
361
+ });
362
+ if (!response.ok) {
363
+ const error = await response.json().catch(() => ({ error: "Request failed" }));
364
+ throw new Error(error.error || `HTTP ${response.status}: ${response.statusText}`);
365
+ }
366
+ return response.json();
367
+ }
368
+ get(path) {
369
+ return this.request("GET", path);
370
+ }
371
+ post(path, body) {
372
+ return this.request("POST", path, body);
373
+ }
374
+ patch(path, body) {
375
+ return this.request("PATCH", path, body);
376
+ }
377
+ delete(path) {
378
+ return this.request("DELETE", path);
379
+ }
380
+ };
381
+ var toolHandlers = {
382
+ // Organization
383
+ get_organization: (client) => client.get("/org"),
384
+ // Projects
385
+ list_projects: (client, args) => {
386
+ const params = new URLSearchParams();
387
+ if (args.limit) params.set("limit", String(args.limit));
388
+ if (args.offset) params.set("offset", String(args.offset));
389
+ return client.get(`/projects?${params}`);
390
+ },
391
+ get_project: (client, args) => client.get(`/projects/${args.project_id}`),
392
+ // Artifacts
393
+ list_artifacts: (client, args) => {
394
+ const params = new URLSearchParams();
395
+ if (args.project_id) params.set("project_id", String(args.project_id));
396
+ if (args.type) params.set("type", String(args.type));
397
+ if (args.status) params.set("status", String(args.status));
398
+ if (args.limit) params.set("limit", String(args.limit));
399
+ return client.get(`/artifacts?${params}`);
400
+ },
401
+ get_artifact: (client, args) => client.get(`/artifacts/${args.artifact_id}`),
402
+ create_artifact: (client, args) => {
403
+ const envelope = {
404
+ aah_version: "0.3",
405
+ artifact: {
406
+ id: args.id || `artifact-${Date.now()}`,
407
+ title: args.title,
408
+ type: args.type || "document/sectioned",
409
+ artifact_type: args.artifact_type || args.type || "doc",
410
+ parent_id: args.parent_id,
411
+ tags: args.tags
412
+ },
413
+ content: args.content ? {
414
+ media_type: "text/markdown",
415
+ body: args.content
416
+ } : void 0,
417
+ source: {
418
+ agent_id: "mcp-agent"
419
+ }
420
+ };
421
+ return client.post("/artifacts", envelope);
422
+ },
423
+ update_artifact: (client, args) => {
424
+ const { artifact_id, ...body } = args;
425
+ return client.patch(`/artifacts/${artifact_id}`, body);
426
+ },
427
+ // Sections
428
+ list_sections: (client, args) => client.get(`/artifacts/${args.artifact_id}/sections`),
429
+ get_section: (client, args) => client.get(`/artifacts/${args.artifact_id}/sections/${args.section_id}`),
430
+ create_section: (client, args) => {
431
+ const { artifact_id, section_id, ...rest } = args;
432
+ const body = { id: section_id, ...rest };
433
+ return client.post(`/artifacts/${artifact_id}/sections`, body);
434
+ },
435
+ update_section: (client, args) => {
436
+ const { artifact_id, section_id, ...body } = args;
437
+ return client.patch(`/artifacts/${artifact_id}/sections/${section_id}`, body);
438
+ },
439
+ delete_section: (client, args) => client.delete(`/artifacts/${args.artifact_id}/sections/${args.section_id}`),
440
+ // Tasks
441
+ list_tasks: (client, args) => {
442
+ const params = new URLSearchParams();
443
+ if (args.artifact_id) params.set("artifact_id", String(args.artifact_id));
444
+ if (args.status) params.set("status", String(args.status));
445
+ if (args.assignee) params.set("assignee", String(args.assignee));
446
+ return client.get(`/tasks?${params}`);
447
+ },
448
+ claim_task: (client, args) => client.post(`/tasks/${args.task_id}/claim`),
449
+ complete_task: (client, args) => {
450
+ const { task_id, ...body } = args;
451
+ return client.post(`/tasks/${task_id}/complete`, body);
452
+ },
453
+ block_task: (client, args) => {
454
+ const { task_id, ...body } = args;
455
+ return client.post(`/tasks/${task_id}/block`, body);
456
+ },
457
+ // Agents
458
+ list_agents: (client, args) => {
459
+ const params = new URLSearchParams();
460
+ if (args.status) params.set("status", String(args.status));
461
+ return client.get(`/agents?${params}`);
462
+ },
463
+ get_agent: (client, args) => client.get(`/agents/${args.agent_id}`),
464
+ create_agent: (client, args) => {
465
+ const body = {
466
+ agentId: args.agentId,
467
+ name: args.name,
468
+ role: args.role,
469
+ description: args.description,
470
+ permissions: args.permissions || { write: true, delete: false, delegate_tasks: false },
471
+ metadata: {
472
+ capabilities: args.capabilities || [],
473
+ systemPrompt: args.systemPrompt,
474
+ createdVia: "mcp"
475
+ }
476
+ };
477
+ return client.post("/agents", body);
478
+ },
479
+ update_agent: (client, args) => {
480
+ const { agent_id, ...body } = args;
481
+ return client.patch(`/agents/${agent_id}`, body);
482
+ },
483
+ // Blockers
484
+ list_blockers: (client, args) => {
485
+ const params = new URLSearchParams();
486
+ if (args.artifact_id) params.set("artifact_id", String(args.artifact_id));
487
+ if (args.status) params.set("status", String(args.status));
488
+ return client.get(`/blockers?${params}`);
489
+ },
490
+ create_blocker: (client, args) => {
491
+ const { artifact_id, ...body } = args;
492
+ return client.post(`/artifacts/${artifact_id}/blockers`, body);
493
+ },
494
+ resolve_blocker: (client, args) => {
495
+ const { blocker_id, ...body } = args;
496
+ return client.post(`/blockers/${blocker_id}/resolve`, body);
497
+ },
498
+ // Search
499
+ search_artifacts: (client, args) => {
500
+ const params = new URLSearchParams();
501
+ params.set("q", String(args.query));
502
+ if (args.type) params.set("type", String(args.type));
503
+ if (args.limit) params.set("limit", String(args.limit));
504
+ return client.get(`/search?${params}`);
505
+ },
506
+ // Context
507
+ get_task_context: (client, args) => client.get(`/tasks/${args.task_id}/context`)
508
+ };
509
+ var ArtyfactsMcpServer = class {
510
+ server;
511
+ client;
512
+ config;
513
+ constructor(config) {
514
+ this.config = config;
515
+ this.client = new ArtyfactsApiClient(
516
+ config.baseUrl || "https://artyfacts.dev/api/v1",
517
+ config.apiKey
518
+ );
519
+ this.server = new Server(
520
+ {
521
+ name: config.name || "artyfacts-mcp",
522
+ version: config.version || "1.0.0"
523
+ },
524
+ {
525
+ capabilities: {
526
+ tools: {}
527
+ }
528
+ }
529
+ );
530
+ this.setupHandlers();
531
+ }
532
+ setupHandlers() {
533
+ this.server.setRequestHandler(ListToolsRequestSchema, async () => {
534
+ return { tools: ARTYFACTS_TOOLS };
535
+ });
536
+ this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
537
+ const { name, arguments: args } = request.params;
538
+ const handler = toolHandlers[name];
539
+ if (!handler) {
540
+ return {
541
+ content: [{ type: "text", text: `Unknown tool: ${name}` }],
542
+ isError: true
543
+ };
544
+ }
545
+ try {
546
+ const result = await handler(this.client, args || {});
547
+ return {
548
+ content: [{ type: "text", text: JSON.stringify(result, null, 2) }]
549
+ };
550
+ } catch (error) {
551
+ const message = error instanceof Error ? error.message : String(error);
552
+ return {
553
+ content: [{ type: "text", text: `Error: ${message}` }],
554
+ isError: true
555
+ };
556
+ }
557
+ });
558
+ }
559
+ async start() {
560
+ const transport = new StdioServerTransport();
561
+ await this.server.connect(transport);
562
+ console.error(`Artyfacts MCP server running (${ARTYFACTS_TOOLS.length} tools)`);
563
+ }
564
+ getServer() {
565
+ return this.server;
566
+ }
567
+ };
568
+ function createMcpServer(config) {
569
+ return new ArtyfactsMcpServer(config);
570
+ }
571
+ async function startServer(server) {
572
+ await server.start();
573
+ }
574
+
575
+ export {
576
+ ArtyfactsMcpServer,
577
+ createMcpServer,
578
+ startServer
579
+ };