@nwire/mcp 0.7.0 → 0.8.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/README.md +49 -31
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +85 -33
- package/dist/index.js.map +1 -1
- package/dist/inspect.d.ts +40 -0
- package/dist/inspect.d.ts.map +1 -0
- package/dist/inspect.js +278 -0
- package/dist/inspect.js.map +1 -0
- package/dist/write-tools.d.ts +27 -0
- package/dist/write-tools.d.ts.map +1 -0
- package/dist/write-tools.js +212 -0
- package/dist/write-tools.js.map +1 -0
- package/package.json +5 -3
- package/src/__tests__/inspect-tools.test.ts +332 -0
- package/src/__tests__/mcp-io.test.ts +180 -0
- package/src/__tests__/write-tools.test.ts +350 -0
- package/src/index.ts +106 -38
- package/src/inspect.ts +315 -0
- package/src/write-tools.ts +238 -0
package/README.md
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
# @nwire/mcp
|
|
2
2
|
|
|
3
|
-
> Model Context Protocol server — exposes the kernel's CommandRouter as MCP tools over stdio.
|
|
3
|
+
> Model Context Protocol server — exposes the kernel's CommandRouter + read-only inspect tools + mutating write tools as MCP tools over stdio.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Wraps the Nwire kernel as a Model Context Protocol server. AI clients
|
|
6
|
+
(Claude Desktop, Cursor, IDE plugins) speak JSON-RPC 2.0 over stdio per
|
|
7
|
+
the MCP spec; this server routes `tools/list` and `tools/call` to:
|
|
6
8
|
|
|
7
|
-
|
|
9
|
+
1. **Kernel CommandRouter** — same commands the CLI and Studio drive.
|
|
10
|
+
2. **Inspect tools** — read-only introspection over `/__nwire/*` (falls back to `.nwire/` cache).
|
|
11
|
+
3. **Write tools** — mutating actions that POST to `/__nwire/*` on a live wire.
|
|
8
12
|
|
|
9
|
-
|
|
13
|
+
One transport, three surfaces (CLI, Studio, MCP).
|
|
10
14
|
|
|
11
15
|
```bash
|
|
12
16
|
pnpm add @nwire/mcp
|
|
13
17
|
```
|
|
14
18
|
|
|
15
|
-
## Quick
|
|
19
|
+
## Quick example
|
|
16
20
|
|
|
17
21
|
```ts
|
|
18
22
|
import { serveMcp } from "@nwire/mcp";
|
|
@@ -20,7 +24,7 @@ import { createKernel } from "@nwire/kernel";
|
|
|
20
24
|
|
|
21
25
|
const kernel = createKernel();
|
|
22
26
|
kernel.router.register("dev", devHandler);
|
|
23
|
-
kernel.router.register("ls",
|
|
27
|
+
kernel.router.register("ls", listHandler);
|
|
24
28
|
|
|
25
29
|
await serveMcp({ kernel, serverName: "my-app" });
|
|
26
30
|
// Process now speaks MCP over stdin/stdout; stderr is for logs.
|
|
@@ -32,40 +36,54 @@ Then point Claude Desktop at the binary in `claude_desktop_config.json`:
|
|
|
32
36
|
{ "mcpServers": { "my-app": { "command": "node", "args": ["./mcp.js"] } } }
|
|
33
37
|
```
|
|
34
38
|
|
|
35
|
-
##
|
|
39
|
+
## Surface
|
|
36
40
|
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
| Export | Role |
|
|
42
|
+
| ------------------------------------------------------- | ------------------------------------------------------------- |
|
|
43
|
+
| `serveMcp({ kernel?, serverName?, serverVersion?, stdin?, stdout? })` | Boot the server on stdio; resolves when stdin closes. |
|
|
44
|
+
| `JsonRpcRequest` / `JsonRpcResponse` / `JsonRpcNotification` | JSON-RPC types for callers writing alternative transports (WebSocket, etc.). |
|
|
39
45
|
|
|
40
|
-
|
|
46
|
+
### Built-in tools
|
|
41
47
|
|
|
42
|
-
|
|
48
|
+
Beyond the kernel's CommandRouter, the server exposes these tools:
|
|
43
49
|
|
|
44
|
-
|
|
50
|
+
**Inspect (read-only)** — proxy `/__nwire/*` on a running wire, fall back to `.nwire/*.json` on disk:
|
|
45
51
|
|
|
46
|
-
|
|
52
|
+
| Tool | Reads |
|
|
53
|
+
| ------------------- | ---------------------------------------------------- |
|
|
54
|
+
| `manifest` | `.nwire/manifest.json` |
|
|
55
|
+
| `list_actions` | `.nwire/actions.json` |
|
|
56
|
+
| `list_events` | `.nwire/events.json` |
|
|
57
|
+
| `list_hooks` | `.nwire/hooks.json` |
|
|
58
|
+
| `list_plugins` | `.nwire/plugins.json` |
|
|
59
|
+
| `recent_events` | Live `/__nwire/events/recent` |
|
|
60
|
+
| `recent_telemetry` | Live `/__nwire/telemetry/recent` |
|
|
47
61
|
|
|
48
|
-
|
|
49
|
-
// See the package's main entry (src/) for the standalone surface.
|
|
50
|
-
// The exports below work without @nwire/app or @nwire/forge.
|
|
51
|
-
import {} from /* ...standalone exports... */ "@nwire/mcp";
|
|
52
|
-
```
|
|
62
|
+
**Write (mutating)** — POST to a live wire:
|
|
53
63
|
|
|
54
|
-
|
|
64
|
+
| Tool | Posts to |
|
|
65
|
+
| ---------------- | --------------------------------------------------------- |
|
|
66
|
+
| `dispatch_action`| `/__nwire/dispatch` — fire any registered action. |
|
|
67
|
+
| `run_command` | `/__nwire/commands/run` — invoke a `defineCommand`. |
|
|
68
|
+
| `replay_trace` | `/__nwire/replay` — replay a recording against the wire. |
|
|
55
69
|
|
|
56
|
-
|
|
70
|
+
Write tools gracefully gap-flag when the target endpoint isn't mounted
|
|
71
|
+
(e.g., MCP running standalone with no wire up).
|
|
57
72
|
|
|
58
|
-
|
|
59
|
-
import { createApp } from "@nwire/forge";
|
|
73
|
+
### Progress notifications
|
|
60
74
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
For kernel router commands, the server forwards `command.log` and
|
|
76
|
+
`command.progress` events as MCP `notifications/progress` so the AI
|
|
77
|
+
client streams output as the command runs. Inspect + write tools are
|
|
78
|
+
synchronous and don't notify.
|
|
79
|
+
|
|
80
|
+
## Related
|
|
81
|
+
|
|
82
|
+
- `@nwire/kernel` — supplies the `CommandRouter` + `CommandHandle` lifecycle.
|
|
83
|
+
- `@nwire/cli` — same kernel router exposed as a terminal CLI.
|
|
84
|
+
- `@nwire/studio` — same `/__nwire/*` middleware that write/inspect tools target.
|
|
85
|
+
- `@nwire/scan` — produces the `.nwire/*.json` files inspect tools fall back to.
|
|
66
86
|
|
|
67
|
-
##
|
|
87
|
+
## Status
|
|
68
88
|
|
|
69
|
-
|
|
70
|
-
- [Model Context Protocol spec](https://spec.modelcontextprotocol.io/)
|
|
71
|
-
- Sibling packages: [@nwire/kernel](../nwire-kernel), [@nwire/cli](../nwire-cli), [@nwire/studio](../nwire-studio)
|
|
89
|
+
v0.x — `initialize`, `tools/list`, `tools/call` work end-to-end. Resources, prompts, and sampling are sketched but not implemented yet.
|
package/dist/index.d.ts
CHANGED
|
@@ -52,6 +52,18 @@ export interface ServeMcpOptions {
|
|
|
52
52
|
readonly serverName?: string;
|
|
53
53
|
/** Server version reported on `initialize`. Default `"0.1.0"`. */
|
|
54
54
|
readonly serverVersion?: string;
|
|
55
|
+
/**
|
|
56
|
+
* Input stream the server reads newline-delimited JSON-RPC from.
|
|
57
|
+
* Defaults to `process.stdin`. Tests supply a PassThrough; foreign
|
|
58
|
+
* transports (websocket, http) can adapt to this same shape.
|
|
59
|
+
*/
|
|
60
|
+
readonly stdin?: NodeJS.ReadableStream;
|
|
61
|
+
/**
|
|
62
|
+
* Output stream the server writes responses + notifications to.
|
|
63
|
+
* Defaults to `process.stdout`. Stderr is always used for server
|
|
64
|
+
* logs and is never overridden.
|
|
65
|
+
*/
|
|
66
|
+
readonly stdout?: NodeJS.WritableStream;
|
|
55
67
|
}
|
|
56
68
|
/**
|
|
57
69
|
* Start the MCP server on stdio. Blocks the process until stdin closes
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAoC,KAAK,MAAM,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","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Q,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,cAAc,CAAC;CACzC;AAED;;;;;;;;GAQG;AACH,wBAAsB,QAAQ,CAAC,OAAO,GAAE,eAAoB,GAAG,OAAO,CAAC,IAAI,CAAC,CAiC3E;AAoND,YAAY,EAAE,cAAc,EAAE,eAAe,EAAE,mBAAmB,EAAE,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -24,17 +24,12 @@
|
|
|
24
24
|
* (AI client invokes an nwire command) works end-to-end.
|
|
25
25
|
*/
|
|
26
26
|
import { createKernel } from "@nwire/kernel";
|
|
27
|
+
import { inspectTools, findInspectTool } from "./inspect.js";
|
|
28
|
+
import { writeTools, findWriteTool } from "./write-tools.js";
|
|
27
29
|
const ERR_PARSE = -32700;
|
|
28
|
-
const ERR_INVALID_REQ = -32600;
|
|
29
30
|
const ERR_NOT_FOUND = -32601;
|
|
30
31
|
const ERR_INVALID_PARAMS = -32602;
|
|
31
32
|
const ERR_INTERNAL = -32603;
|
|
32
|
-
function send(msg) {
|
|
33
|
-
process.stdout.write(JSON.stringify(msg) + "\n");
|
|
34
|
-
}
|
|
35
|
-
function log(text) {
|
|
36
|
-
process.stderr.write(`[nwire-mcp] ${text}\n`);
|
|
37
|
-
}
|
|
38
33
|
/**
|
|
39
34
|
* Start the MCP server on stdio. Blocks the process until stdin closes
|
|
40
35
|
* (the client disconnected). Returns the kernel for callers who want
|
|
@@ -48,8 +43,16 @@ export async function serveMcp(options = {}) {
|
|
|
48
43
|
const kernel = options.kernel ?? createKernel();
|
|
49
44
|
const serverName = options.serverName ?? "nwire";
|
|
50
45
|
const serverVersion = options.serverVersion ?? "0.1.0";
|
|
46
|
+
const stdin = options.stdin ?? process.stdin;
|
|
47
|
+
const stdout = options.stdout ?? process.stdout;
|
|
48
|
+
const send = (msg) => {
|
|
49
|
+
stdout.write(JSON.stringify(msg) + "\n");
|
|
50
|
+
};
|
|
51
|
+
const log = (text) => {
|
|
52
|
+
process.stderr.write(`[nwire-mcp] ${text}\n`);
|
|
53
|
+
};
|
|
51
54
|
log(`server starting (${kernel.router.list().length} commands registered)`);
|
|
52
|
-
await readLines(async (line) => {
|
|
55
|
+
await readLines(stdin, async (line) => {
|
|
53
56
|
if (!line.trim())
|
|
54
57
|
return;
|
|
55
58
|
let request;
|
|
@@ -64,7 +67,7 @@ export async function serveMcp(options = {}) {
|
|
|
64
67
|
});
|
|
65
68
|
return;
|
|
66
69
|
}
|
|
67
|
-
await handle(request, { kernel, serverName, serverVersion });
|
|
70
|
+
await handle(request, { kernel, serverName, serverVersion, send });
|
|
68
71
|
});
|
|
69
72
|
log("stdin closed — server exiting");
|
|
70
73
|
}
|
|
@@ -73,7 +76,7 @@ async function handle(req, ctx) {
|
|
|
73
76
|
try {
|
|
74
77
|
switch (req.method) {
|
|
75
78
|
case "initialize":
|
|
76
|
-
send({
|
|
79
|
+
ctx.send({
|
|
77
80
|
jsonrpc: "2.0",
|
|
78
81
|
id,
|
|
79
82
|
result: {
|
|
@@ -84,15 +87,32 @@ async function handle(req, ctx) {
|
|
|
84
87
|
});
|
|
85
88
|
return;
|
|
86
89
|
case "tools/list":
|
|
87
|
-
send({
|
|
90
|
+
ctx.send({
|
|
88
91
|
jsonrpc: "2.0",
|
|
89
92
|
id,
|
|
90
93
|
result: {
|
|
91
|
-
tools:
|
|
92
|
-
name
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
tools: [
|
|
95
|
+
...ctx.kernel.router.list().map((name) => ({
|
|
96
|
+
name,
|
|
97
|
+
description: `Nwire command "${name}"`,
|
|
98
|
+
inputSchema: { type: "object", additionalProperties: true },
|
|
99
|
+
})),
|
|
100
|
+
// Read-only introspection tools that proxy /_nwire/* (or
|
|
101
|
+
// fall back to the .nwire/ disk cache).
|
|
102
|
+
...inspectTools.map((t) => ({
|
|
103
|
+
name: t.name,
|
|
104
|
+
description: t.description,
|
|
105
|
+
inputSchema: t.inputSchema,
|
|
106
|
+
})),
|
|
107
|
+
// Mutating tools that drive the wire via POST /_nwire/*.
|
|
108
|
+
// Some target endpoints aren't mounted yet — those tools
|
|
109
|
+
// gracefully gap-flag (see write-tools.ts).
|
|
110
|
+
...writeTools.map((t) => ({
|
|
111
|
+
name: t.name,
|
|
112
|
+
description: t.description,
|
|
113
|
+
inputSchema: t.inputSchema,
|
|
114
|
+
})),
|
|
115
|
+
],
|
|
96
116
|
},
|
|
97
117
|
});
|
|
98
118
|
return;
|
|
@@ -100,7 +120,7 @@ async function handle(req, ctx) {
|
|
|
100
120
|
await callTool(req, id, ctx);
|
|
101
121
|
return;
|
|
102
122
|
default:
|
|
103
|
-
send({
|
|
123
|
+
ctx.send({
|
|
104
124
|
jsonrpc: "2.0",
|
|
105
125
|
id,
|
|
106
126
|
error: { code: ERR_NOT_FOUND, message: `unknown method "${req.method}"` },
|
|
@@ -108,7 +128,7 @@ async function handle(req, ctx) {
|
|
|
108
128
|
}
|
|
109
129
|
}
|
|
110
130
|
catch (err) {
|
|
111
|
-
send({
|
|
131
|
+
ctx.send({
|
|
112
132
|
jsonrpc: "2.0",
|
|
113
133
|
id,
|
|
114
134
|
error: { code: ERR_INTERNAL, message: err.message },
|
|
@@ -119,15 +139,44 @@ async function callTool(req, id, ctx) {
|
|
|
119
139
|
const name = req.params?.name;
|
|
120
140
|
const args = (req.params?.arguments ?? {});
|
|
121
141
|
if (!name) {
|
|
122
|
-
send({
|
|
142
|
+
ctx.send({
|
|
123
143
|
jsonrpc: "2.0",
|
|
124
144
|
id,
|
|
125
145
|
error: { code: ERR_INVALID_PARAMS, message: "tools/call requires `name`" },
|
|
126
146
|
});
|
|
127
147
|
return;
|
|
128
148
|
}
|
|
149
|
+
// Inspect + write tools live alongside the kernel CommandRouter but
|
|
150
|
+
// don't emit progress notifications — they're synchronous HTTP/file
|
|
151
|
+
// reads (inspect) or single POSTs (write). Match these BEFORE the
|
|
152
|
+
// router-has check so they don't collide.
|
|
153
|
+
const httpTool = findInspectTool(name) ?? findWriteTool(name);
|
|
154
|
+
if (httpTool) {
|
|
155
|
+
try {
|
|
156
|
+
const out = await httpTool.run(args);
|
|
157
|
+
ctx.send({
|
|
158
|
+
jsonrpc: "2.0",
|
|
159
|
+
id,
|
|
160
|
+
result: {
|
|
161
|
+
content: [{ type: "text", text: JSON.stringify(out) }],
|
|
162
|
+
isError: false,
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
catch (err) {
|
|
167
|
+
ctx.send({
|
|
168
|
+
jsonrpc: "2.0",
|
|
169
|
+
id,
|
|
170
|
+
result: {
|
|
171
|
+
content: [{ type: "text", text: err.message }],
|
|
172
|
+
isError: true,
|
|
173
|
+
},
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
129
178
|
if (!ctx.kernel.router.has(name)) {
|
|
130
|
-
send({
|
|
179
|
+
ctx.send({
|
|
131
180
|
jsonrpc: "2.0",
|
|
132
181
|
id,
|
|
133
182
|
error: { code: ERR_INVALID_PARAMS, message: `unknown tool "${name}"` },
|
|
@@ -138,7 +187,7 @@ async function callTool(req, id, ctx) {
|
|
|
138
187
|
const handle = ctx.kernel.run(name, args);
|
|
139
188
|
const unsubscribe = handle.on((event) => {
|
|
140
189
|
if (event.kind === "command.log") {
|
|
141
|
-
send({
|
|
190
|
+
ctx.send({
|
|
142
191
|
jsonrpc: "2.0",
|
|
143
192
|
method: "notifications/progress",
|
|
144
193
|
params: {
|
|
@@ -149,7 +198,7 @@ async function callTool(req, id, ctx) {
|
|
|
149
198
|
});
|
|
150
199
|
}
|
|
151
200
|
else if (event.kind === "command.progress") {
|
|
152
|
-
send({
|
|
201
|
+
ctx.send({
|
|
153
202
|
jsonrpc: "2.0",
|
|
154
203
|
method: "notifications/progress",
|
|
155
204
|
params: {
|
|
@@ -162,7 +211,7 @@ async function callTool(req, id, ctx) {
|
|
|
162
211
|
});
|
|
163
212
|
try {
|
|
164
213
|
const result = await handle.promise;
|
|
165
|
-
send({
|
|
214
|
+
ctx.send({
|
|
166
215
|
jsonrpc: "2.0",
|
|
167
216
|
id,
|
|
168
217
|
result: {
|
|
@@ -172,7 +221,7 @@ async function callTool(req, id, ctx) {
|
|
|
172
221
|
});
|
|
173
222
|
}
|
|
174
223
|
catch (err) {
|
|
175
|
-
send({
|
|
224
|
+
ctx.send({
|
|
176
225
|
jsonrpc: "2.0",
|
|
177
226
|
id,
|
|
178
227
|
result: {
|
|
@@ -186,27 +235,30 @@ async function callTool(req, id, ctx) {
|
|
|
186
235
|
}
|
|
187
236
|
}
|
|
188
237
|
/**
|
|
189
|
-
* Read newline-delimited messages from
|
|
190
|
-
*
|
|
238
|
+
* Read newline-delimited messages from a stream. Resolves when the
|
|
239
|
+
* stream ends. Tolerates partial chunks (buffers + splits on \n).
|
|
191
240
|
*/
|
|
192
|
-
function readLines(onLine) {
|
|
241
|
+
function readLines(stream, onLine) {
|
|
193
242
|
return new Promise((resolve) => {
|
|
194
243
|
let buffer = "";
|
|
195
|
-
|
|
196
|
-
buffer += chunk.toString("utf8");
|
|
197
|
-
|
|
244
|
+
stream.on("data", async (chunk) => {
|
|
245
|
+
buffer += typeof chunk === "string" ? chunk : chunk.toString("utf8");
|
|
246
|
+
// CRLF-safe: Windows MCP clients write `\r\n` terminated frames.
|
|
247
|
+
// Splitting on `\n` alone leaves a trailing `\r` on every line which
|
|
248
|
+
// breaks downstream JSON parsing of the next message.
|
|
249
|
+
const lines = buffer.split(/\r?\n/);
|
|
198
250
|
buffer = lines.pop() ?? "";
|
|
199
251
|
for (const line of lines) {
|
|
200
252
|
try {
|
|
201
253
|
await onLine(line);
|
|
202
254
|
}
|
|
203
255
|
catch (err) {
|
|
204
|
-
|
|
256
|
+
process.stderr.write(`[nwire-mcp] onLine threw: ${err.message}\n`);
|
|
205
257
|
}
|
|
206
258
|
}
|
|
207
259
|
});
|
|
208
|
-
|
|
209
|
-
|
|
260
|
+
stream.on("end", () => resolve());
|
|
261
|
+
stream.on("close", () => resolve());
|
|
210
262
|
});
|
|
211
263
|
}
|
|
212
264
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,YAAY,EAAmC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,YAAY,EAAmC,MAAM,eAAe,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAwB7D,MAAM,SAAS,GAAY,CAAC,KAAK,CAAC;AAClC,MAAM,aAAa,GAAQ,CAAC,KAAK,CAAC;AAClC,MAAM,kBAAkB,GAAG,CAAC,KAAK,CAAC;AAClC,MAAM,YAAY,GAAS,CAAC,KAAK,CAAC;AAyBlC;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,QAAQ,CAAC,UAA2B,EAAE;IAC1D,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,YAAY,EAAE,CAAC;IAChD,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,OAAO,CAAC;IACjD,MAAM,aAAa,GAAG,OAAO,CAAC,aAAa,IAAI,OAAO,CAAC;IACvD,MAAM,KAAK,GAAI,OAAO,CAAC,KAAK,IAAK,OAAO,CAAC,KAAK,CAAC;IAC/C,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,OAAO,CAAC,MAAM,CAAC;IAEhD,MAAM,IAAI,GAAG,CAAC,GAA0C,EAAQ,EAAE;QAChE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CA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AAQ,CAAC,MAAM,CAAC,CAAC;YACrE,iEAAiE;YACjE,qEAAqE;YACrE,sDAAsD;YACtD,MAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;YACpC,MAAM,GAAG,KAAK,CAAC,GAAG,EAAE,IAAI,EAAE,CAAC;YAC3B,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;gBACzB,IAAI,CAAC;oBACH,MAAM,MAAM,CAAC,IAAI,CAAC,CAAC;gBACrB,CAAC;gBAAC,OAAO,GAAG,EAAE,CAAC;oBACb,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,6BAA8B,GAAa,CAAC,OAAO,IAAI,CAAC,CAAC;gBAChF,CAAC;YACH,CAAC;QACH,CAAC,CAAC,CAAC;QACH,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;QAClC,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inspect tools — proxy a running wire's `/_nwire/*` introspection
|
|
3
|
+
* endpoints (or fall back to the on-disk `.nwire/` cache) as MCP tools.
|
|
4
|
+
*
|
|
5
|
+
* Today's `@nwire/mcp` only exposed the kernel's CLI commands. The
|
|
6
|
+
* running wire mounts a rich read-only surface (manifest, recent events,
|
|
7
|
+
* recent telemetry, dispatch…) at `/_nwire/*`. We adapt that surface
|
|
8
|
+
* into MCP tools so an AI client can ask "what actions does this app
|
|
9
|
+
* expose?" or "show me the last 100 events" without booting anything.
|
|
10
|
+
*
|
|
11
|
+
* Discovery follows the same pattern Studio uses (see
|
|
12
|
+
* `packages/nwire-studio/vite.config.ts`):
|
|
13
|
+
*
|
|
14
|
+
* 1. If `NWIRE_INSPECT_URL` is set, trust it.
|
|
15
|
+
* 2. Otherwise, probe a small fixed list of ports for a wire that
|
|
16
|
+
* answers `GET /_nwire/events/recent?limit=1` with a JSON array.
|
|
17
|
+
* 3. Cache the result for 5s so a burst of tool calls is cheap.
|
|
18
|
+
*
|
|
19
|
+
* For tools that have a disk equivalent (`manifest`, `hooks`,
|
|
20
|
+
* `plugins`), we fall through to `${cwd}/.nwire/<file>.json` when no
|
|
21
|
+
* live wire answers. That makes the inspect tools usable in a cold
|
|
22
|
+
* project too — just run `nwire cache` once.
|
|
23
|
+
*/
|
|
24
|
+
/** Reset the URL cache. Tests use this to flush between cases. */
|
|
25
|
+
export declare function resetInspectDiscoveryCache(): void;
|
|
26
|
+
/**
|
|
27
|
+
* Discover the base URL of a running wire. Honours `NWIRE_INSPECT_URL`
|
|
28
|
+
* first (and does NOT validate it — callers asked for it explicitly),
|
|
29
|
+
* then probes a fixed list of ports.
|
|
30
|
+
*/
|
|
31
|
+
export declare function discoverInspectUrl(): Promise<string | undefined>;
|
|
32
|
+
export interface InspectToolDef {
|
|
33
|
+
readonly name: string;
|
|
34
|
+
readonly description: string;
|
|
35
|
+
readonly inputSchema: Record<string, unknown>;
|
|
36
|
+
readonly run: (args: Record<string, unknown>) => Promise<unknown>;
|
|
37
|
+
}
|
|
38
|
+
export declare const inspectTools: readonly InspectToolDef[];
|
|
39
|
+
export declare function findInspectTool(name: string): InspectToolDef | undefined;
|
|
40
|
+
//# sourceMappingURL=inspect.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inspect.d.ts","sourceRoot":"","sources":["../src/inspect.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAyBH,kEAAkE;AAClE,wBAAgB,0BAA0B,IAAI,IAAI,CAEjD;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,IAAI,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAetE;AAgFD,MAAM,WAAW,cAAc;IAC7B,QAAQ,CAAC,IAAI,EAAS,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC;IAC7B,QAAQ,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9C,QAAQ,CAAC,GAAG,EAAU,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3E;AA8BD,eAAO,MAAM,YAAY,EAAE,SAAS,cAAc,EA2HjD,CAAC;AAEF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,cAAc,GAAG,SAAS,CAExE"}
|