@jiangxiaoxu/lm-tools-bridge-proxy 0.1.0 → 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.
Files changed (3) hide show
  1. package/README.md +11 -1
  2. package/dist/index.js +25 -4
  3. package/package.json +2 -2
package/README.md CHANGED
@@ -11,9 +11,19 @@ args = ["-y", "@jiangxiaoxu/lm-tools-bridge-proxy"]
11
11
 
12
12
  The proxy uses the current working directory (`cwd`) to resolve the VS Code instance.
13
13
 
14
+ ## Logging
15
+
16
+ Set `LM_TOOLS_BRIDGE_PROXY_LOG` to a file path to enable log output. If unset, the proxy emits no logs.
17
+
18
+ ## Resolve test
19
+
20
+ ```
21
+ node ./scripts/resolve-test.mjs --cwd <workspace-path>
22
+ ```
23
+
14
24
  ## Development
15
25
 
16
26
  ```
17
27
  npm install
18
28
  npm run build
19
- ```
29
+ ```
package/dist/index.js CHANGED
@@ -27,10 +27,11 @@ var import_node_http = __toESM(require("node:http"));
27
27
  var import_node_process = __toESM(require("node:process"));
28
28
  var import_node_crypto = __toESM(require("node:crypto"));
29
29
  var import_node_os = __toESM(require("node:os"));
30
+ var import_node_fs = __toESM(require("node:fs"));
30
31
  var MANAGER_TIMEOUT_MS = 1500;
31
32
  var RESOLVE_RETRIES = 5;
32
33
  var RESOLVE_RETRY_DELAY_MS = 1e3;
33
- var TARGET_HOST_HEADER = "x-mcp-target";
34
+ var LOG_ENV = "LM_TOOLS_BRIDGE_PROXY_LOG";
34
35
  function getUserSeed() {
35
36
  return import_node_process.default.env.USERNAME ?? import_node_process.default.env.USERPROFILE ?? import_node_os.default.userInfo().username ?? "default-user";
36
37
  }
@@ -101,6 +102,20 @@ async function managerRequest(method, requestPath, body) {
101
102
  request.end();
102
103
  });
103
104
  }
105
+ function getLogPath() {
106
+ return import_node_process.default.env[LOG_ENV];
107
+ }
108
+ function appendLog(message) {
109
+ const logPath = getLogPath();
110
+ if (!logPath) {
111
+ return;
112
+ }
113
+ try {
114
+ import_node_fs.default.appendFileSync(logPath, `${message}
115
+ `, { encoding: "utf8" });
116
+ } catch {
117
+ }
118
+ }
104
119
  function createStdioMessageHandler(target) {
105
120
  const targetUrl = new URL(`http://${target.host}:${target.port}/mcp`);
106
121
  return (message) => {
@@ -113,8 +128,7 @@ function createStdioMessageHandler(target) {
113
128
  method: "POST",
114
129
  headers: {
115
130
  "Content-Type": "application/json",
116
- "Content-Length": Buffer.byteLength(payload),
117
- [TARGET_HOST_HEADER]: `${target.host}:${target.port}`
131
+ "Content-Length": Buffer.byteLength(payload)
118
132
  }
119
133
  },
120
134
  (response) => {
@@ -130,9 +144,13 @@ function createStdioMessageHandler(target) {
130
144
  }
131
145
  );
132
146
  request.on("error", (error) => {
147
+ appendLog(`MCP proxy request failed: ${String(error)}`);
148
+ if (message.id === void 0 || message.id === null) {
149
+ return;
150
+ }
133
151
  const errorPayload = {
134
152
  jsonrpc: "2.0",
135
- id: message.id ?? null,
153
+ id: message.id,
136
154
  error: {
137
155
  code: -32e3,
138
156
  message: `MCP proxy request failed: ${String(error)}`
@@ -149,6 +167,7 @@ async function main() {
149
167
  const cwd = import_node_process.default.cwd();
150
168
  const target = await resolveTarget(cwd);
151
169
  if (!target) {
170
+ appendLog(`No VS Code instance registered for cwd: ${cwd}`);
152
171
  const errorPayload = {
153
172
  jsonrpc: "2.0",
154
173
  id: null,
@@ -176,6 +195,7 @@ async function main() {
176
195
  const message = JSON.parse(line);
177
196
  handler(message);
178
197
  } catch {
198
+ appendLog("Invalid JSON received by MCP proxy.");
179
199
  const errorPayload = {
180
200
  jsonrpc: "2.0",
181
201
  id: null,
@@ -196,6 +216,7 @@ async function main() {
196
216
  });
197
217
  }
198
218
  main().catch((error) => {
219
+ appendLog(`MCP proxy startup failed: ${String(error)}`);
199
220
  const errorPayload = {
200
221
  jsonrpc: "2.0",
201
222
  id: null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jiangxiaoxu/lm-tools-bridge-proxy",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Stdio MCP proxy for LM Tools Bridge (Windows Named Pipe resolve).",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -23,4 +23,4 @@
23
23
  "esbuild": "^0.27.2",
24
24
  "typescript": "^5.4.5"
25
25
  }
26
- }
26
+ }