@webmcp-bridge/local-mcp 0.1.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/LICENSE +21 -0
- package/dist/bridge.d.ts +31 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +120 -0
- package/dist/bridge.js.map +1 -0
- package/dist/cli.d.ts +20 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +184 -0
- package/dist/cli.js.map +1 -0
- package/dist/client.d.ts +39 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +232 -0
- package/dist/client.js.map +1 -0
- package/dist/event-buffer.d.ts +22 -0
- package/dist/event-buffer.d.ts.map +1 -0
- package/dist/event-buffer.js +46 -0
- package/dist/event-buffer.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-types.d.ts +61 -0
- package/dist/mcp-types.d.ts.map +1 -0
- package/dist/mcp-types.js +6 -0
- package/dist/mcp-types.js.map +1 -0
- package/dist/protocol.d.ts +11 -0
- package/dist/protocol.d.ts.map +1 -0
- package/dist/protocol.js +52 -0
- package/dist/protocol.js.map +1 -0
- package/dist/runtime.d.ts +30 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +154 -0
- package/dist/runtime.js.map +1 -0
- package/dist/server.d.ts +24 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +189 -0
- package/dist/server.js.map +1 -0
- package/dist/sites.d.ts +22 -0
- package/dist/sites.d.ts.map +1 -0
- package/dist/sites.js +188 -0
- package/dist/sites.js.map +1 -0
- package/package.json +37 -0
package/dist/client.js
ADDED
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module implements a Unix-socket MCP JSON-RPC and SSE client for local MCP servers.
|
|
3
|
+
* It is depended on by connectors and examples so they can call tools and consume event streams uniformly.
|
|
4
|
+
*/
|
|
5
|
+
import { randomUUID } from "node:crypto";
|
|
6
|
+
import { request as httpRequest } from "node:http";
|
|
7
|
+
export class LocalMcpHttpError extends Error {
|
|
8
|
+
status;
|
|
9
|
+
code;
|
|
10
|
+
retryable;
|
|
11
|
+
details;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
super(options.message);
|
|
14
|
+
this.name = "LocalMcpHttpError";
|
|
15
|
+
this.status = options.status;
|
|
16
|
+
this.code = options.code ?? "INTERNAL";
|
|
17
|
+
this.retryable = options.retryable ?? false;
|
|
18
|
+
this.details = options.details;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
export class LocalMcpClient {
|
|
22
|
+
socketPath;
|
|
23
|
+
constructor(options) {
|
|
24
|
+
this.socketPath = options.socketPath;
|
|
25
|
+
}
|
|
26
|
+
async listTools() {
|
|
27
|
+
const response = await this.requestJsonRpc({
|
|
28
|
+
jsonrpc: "2.0",
|
|
29
|
+
id: randomUUID(),
|
|
30
|
+
method: "tools/list",
|
|
31
|
+
});
|
|
32
|
+
if ("error" in response) {
|
|
33
|
+
throw this.toError(response);
|
|
34
|
+
}
|
|
35
|
+
const tools = response.result?.tools;
|
|
36
|
+
if (!Array.isArray(tools)) {
|
|
37
|
+
throw new LocalMcpHttpError({
|
|
38
|
+
status: 500,
|
|
39
|
+
message: "invalid tools/list response",
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
return tools;
|
|
43
|
+
}
|
|
44
|
+
async callTool(name, args) {
|
|
45
|
+
const response = await this.requestJsonRpc({
|
|
46
|
+
jsonrpc: "2.0",
|
|
47
|
+
id: randomUUID(),
|
|
48
|
+
method: "tools/call",
|
|
49
|
+
params: {
|
|
50
|
+
name,
|
|
51
|
+
arguments: args,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
if ("error" in response) {
|
|
55
|
+
throw this.toError(response);
|
|
56
|
+
}
|
|
57
|
+
const content = response.result?.content;
|
|
58
|
+
if (!Array.isArray(content) || content.length === 0) {
|
|
59
|
+
throw new LocalMcpHttpError({
|
|
60
|
+
status: 500,
|
|
61
|
+
message: "invalid tools/call response",
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
const first = content[0];
|
|
65
|
+
return first.json;
|
|
66
|
+
}
|
|
67
|
+
async requestJsonRpc(request) {
|
|
68
|
+
return await new Promise((resolve, reject) => {
|
|
69
|
+
const req = httpRequest({
|
|
70
|
+
socketPath: this.socketPath,
|
|
71
|
+
method: "POST",
|
|
72
|
+
path: "/mcp",
|
|
73
|
+
headers: {
|
|
74
|
+
"content-type": "application/json; charset=utf-8",
|
|
75
|
+
},
|
|
76
|
+
}, (res) => {
|
|
77
|
+
const chunks = [];
|
|
78
|
+
res.on("data", (chunk) => {
|
|
79
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
80
|
+
});
|
|
81
|
+
res.on("end", () => {
|
|
82
|
+
const raw = Buffer.concat(chunks).toString("utf8").trim();
|
|
83
|
+
if (!raw) {
|
|
84
|
+
reject(new LocalMcpHttpError({
|
|
85
|
+
status: res.statusCode ?? 500,
|
|
86
|
+
message: "empty mcp response",
|
|
87
|
+
}));
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
try {
|
|
91
|
+
resolve(JSON.parse(raw));
|
|
92
|
+
}
|
|
93
|
+
catch {
|
|
94
|
+
reject(new LocalMcpHttpError({
|
|
95
|
+
status: res.statusCode ?? 500,
|
|
96
|
+
message: "invalid mcp json response",
|
|
97
|
+
}));
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
req.setTimeout(30000, () => {
|
|
102
|
+
req.destroy(new Error("mcp request timeout"));
|
|
103
|
+
});
|
|
104
|
+
req.on("error", reject);
|
|
105
|
+
req.write(JSON.stringify(request));
|
|
106
|
+
req.end();
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
async consumeEventStream(options) {
|
|
110
|
+
await new Promise((resolve, reject) => {
|
|
111
|
+
const req = httpRequest({
|
|
112
|
+
socketPath: this.socketPath,
|
|
113
|
+
method: "GET",
|
|
114
|
+
path: "/mcp/events",
|
|
115
|
+
headers: options.lastEventId
|
|
116
|
+
? {
|
|
117
|
+
accept: "text/event-stream",
|
|
118
|
+
"last-event-id": options.lastEventId,
|
|
119
|
+
}
|
|
120
|
+
: {
|
|
121
|
+
accept: "text/event-stream",
|
|
122
|
+
},
|
|
123
|
+
}, (res) => {
|
|
124
|
+
if ((res.statusCode ?? 0) >= 400) {
|
|
125
|
+
const chunks = [];
|
|
126
|
+
res.on("data", (chunk) => {
|
|
127
|
+
chunks.push(Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk));
|
|
128
|
+
});
|
|
129
|
+
res.on("end", () => {
|
|
130
|
+
reject(new LocalMcpHttpError({
|
|
131
|
+
status: res.statusCode ?? 500,
|
|
132
|
+
message: Buffer.concat(chunks).toString("utf8") || "stream open failed",
|
|
133
|
+
}));
|
|
134
|
+
});
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
let pending = "";
|
|
138
|
+
let watchdog;
|
|
139
|
+
const resetWatchdog = () => {
|
|
140
|
+
if (watchdog) {
|
|
141
|
+
clearTimeout(watchdog);
|
|
142
|
+
}
|
|
143
|
+
watchdog = setTimeout(() => {
|
|
144
|
+
req.destroy(new Error("stream heartbeat timeout"));
|
|
145
|
+
}, options.heartbeatTimeoutMs);
|
|
146
|
+
};
|
|
147
|
+
resetWatchdog();
|
|
148
|
+
const parseAndEmit = async (block) => {
|
|
149
|
+
const lines = block
|
|
150
|
+
.split("\n")
|
|
151
|
+
.map((line) => line.replace(/\r$/, ""))
|
|
152
|
+
.filter((line) => line.length > 0);
|
|
153
|
+
if (lines.length === 0) {
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
let id;
|
|
157
|
+
let event = "message";
|
|
158
|
+
const dataLines = [];
|
|
159
|
+
for (const line of lines) {
|
|
160
|
+
if (line.startsWith("id:")) {
|
|
161
|
+
id = line.slice(3).trim();
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
if (line.startsWith("event:")) {
|
|
165
|
+
event = line.slice(6).trim();
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (line.startsWith("data:")) {
|
|
169
|
+
dataLines.push(line.slice(5).trim());
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
const sseEvent = {
|
|
173
|
+
event,
|
|
174
|
+
data: dataLines.join("\n"),
|
|
175
|
+
};
|
|
176
|
+
if (id !== undefined) {
|
|
177
|
+
sseEvent.id = id;
|
|
178
|
+
}
|
|
179
|
+
await options.onEvent(sseEvent);
|
|
180
|
+
};
|
|
181
|
+
res.on("data", (chunk) => {
|
|
182
|
+
resetWatchdog();
|
|
183
|
+
pending += Buffer.isBuffer(chunk) ? chunk.toString("utf8") : String(chunk);
|
|
184
|
+
const blocks = pending.split("\n\n");
|
|
185
|
+
pending = blocks.pop() ?? "";
|
|
186
|
+
void (async () => {
|
|
187
|
+
for (const block of blocks) {
|
|
188
|
+
await parseAndEmit(block);
|
|
189
|
+
}
|
|
190
|
+
})().catch((error) => {
|
|
191
|
+
req.destroy(error instanceof Error ? error : new Error(String(error)));
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
res.on("end", () => {
|
|
195
|
+
if (watchdog) {
|
|
196
|
+
clearTimeout(watchdog);
|
|
197
|
+
}
|
|
198
|
+
resolve();
|
|
199
|
+
});
|
|
200
|
+
});
|
|
201
|
+
const abortHandler = () => {
|
|
202
|
+
req.destroy(new Error("stream aborted"));
|
|
203
|
+
};
|
|
204
|
+
options.signal?.addEventListener("abort", abortHandler);
|
|
205
|
+
req.on("error", reject);
|
|
206
|
+
req.on("close", () => {
|
|
207
|
+
options.signal?.removeEventListener("abort", abortHandler);
|
|
208
|
+
});
|
|
209
|
+
req.end();
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
parseSseMessagePayload(raw) {
|
|
213
|
+
return JSON.parse(raw);
|
|
214
|
+
}
|
|
215
|
+
parseSseErrorPayload(raw) {
|
|
216
|
+
return JSON.parse(raw);
|
|
217
|
+
}
|
|
218
|
+
toError(response) {
|
|
219
|
+
const data = response.error.data ?? {};
|
|
220
|
+
const errorOptions = {
|
|
221
|
+
status: 500,
|
|
222
|
+
message: response.error.message,
|
|
223
|
+
code: typeof data.code === "string" ? data.code : "INTERNAL",
|
|
224
|
+
retryable: Boolean(data.retryable),
|
|
225
|
+
};
|
|
226
|
+
if (typeof data.details === "object" && data.details) {
|
|
227
|
+
errorOptions.details = data.details;
|
|
228
|
+
}
|
|
229
|
+
return new LocalMcpHttpError(errorOptions);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,WAAW,CAAC;AAYnD,MAAM,OAAO,iBAAkB,SAAQ,KAAK;IACjC,MAAM,CAAS;IACf,IAAI,CAAS;IACb,SAAS,CAAU;IACnB,OAAO,CAAsC;IAEtD,YAAY,OAMX;QACC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QACvB,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAC;QAChC,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,UAAU,CAAC;QACvC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,KAAK,CAAC;QAC5C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;IACjC,CAAC;CACF;AAMD,MAAM,OAAO,cAAc;IACR,UAAU,CAAS;IAEpC,YAAY,OAA8B;QACxC,I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,CAAC;IACL,CAAC;IAED,sBAAsB,CAAC,GAAW;QAChC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAyB,CAAC;IACjD,CAAC;IAED,oBAAoB,CAAC,GAAW;QAC9B,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAuB,CAAC;IAC/C,CAAC;IAEO,OAAO,CAAC,QAAyB;QACvC,MAAM,IAAI,GAAG,QAAQ,CAAC,KAAK,CAAC,IAAI,IAAI,EAAE,CAAC;QACvC,MAAM,YAAY,GAMd;YACF,MAAM,EAAE,GAAG;YACX,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,OAAO;YAC/B,IAAI,EAAE,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU;YAC5D,SAAS,EAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC;SACnC,CAAC;QACF,IAAI,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACrD,YAAY,CAAC,OAAO,GAAG,IAAI,CAAC,OAAkC,CAAC;QACjE,CAAC;QACD,OAAO,IAAI,iBAAiB,CAAC,YAAY,CAAC,CAAC;IAC7C,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides a bounded in-memory ring buffer for replayable local MCP events.
|
|
3
|
+
* It is depended on by the local MCP server SSE path to provide at-least-once delivery and overflow detection.
|
|
4
|
+
*/
|
|
5
|
+
import type { JsonValue } from "@webmcp-bridge/core";
|
|
6
|
+
export type BufferedEvent = {
|
|
7
|
+
seq: number;
|
|
8
|
+
event: JsonValue;
|
|
9
|
+
};
|
|
10
|
+
export type BufferedReplayResult = {
|
|
11
|
+
overflow: boolean;
|
|
12
|
+
events: BufferedEvent[];
|
|
13
|
+
};
|
|
14
|
+
export declare class EventBuffer {
|
|
15
|
+
private readonly capacity;
|
|
16
|
+
private readonly events;
|
|
17
|
+
private nextSeq;
|
|
18
|
+
constructor(capacity?: number);
|
|
19
|
+
append(event: JsonValue): BufferedEvent;
|
|
20
|
+
replayAfter(lastSeq: number): BufferedReplayResult;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=event-buffer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-buffer.d.ts","sourceRoot":"","sources":["../src/event-buffer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,MAAM,aAAa,GAAG;IAC1B,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,SAAS,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE,aAAa,EAAE,CAAC;CACzB,CAAC;AAEF,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAuB;IAC9C,OAAO,CAAC,OAAO,CAAK;gBAER,QAAQ,SAAO;IAI3B,MAAM,CAAC,KAAK,EAAE,SAAS,GAAG,aAAa;IAavC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,oBAAoB;CAuBnD"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides a bounded in-memory ring buffer for replayable local MCP events.
|
|
3
|
+
* It is depended on by the local MCP server SSE path to provide at-least-once delivery and overflow detection.
|
|
4
|
+
*/
|
|
5
|
+
export class EventBuffer {
|
|
6
|
+
capacity;
|
|
7
|
+
events = [];
|
|
8
|
+
nextSeq = 1;
|
|
9
|
+
constructor(capacity = 5000) {
|
|
10
|
+
this.capacity = Math.max(1, capacity);
|
|
11
|
+
}
|
|
12
|
+
append(event) {
|
|
13
|
+
const buffered = {
|
|
14
|
+
seq: this.nextSeq,
|
|
15
|
+
event,
|
|
16
|
+
};
|
|
17
|
+
this.nextSeq += 1;
|
|
18
|
+
this.events.push(buffered);
|
|
19
|
+
if (this.events.length > this.capacity) {
|
|
20
|
+
this.events.shift();
|
|
21
|
+
}
|
|
22
|
+
return buffered;
|
|
23
|
+
}
|
|
24
|
+
replayAfter(lastSeq) {
|
|
25
|
+
if (this.events.length === 0) {
|
|
26
|
+
return {
|
|
27
|
+
overflow: false,
|
|
28
|
+
events: [],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
if (lastSeq > 0) {
|
|
32
|
+
const oldest = this.events[0]?.seq ?? 0;
|
|
33
|
+
if (lastSeq < oldest - 1) {
|
|
34
|
+
return {
|
|
35
|
+
overflow: true,
|
|
36
|
+
events: [],
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
overflow: false,
|
|
42
|
+
events: this.events.filter((item) => item.seq > lastSeq),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=event-buffer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"event-buffer.js","sourceRoot":"","sources":["../src/event-buffer.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAcH,MAAM,OAAO,WAAW;IACL,QAAQ,CAAS;IACjB,MAAM,GAAoB,EAAE,CAAC;IACtC,OAAO,GAAG,CAAC,CAAC;IAEpB,YAAY,QAAQ,GAAG,IAAI;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAC;IACxC,CAAC;IAED,MAAM,CAAC,KAAgB;QACrB,MAAM,QAAQ,GAAkB;YAC9B,GAAG,EAAE,IAAI,CAAC,OAAO;YACjB,KAAK;SACN,CAAC;QACF,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC;QAClB,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QAC3B,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC,QAAQ,EAAE,CAAC;YACvC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACtB,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,WAAW,CAAC,OAAe;QACzB,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YAC7B,OAAO;gBACL,QAAQ,EAAE,KAAK;gBACf,MAAM,EAAE,EAAE;aACX,CAAC;QACJ,CAAC;QAED,IAAI,OAAO,GAAG,CAAC,EAAE,CAAC;YAChB,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC;YACxC,IAAI,OAAO,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC;gBACzB,OAAO;oBACL,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,EAAE;iBACX,CAAC;YACJ,CAAC;QACH,CAAC;QAED,OAAO;YACL,QAAQ,EAAE,KAAK;YACf,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC;SACzD,CAAC;IACJ,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module exposes local-mcp stdio bridge, runtime, and protocol public APIs.
|
|
3
|
+
* It depends on server/runtime/bridge/cli modules for one-site MCP proxy integration.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./mcp-types.js";
|
|
6
|
+
export * from "./server.js";
|
|
7
|
+
export * from "./sites.js";
|
|
8
|
+
export * from "./runtime.js";
|
|
9
|
+
export * from "./bridge.js";
|
|
10
|
+
export * from "./cli.js";
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module exposes local-mcp stdio bridge, runtime, and protocol public APIs.
|
|
3
|
+
* It depends on server/runtime/bridge/cli modules for one-site MCP proxy integration.
|
|
4
|
+
*/
|
|
5
|
+
export * from "./mcp-types.js";
|
|
6
|
+
export * from "./server.js";
|
|
7
|
+
export * from "./sites.js";
|
|
8
|
+
export * from "./runtime.js";
|
|
9
|
+
export * from "./bridge.js";
|
|
10
|
+
export * from "./cli.js";
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC;AAC5B,cAAc,YAAY,CAAC;AAC3B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module defines MCP JSON-RPC types for stdio transport and WebMCP proxy methods.
|
|
3
|
+
* It is depended on by local server tests and shared exports so JSON-RPC and tool payload typings remain consistent.
|
|
4
|
+
*/
|
|
5
|
+
import type { JsonValue } from "@webmcp-bridge/core";
|
|
6
|
+
export type McpJsonRpcId = string | number | null;
|
|
7
|
+
export type McpToolDefinition = {
|
|
8
|
+
name: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
inputSchema?: JsonValue;
|
|
11
|
+
annotations?: {
|
|
12
|
+
readOnlyHint?: boolean;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
export type McpJsonRpcRequest = {
|
|
16
|
+
jsonrpc: "2.0";
|
|
17
|
+
id?: McpJsonRpcId;
|
|
18
|
+
method: string;
|
|
19
|
+
params?: Record<string, unknown>;
|
|
20
|
+
};
|
|
21
|
+
export type McpJsonRpcSuccess = {
|
|
22
|
+
jsonrpc: "2.0";
|
|
23
|
+
id: McpJsonRpcId;
|
|
24
|
+
result: Record<string, unknown>;
|
|
25
|
+
};
|
|
26
|
+
export type McpJsonRpcError = {
|
|
27
|
+
jsonrpc: "2.0";
|
|
28
|
+
id: McpJsonRpcId;
|
|
29
|
+
error: {
|
|
30
|
+
code: number;
|
|
31
|
+
message: string;
|
|
32
|
+
data?: Record<string, unknown>;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export type McpJsonRpcResponse = McpJsonRpcSuccess | McpJsonRpcError;
|
|
36
|
+
export type McpToolCallParams = {
|
|
37
|
+
name: string;
|
|
38
|
+
arguments?: Record<string, unknown>;
|
|
39
|
+
};
|
|
40
|
+
export type McpInitializeResult = {
|
|
41
|
+
protocolVersion: string;
|
|
42
|
+
capabilities: {
|
|
43
|
+
tools: Record<string, never>;
|
|
44
|
+
};
|
|
45
|
+
serverInfo: {
|
|
46
|
+
name: string;
|
|
47
|
+
version: string;
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export type McpToolListResult = {
|
|
51
|
+
tools: McpToolDefinition[];
|
|
52
|
+
};
|
|
53
|
+
export type McpToolCallResult = {
|
|
54
|
+
content?: Array<{
|
|
55
|
+
type: "text";
|
|
56
|
+
text: string;
|
|
57
|
+
}>;
|
|
58
|
+
structuredContent?: Record<string, unknown>;
|
|
59
|
+
isError?: boolean;
|
|
60
|
+
};
|
|
61
|
+
//# sourceMappingURL=mcp-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-types.d.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,MAAM,MAAM,mBAAmB,GAAG;IAChC,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE;QACZ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;KAC9B,CAAC;IACF,UAAU,EAAE;QACV,IAAI,EAAE,MAAM,CAAC;QACb,OAAO,EAAE,MAAM,CAAC;KACjB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,KAAK,EAAE,iBAAiB,EAAE,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,OAAO,CAAC,EAAE,KAAK,CAAC;QACd,IAAI,EAAE,MAAM,CAAC;QACb,IAAI,EAAE,MAAM,CAAC;KACd,CAAC,CAAC;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC5C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-types.js","sourceRoot":"","sources":["../src/mcp-types.ts"],"names":[],"mappings":"AAAA;;;GAGG"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides stdio JSON-RPC framing for MCP messages.
|
|
3
|
+
* It is depended on by the stdio server implementation to decode incoming requests and encode responses.
|
|
4
|
+
*/
|
|
5
|
+
export declare class McpStdioMessageReader {
|
|
6
|
+
private buffer;
|
|
7
|
+
private expectedBodyLength;
|
|
8
|
+
push<T = unknown>(chunk: Buffer): T[];
|
|
9
|
+
}
|
|
10
|
+
export declare function encodeMcpStdioMessage(message: unknown): Buffer;
|
|
11
|
+
//# sourceMappingURL=protocol.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.d.ts","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,qBAAa,qBAAqB;IAChC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,kBAAkB,CAAqB;IAE/C,IAAI,CAAC,CAAC,GAAG,OAAO,EAAE,KAAK,EAAE,MAAM,GAAG,CAAC,EAAE;CA8CtC;AAED,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM,CAI9D"}
|
package/dist/protocol.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module provides stdio JSON-RPC framing for MCP messages.
|
|
3
|
+
* It is depended on by the stdio server implementation to decode incoming requests and encode responses.
|
|
4
|
+
*/
|
|
5
|
+
const HEADER_DELIMITER = Buffer.from("\r\n\r\n", "utf8");
|
|
6
|
+
export class McpStdioMessageReader {
|
|
7
|
+
buffer = Buffer.alloc(0);
|
|
8
|
+
expectedBodyLength;
|
|
9
|
+
push(chunk) {
|
|
10
|
+
if (chunk.length === 0) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
this.buffer = Buffer.concat([this.buffer, chunk]);
|
|
14
|
+
const messages = [];
|
|
15
|
+
while (true) {
|
|
16
|
+
if (this.expectedBodyLength === undefined) {
|
|
17
|
+
const headerEnd = this.buffer.indexOf(HEADER_DELIMITER);
|
|
18
|
+
if (headerEnd < 0) {
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
const rawHeaders = this.buffer.slice(0, headerEnd).toString("utf8");
|
|
22
|
+
this.buffer = this.buffer.slice(headerEnd + HEADER_DELIMITER.length);
|
|
23
|
+
const headers = rawHeaders.split("\r\n");
|
|
24
|
+
const lengthLine = headers.find((line) => line.toLowerCase().startsWith("content-length:"));
|
|
25
|
+
if (!lengthLine) {
|
|
26
|
+
throw new Error("missing Content-Length header");
|
|
27
|
+
}
|
|
28
|
+
const length = Number.parseInt(lengthLine.slice("content-length:".length).trim(), 10);
|
|
29
|
+
if (!Number.isFinite(length) || length < 0) {
|
|
30
|
+
throw new Error("invalid Content-Length header");
|
|
31
|
+
}
|
|
32
|
+
this.expectedBodyLength = length;
|
|
33
|
+
}
|
|
34
|
+
const expectedLength = this.expectedBodyLength;
|
|
35
|
+
if (expectedLength === undefined || this.buffer.length < expectedLength) {
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
const rawBody = this.buffer.slice(0, expectedLength);
|
|
39
|
+
this.buffer = this.buffer.slice(expectedLength);
|
|
40
|
+
this.expectedBodyLength = undefined;
|
|
41
|
+
const parsed = JSON.parse(rawBody.toString("utf8"));
|
|
42
|
+
messages.push(parsed);
|
|
43
|
+
}
|
|
44
|
+
return messages;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function encodeMcpStdioMessage(message) {
|
|
48
|
+
const body = Buffer.from(JSON.stringify(message), "utf8");
|
|
49
|
+
const header = Buffer.from(`Content-Length: ${body.length}\r\n\r\n`, "utf8");
|
|
50
|
+
return Buffer.concat([header, body]);
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=protocol.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protocol.js","sourceRoot":"","sources":["../src/protocol.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,MAAM,gBAAgB,GAAG,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;AAEzD,MAAM,OAAO,qBAAqB;IACxB,MAAM,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACzB,kBAAkB,CAAqB;IAE/C,IAAI,CAAc,KAAa;QAC7B,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;YACvB,OAAO,EAAE,CAAC;QACZ,CAAC;QAED,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC,CAAC;QAClD,MAAM,QAAQ,GAAQ,EAAE,CAAC;QAEzB,OAAO,IAAI,EAAE,CAAC;YACZ,IAAI,IAAI,CAAC,kBAAkB,KAAK,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;YACR,CAAC;YAED,MAAM,OAAO,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,cAAc,CAAC,CAAC;YACrD,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;YAChD,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAC;YAEpC,MAAM,MAAM,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAM,CAAC;YACzD,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACxB,CAAC;QAED,OAAO,QAAQ,CAAC;IAClB,CAAC;CACF;AAED,MAAM,UAAU,qBAAqB,CAAC,OAAgB;IACpD,MAAM,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;IAC1D,MAAM,MAAM,GAAG,MAAM,CAAC,IAAI,CAAC,mBAAmB,IAAI,CAAC,MAAM,UAAU,EAAE,MAAM,CAAC,CAAC;IAC7E,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This module boots a Playwright page and WebMCP gateway for one target site session.
|
|
3
|
+
* It depends on resolved site definitions and Playwright gateway APIs so local-mcp can proxy browser-side tool execution.
|
|
4
|
+
*/
|
|
5
|
+
import { type Page } from "playwright";
|
|
6
|
+
import type { LocalMcpGateway } from "./server.js";
|
|
7
|
+
import type { SiteDefinition } from "./sites.js";
|
|
8
|
+
export type BrowserEngine = "chromium" | "firefox" | "webkit";
|
|
9
|
+
export type LocalMcpRuntimeOptions = {
|
|
10
|
+
siteDefinition: SiteDefinition;
|
|
11
|
+
url?: string;
|
|
12
|
+
browser?: BrowserEngine;
|
|
13
|
+
headless?: boolean;
|
|
14
|
+
userDataDir?: string;
|
|
15
|
+
preferNative?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export type LocalMcpRuntime = {
|
|
18
|
+
site: string;
|
|
19
|
+
siteDefinition: SiteDefinition;
|
|
20
|
+
targetUrl: string;
|
|
21
|
+
mode: "native" | "polyfill" | "adapter-shim";
|
|
22
|
+
headless: boolean;
|
|
23
|
+
page: Page;
|
|
24
|
+
gateway: LocalMcpGateway;
|
|
25
|
+
close: () => Promise<void>;
|
|
26
|
+
};
|
|
27
|
+
export declare function isUrlAllowed(url: string, hostPatterns: string[]): boolean;
|
|
28
|
+
export declare function resolveTargetUrl(urlOverride: string | undefined, defaultUrl: string | undefined): string;
|
|
29
|
+
export declare function startLocalMcpRuntime(options: LocalMcpRuntimeOptions): Promise<LocalMcpRuntime>;
|
|
30
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime.d.ts","sourceRoot":"","sources":["../src/runtime.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,OAAO,EAML,KAAK,IAAI,EACV,MAAM,YAAY,CAAC;AACpB,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAEjD,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE9D,MAAM,MAAM,sBAAsB,GAAG;IACnC,cAAc,EAAE,cAAc,CAAC;IAC/B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,aAAa,CAAC;IACxB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,cAAc,EAAE,cAAc,CAAC;IAC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