@knitmd/mcp 0.0.0-stage → 0.1.1
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/LICENSE +21 -0
- package/README.md +12 -2
- package/dist/index.d.ts +69 -0
- package/dist/index.js +361 -0
- package/package.json +26 -4
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Miikka Lammela
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @knitmd/mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The MCP server of [Knit](https://github.com/knitmd/knit): ticket tools and reports for agents
|
|
4
|
+
over the Model Context Protocol (stdio). It is optional: install it next to the `nit` command
|
|
5
|
+
to enable `nit mcp`.
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
npm install --global knitmd @knitmd/mcp
|
|
9
|
+
nit init --mcp # registers `nit mcp` for Claude Code and VS Code
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
The package implements the protocol without dependencies; every tool runs a `nit` command line,
|
|
13
|
+
so agents get the same rules and messages as the command line (ADR 0018 in the repository).
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Knit MCP server: JSON-RPC 2.0 over newline-delimited stdio (the MCP stdio
|
|
3
|
+
* transport), without dependencies.
|
|
4
|
+
*
|
|
5
|
+
* The server does not know the tracker: every tool is a `nit` command line, run through the
|
|
6
|
+
* `run` callback of the front end, so tools and the CLI share the rules and the messages.
|
|
7
|
+
*/
|
|
8
|
+
/** The result of one `nit` command line. */
|
|
9
|
+
export interface RunResult {
|
|
10
|
+
code: number;
|
|
11
|
+
out: string;
|
|
12
|
+
err: string;
|
|
13
|
+
}
|
|
14
|
+
/** Runs `nit <argv>` and returns its output. */
|
|
15
|
+
export type Runner = (argv: string[]) => RunResult;
|
|
16
|
+
/** A resource the server offers, read on demand. */
|
|
17
|
+
export interface Resource {
|
|
18
|
+
uri: string;
|
|
19
|
+
name: string;
|
|
20
|
+
description: string;
|
|
21
|
+
mimeType: string;
|
|
22
|
+
read: () => string;
|
|
23
|
+
}
|
|
24
|
+
export interface ServerOptions {
|
|
25
|
+
name: string;
|
|
26
|
+
version: string;
|
|
27
|
+
run: Runner;
|
|
28
|
+
resources?: Resource[];
|
|
29
|
+
instructions?: string;
|
|
30
|
+
}
|
|
31
|
+
type Args = Record<string, unknown>;
|
|
32
|
+
/** A tool: its MCP description and the command line it runs. */
|
|
33
|
+
export interface Tool {
|
|
34
|
+
name: string;
|
|
35
|
+
title: string;
|
|
36
|
+
description: string;
|
|
37
|
+
inputSchema: {
|
|
38
|
+
type: 'object';
|
|
39
|
+
properties: Record<string, unknown>;
|
|
40
|
+
required?: string[];
|
|
41
|
+
};
|
|
42
|
+
argv: (a: Args) => string[];
|
|
43
|
+
/** The command prints JSON (`--json`), returned as structured content. */
|
|
44
|
+
json?: string;
|
|
45
|
+
readOnly?: boolean;
|
|
46
|
+
}
|
|
47
|
+
export declare const PROTOCOL_VERSIONS: string[];
|
|
48
|
+
/** The tools: the everyday ticket commands. */
|
|
49
|
+
export declare const TOOLS: Tool[];
|
|
50
|
+
interface Message {
|
|
51
|
+
jsonrpc: '2.0';
|
|
52
|
+
id?: string | number | null;
|
|
53
|
+
method?: string;
|
|
54
|
+
params?: Record<string, unknown>;
|
|
55
|
+
}
|
|
56
|
+
/** The protocol handler: one message in, at most one message out. */
|
|
57
|
+
export declare class Server {
|
|
58
|
+
readonly options: ServerOptions;
|
|
59
|
+
readonly tools: Tool[];
|
|
60
|
+
constructor(options: ServerOptions, tools?: Tool[]);
|
|
61
|
+
/** Handles one line of the stdio transport; returns the response line, or undefined. */
|
|
62
|
+
handleLine(line: string): string | undefined;
|
|
63
|
+
handle(msg: Message): object | undefined;
|
|
64
|
+
private dispatch;
|
|
65
|
+
private call;
|
|
66
|
+
}
|
|
67
|
+
/** Serves on a stream pair (stdin/stdout); resolves when the input ends. */
|
|
68
|
+
export declare function serve(server: Server, input: NodeJS.ReadableStream, write: (line: string) => void): Promise<void>;
|
|
69
|
+
export {};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Knit MCP server: JSON-RPC 2.0 over newline-delimited stdio (the MCP stdio
|
|
3
|
+
* transport), without dependencies.
|
|
4
|
+
*
|
|
5
|
+
* The server does not know the tracker: every tool is a `nit` command line, run through the
|
|
6
|
+
* `run` callback of the front end, so tools and the CLI share the rules and the messages.
|
|
7
|
+
*/
|
|
8
|
+
export const PROTOCOL_VERSIONS = ['2025-06-18', '2025-03-26', '2024-11-05'];
|
|
9
|
+
const str = (description) => ({ type: 'string', description });
|
|
10
|
+
const strs = (description) => ({ type: 'array', items: { type: 'string' }, description });
|
|
11
|
+
const bool = (description) => ({ type: 'boolean', description });
|
|
12
|
+
const ID = str('Ticket ID, such as SHOP-12.');
|
|
13
|
+
function text(a, key) {
|
|
14
|
+
const v = a[key];
|
|
15
|
+
if (v === undefined || v === null || v === '')
|
|
16
|
+
return undefined;
|
|
17
|
+
if (typeof v !== 'string' && typeof v !== 'number')
|
|
18
|
+
throw new ToolInputError(`'${key}' must be a string`);
|
|
19
|
+
return String(v);
|
|
20
|
+
}
|
|
21
|
+
function need(a, key) {
|
|
22
|
+
const v = text(a, key);
|
|
23
|
+
if (v === undefined)
|
|
24
|
+
throw new ToolInputError(`'${key}' is required`);
|
|
25
|
+
return v;
|
|
26
|
+
}
|
|
27
|
+
function list(a, key) {
|
|
28
|
+
const v = a[key];
|
|
29
|
+
if (v === undefined || v === null)
|
|
30
|
+
return [];
|
|
31
|
+
if (Array.isArray(v))
|
|
32
|
+
return v.map(String);
|
|
33
|
+
return [String(v)];
|
|
34
|
+
}
|
|
35
|
+
function flag(a, key, name = key) {
|
|
36
|
+
return a[key] === true ? [`--${name}`] : [];
|
|
37
|
+
}
|
|
38
|
+
function opt(a, key, name = key) {
|
|
39
|
+
const v = text(a, key);
|
|
40
|
+
return v === undefined ? [] : [`--${name}`, v];
|
|
41
|
+
}
|
|
42
|
+
function fields(a) {
|
|
43
|
+
const v = a.fields;
|
|
44
|
+
if (v === undefined || v === null)
|
|
45
|
+
return [];
|
|
46
|
+
if (typeof v !== 'object' || Array.isArray(v))
|
|
47
|
+
throw new ToolInputError("'fields' must be an object");
|
|
48
|
+
return Object.entries(v).map(([k, x]) => `${k}=${Array.isArray(x) ? `[${x.map(String).join(', ')}]` : x === null ? '' : String(x)}`);
|
|
49
|
+
}
|
|
50
|
+
class ToolInputError extends Error {
|
|
51
|
+
}
|
|
52
|
+
/** The tools: the everyday ticket commands. */
|
|
53
|
+
export const TOOLS = [
|
|
54
|
+
{
|
|
55
|
+
name: 'list',
|
|
56
|
+
title: 'List tickets',
|
|
57
|
+
description: 'List tickets with their status, assignee and tags. Open tickets by default; filters combine. `in` lists the tickets that the commits of a Git range refer to.',
|
|
58
|
+
inputSchema: {
|
|
59
|
+
type: 'object',
|
|
60
|
+
properties: {
|
|
61
|
+
status: strs('Only these statuses.'),
|
|
62
|
+
assignee: str('Only tickets of this person or team:<name>.'),
|
|
63
|
+
milestone: str('Only this milestone.'),
|
|
64
|
+
tag: strs('Only tickets with these tags; `ns:` matches any value of a namespace.'),
|
|
65
|
+
type: str('Only this ticket type.'),
|
|
66
|
+
in: str('A Git range such as v1.3..v1.4.'),
|
|
67
|
+
all: bool('Include closed tickets.'),
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
argv: (a) => [
|
|
71
|
+
'list',
|
|
72
|
+
...list(a, 'status').flatMap((s) => ['--status', s]),
|
|
73
|
+
...opt(a, 'assignee'),
|
|
74
|
+
...opt(a, 'milestone'),
|
|
75
|
+
...list(a, 'tag').flatMap((s) => ['--tag', s]),
|
|
76
|
+
...opt(a, 'type'),
|
|
77
|
+
...opt(a, 'in'),
|
|
78
|
+
...flag(a, 'all'),
|
|
79
|
+
'--json',
|
|
80
|
+
],
|
|
81
|
+
json: 'tickets',
|
|
82
|
+
readOnly: true,
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
name: 'show',
|
|
86
|
+
title: 'Show a ticket',
|
|
87
|
+
description: 'A ticket with its fields, body sections, acceptance criteria (numbered for `tick`), children of an epic and the commits that refer to it.',
|
|
88
|
+
inputSchema: { type: 'object', properties: { id: ID }, required: ['id'] },
|
|
89
|
+
argv: (a) => ['show', need(a, 'id'), '--json'],
|
|
90
|
+
json: 'ticket',
|
|
91
|
+
readOnly: true,
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'next',
|
|
95
|
+
title: 'Next tickets',
|
|
96
|
+
description: 'The ready, unblocked, unclaimed tickets in work order: what to start next.',
|
|
97
|
+
inputSchema: {
|
|
98
|
+
type: 'object',
|
|
99
|
+
properties: { assignee: str('Only tickets of this person.'), limit: { type: 'number' } },
|
|
100
|
+
},
|
|
101
|
+
argv: (a) => ['next', ...opt(a, 'assignee'), ...opt(a, 'limit'), '--json'],
|
|
102
|
+
json: 'tickets',
|
|
103
|
+
readOnly: true,
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'inbox',
|
|
107
|
+
title: 'Inbox',
|
|
108
|
+
description: 'What waits for a person, team or role: tickets in a status they own, open questions addressed to them, and approvals, with the waiting time. Defaults to the current person.',
|
|
109
|
+
inputSchema: {
|
|
110
|
+
type: 'object',
|
|
111
|
+
properties: {
|
|
112
|
+
for: str('A person, team:<name>, role or agent.'),
|
|
113
|
+
all: bool('Everything that waits, for anyone.'),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
argv: (a) => ['inbox', ...opt(a, 'for'), ...flag(a, 'all'), '--json'],
|
|
117
|
+
json: 'items',
|
|
118
|
+
readOnly: true,
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: 'new',
|
|
122
|
+
title: 'Create a ticket',
|
|
123
|
+
description: 'Create a ticket with the next free ID in the first status. Write the Goal and acceptance criteria into the file afterwards, or ask a person to.',
|
|
124
|
+
inputSchema: {
|
|
125
|
+
type: 'object',
|
|
126
|
+
properties: {
|
|
127
|
+
type: str('The ticket type, such as feature, bug or epic.'),
|
|
128
|
+
title: str('One line.'),
|
|
129
|
+
fields: {
|
|
130
|
+
type: 'object',
|
|
131
|
+
description: 'Other fields, such as {"priority": "high", "tags": ["verify:manual"]}.',
|
|
132
|
+
},
|
|
133
|
+
},
|
|
134
|
+
required: ['type', 'title'],
|
|
135
|
+
},
|
|
136
|
+
argv: (a) => ['new', need(a, 'type'), need(a, 'title'), ...fields(a)],
|
|
137
|
+
},
|
|
138
|
+
{
|
|
139
|
+
name: 'set',
|
|
140
|
+
title: 'Change ticket fields',
|
|
141
|
+
description: 'Change fields of a ticket; an empty value removes a field. A status change follows the workflow: the error lists the allowed moves. Agents never approve (move a ticket to ready).',
|
|
142
|
+
inputSchema: {
|
|
143
|
+
type: 'object',
|
|
144
|
+
properties: { id: ID, fields: { type: 'object', description: 'Such as {"status": "review"}.' } },
|
|
145
|
+
required: ['id', 'fields'],
|
|
146
|
+
},
|
|
147
|
+
argv: (a) => ['set', need(a, 'id'), ...fields(a)],
|
|
148
|
+
},
|
|
149
|
+
{
|
|
150
|
+
name: 'tick',
|
|
151
|
+
title: 'Check acceptance criteria',
|
|
152
|
+
description: 'Check acceptance criteria by number, as `show` lists them; `undo` unchecks.',
|
|
153
|
+
inputSchema: {
|
|
154
|
+
type: 'object',
|
|
155
|
+
properties: { id: ID, criteria: { type: 'array', items: { type: 'number' } }, undo: bool('Uncheck.') },
|
|
156
|
+
required: ['id', 'criteria'],
|
|
157
|
+
},
|
|
158
|
+
argv: (a) => ['tick', need(a, 'id'), ...list(a, 'criteria'), ...flag(a, 'undo')],
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: 'log',
|
|
162
|
+
title: 'Add a log line',
|
|
163
|
+
description: 'Append a dated line to the ticket log: decisions, dead ends, handoff notes.',
|
|
164
|
+
inputSchema: { type: 'object', properties: { id: ID, text: str('One line.') }, required: ['id', 'text'] },
|
|
165
|
+
argv: (a) => ['log', need(a, 'id'), need(a, 'text')],
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
name: 'start',
|
|
169
|
+
title: 'Start a ticket',
|
|
170
|
+
description: 'Claim a ready ticket: its branch is created and the claim pushed. Optionally in a new worktree.',
|
|
171
|
+
inputSchema: { type: 'object', properties: { id: ID, worktree: bool('Create a worktree.') }, required: ['id'] },
|
|
172
|
+
argv: (a) => ['start', need(a, 'id'), ...flag(a, 'worktree')],
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: 'finish',
|
|
176
|
+
title: 'Finish a ticket',
|
|
177
|
+
description: 'Verify that every acceptance criterion is checked, move the ticket to the finish status with a Closes: commit, and push.',
|
|
178
|
+
inputSchema: { type: 'object', properties: { id: ID, pr: bool('Open a pull request.') }, required: ['id'] },
|
|
179
|
+
argv: (a) => ['finish', need(a, 'id'), ...flag(a, 'pr')],
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: 'attach',
|
|
183
|
+
title: 'Attach a file or link',
|
|
184
|
+
description: 'Attach a file (copied under attachments/<ID>/) or a URL to a ticket, with a note on what it contains.',
|
|
185
|
+
inputSchema: {
|
|
186
|
+
type: 'object',
|
|
187
|
+
properties: { id: ID, source: str('A file path or URL.'), note: str('What it contains.') },
|
|
188
|
+
required: ['id', 'source', 'note'],
|
|
189
|
+
},
|
|
190
|
+
argv: (a) => ['attach', need(a, 'id'), need(a, 'source'), '--note', need(a, 'note')],
|
|
191
|
+
},
|
|
192
|
+
{
|
|
193
|
+
name: 'check',
|
|
194
|
+
title: 'Validate the tracker',
|
|
195
|
+
description: 'Validate every ticket against the rules; errors and warnings with file and line.',
|
|
196
|
+
inputSchema: { type: 'object', properties: {} },
|
|
197
|
+
argv: () => ['check'],
|
|
198
|
+
readOnly: true,
|
|
199
|
+
},
|
|
200
|
+
];
|
|
201
|
+
const PARSE_ERROR = -32700;
|
|
202
|
+
const INVALID_REQUEST = -32600;
|
|
203
|
+
const METHOD_NOT_FOUND = -32601;
|
|
204
|
+
const INVALID_PARAMS = -32602;
|
|
205
|
+
/** The protocol handler: one message in, at most one message out. */
|
|
206
|
+
export class Server {
|
|
207
|
+
options;
|
|
208
|
+
tools;
|
|
209
|
+
constructor(options, tools = TOOLS) {
|
|
210
|
+
this.options = options;
|
|
211
|
+
this.tools = tools;
|
|
212
|
+
}
|
|
213
|
+
/** Handles one line of the stdio transport; returns the response line, or undefined. */
|
|
214
|
+
handleLine(line) {
|
|
215
|
+
if (line.trim() === '')
|
|
216
|
+
return undefined;
|
|
217
|
+
let msg;
|
|
218
|
+
try {
|
|
219
|
+
msg = JSON.parse(line);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return JSON.stringify(failure(null, PARSE_ERROR, 'parse error'));
|
|
223
|
+
}
|
|
224
|
+
const res = this.handle(msg);
|
|
225
|
+
return res === undefined ? undefined : JSON.stringify(res);
|
|
226
|
+
}
|
|
227
|
+
handle(msg) {
|
|
228
|
+
if (typeof msg !== 'object' || msg === null || typeof msg.method !== 'string') {
|
|
229
|
+
// Responses to our requests (we send none) and malformed messages.
|
|
230
|
+
return msg && 'id' in msg && !('result' in msg || 'error' in msg)
|
|
231
|
+
? failure(msg.id ?? null, INVALID_REQUEST, 'invalid request')
|
|
232
|
+
: undefined;
|
|
233
|
+
}
|
|
234
|
+
const isNotification = msg.id === undefined;
|
|
235
|
+
try {
|
|
236
|
+
const result = this.dispatch(msg.method, msg.params ?? {});
|
|
237
|
+
if (isNotification)
|
|
238
|
+
return undefined;
|
|
239
|
+
if (result === undefined)
|
|
240
|
+
return failure(msg.id ?? null, METHOD_NOT_FOUND, `unknown method ${msg.method}`);
|
|
241
|
+
return { jsonrpc: '2.0', id: msg.id, result };
|
|
242
|
+
}
|
|
243
|
+
catch (e) {
|
|
244
|
+
if (isNotification)
|
|
245
|
+
return undefined;
|
|
246
|
+
const code = e instanceof ProtocolError ? e.code : -32603;
|
|
247
|
+
return failure(msg.id ?? null, code, e.message);
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
dispatch(method, params) {
|
|
251
|
+
switch (method) {
|
|
252
|
+
case 'initialize': {
|
|
253
|
+
const asked = typeof params.protocolVersion === 'string' ? params.protocolVersion : '';
|
|
254
|
+
return {
|
|
255
|
+
protocolVersion: PROTOCOL_VERSIONS.includes(asked) ? asked : PROTOCOL_VERSIONS[0],
|
|
256
|
+
capabilities: { tools: {}, resources: {} },
|
|
257
|
+
serverInfo: { name: this.options.name, version: this.options.version },
|
|
258
|
+
...(this.options.instructions ? { instructions: this.options.instructions } : {}),
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
case 'ping':
|
|
262
|
+
return {};
|
|
263
|
+
case 'notifications/initialized':
|
|
264
|
+
case 'notifications/cancelled':
|
|
265
|
+
return {};
|
|
266
|
+
case 'tools/list':
|
|
267
|
+
return {
|
|
268
|
+
tools: this.tools.map((t) => ({
|
|
269
|
+
name: t.name,
|
|
270
|
+
title: t.title,
|
|
271
|
+
description: t.description,
|
|
272
|
+
inputSchema: t.inputSchema,
|
|
273
|
+
annotations: { readOnlyHint: t.readOnly === true, openWorldHint: false },
|
|
274
|
+
})),
|
|
275
|
+
};
|
|
276
|
+
case 'tools/call':
|
|
277
|
+
return this.call(params);
|
|
278
|
+
case 'resources/list':
|
|
279
|
+
return {
|
|
280
|
+
resources: (this.options.resources ?? []).map(({ read: _, ...r }) => r),
|
|
281
|
+
};
|
|
282
|
+
case 'resources/read': {
|
|
283
|
+
const r = (this.options.resources ?? []).find((x) => x.uri === params.uri);
|
|
284
|
+
if (!r)
|
|
285
|
+
throw new ProtocolError(INVALID_PARAMS, `unknown resource ${String(params.uri)}`);
|
|
286
|
+
return { contents: [{ uri: r.uri, mimeType: r.mimeType, text: r.read() }] };
|
|
287
|
+
}
|
|
288
|
+
default:
|
|
289
|
+
return undefined;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
call(params) {
|
|
293
|
+
const tool = this.tools.find((t) => t.name === params.name);
|
|
294
|
+
if (!tool)
|
|
295
|
+
throw new ProtocolError(INVALID_PARAMS, `unknown tool ${String(params.name)}`);
|
|
296
|
+
let argv;
|
|
297
|
+
try {
|
|
298
|
+
argv = tool.argv((params.arguments ?? {}));
|
|
299
|
+
}
|
|
300
|
+
catch (e) {
|
|
301
|
+
if (e instanceof ToolInputError)
|
|
302
|
+
return toolError(`${tool.name}: ${e.message}`);
|
|
303
|
+
throw e;
|
|
304
|
+
}
|
|
305
|
+
const r = this.options.run(argv);
|
|
306
|
+
if (r.code !== 0)
|
|
307
|
+
return toolError([r.err, r.out].filter(Boolean).join('\n') || `exit code ${r.code}`);
|
|
308
|
+
if (tool.json) {
|
|
309
|
+
try {
|
|
310
|
+
const data = JSON.parse(r.out);
|
|
311
|
+
return {
|
|
312
|
+
content: [{ type: 'text', text: r.out }],
|
|
313
|
+
structuredContent: Array.isArray(data) ? { [tool.json]: data } : data,
|
|
314
|
+
};
|
|
315
|
+
}
|
|
316
|
+
catch {
|
|
317
|
+
// Not JSON after all: return the text.
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
const textOut = [r.out, r.err].filter(Boolean).join('\n');
|
|
321
|
+
return { content: [{ type: 'text', text: textOut || 'ok' }] };
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
class ProtocolError extends Error {
|
|
325
|
+
code;
|
|
326
|
+
constructor(code, message) {
|
|
327
|
+
super(message);
|
|
328
|
+
this.code = code;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
function failure(id, code, message) {
|
|
332
|
+
return { jsonrpc: '2.0', id, error: { code, message } };
|
|
333
|
+
}
|
|
334
|
+
function toolError(message) {
|
|
335
|
+
return { content: [{ type: 'text', text: message }], isError: true };
|
|
336
|
+
}
|
|
337
|
+
/** Serves on a stream pair (stdin/stdout); resolves when the input ends. */
|
|
338
|
+
export function serve(server, input, write) {
|
|
339
|
+
return new Promise((resolve) => {
|
|
340
|
+
let buffer = '';
|
|
341
|
+
input.setEncoding('utf8');
|
|
342
|
+
input.on('data', (chunk) => {
|
|
343
|
+
buffer += chunk;
|
|
344
|
+
let i = buffer.indexOf('\n');
|
|
345
|
+
while (i >= 0) {
|
|
346
|
+
const line = buffer.slice(0, i);
|
|
347
|
+
buffer = buffer.slice(i + 1);
|
|
348
|
+
const out = server.handleLine(line);
|
|
349
|
+
if (out !== undefined)
|
|
350
|
+
write(`${out}\n`);
|
|
351
|
+
i = buffer.indexOf('\n');
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
input.on('end', () => {
|
|
355
|
+
const out = server.handleLine(buffer);
|
|
356
|
+
if (out !== undefined)
|
|
357
|
+
write(`${out}\n`);
|
|
358
|
+
resolve();
|
|
359
|
+
});
|
|
360
|
+
});
|
|
361
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,28 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@knitmd/mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "The Knit MCP server: ticket tools and reports for agents over the Model Context Protocol (stdio).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"engines": {
|
|
14
|
+
"node": ">=22.18"
|
|
15
|
+
},
|
|
16
|
+
"repository": {
|
|
17
|
+
"type": "git",
|
|
18
|
+
"url": "git+https://github.com/knitmd/knit.git",
|
|
19
|
+
"directory": "packages/mcp"
|
|
20
|
+
},
|
|
21
|
+
"homepage": "https://github.com/knitmd/knit#readme",
|
|
22
|
+
"bugs": {
|
|
23
|
+
"url": "https://github.com/knitmd/knit/issues"
|
|
24
|
+
},
|
|
25
|
+
"files": [
|
|
26
|
+
"dist"
|
|
27
|
+
]
|
|
28
|
+
}
|