@akiojin/unity-mcp-server 2.41.4 → 2.41.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@akiojin/unity-mcp-server",
3
- "version": "2.41.4",
3
+ "version": "2.41.6",
4
4
  "description": "MCP server and Unity Editor bridge — enables AI assistants to control Unity for AI-assisted workflows",
5
5
  "type": "module",
6
6
  "main": "src/core/server.js",
@@ -131,13 +131,32 @@ export class CSharpLspUtils {
131
131
  async ensureLocal(rid) {
132
132
  const p = this.getLocalPath(rid);
133
133
  const desired = this.getDesiredVersion();
134
- if (!desired) throw new Error('mcp-server version not found; cannot resolve LSP tag');
134
+
135
+ // バージョン取得失敗時もバイナリが存在すれば使用
136
+ if (!desired) {
137
+ if (fs.existsSync(p)) {
138
+ logger.warn('[csharp-lsp] version not found, using existing binary');
139
+ return p;
140
+ }
141
+ throw new Error('mcp-server version not found; cannot resolve LSP tag');
142
+ }
143
+
135
144
  const current = this.readLocalVersion(rid);
136
145
  if (fs.existsSync(p) && current === desired) return p;
137
- const resolved = await this.autoDownload(rid, desired);
138
- if (!fs.existsSync(p)) throw new Error('csharp-lsp binary not found after download');
139
- this.writeLocalVersion(rid, resolved || desired);
140
- return p;
146
+
147
+ // ダウンロード失敗時のフォールバック
148
+ try {
149
+ const resolved = await this.autoDownload(rid, desired);
150
+ if (!fs.existsSync(p)) throw new Error('csharp-lsp binary not found after download');
151
+ this.writeLocalVersion(rid, resolved || desired);
152
+ return p;
153
+ } catch (e) {
154
+ if (fs.existsSync(p)) {
155
+ logger.warn(`[csharp-lsp] download failed, using existing binary: ${e.message}`);
156
+ return p;
157
+ }
158
+ throw e;
159
+ }
141
160
  }
142
161
 
143
162
  async autoDownload(rid, version) {
@@ -194,7 +213,9 @@ export class CSharpLspUtils {
194
213
  if (process.platform !== 'win32') fs.chmodSync(dest, 0o755);
195
214
  } catch {}
196
215
  logger.info(`[csharp-lsp] downloaded: ${path.basename(dest)} @ ${path.dirname(dest)}`);
197
- return targetVersion;
216
+ // manifestから実際のバージョンを取得(信頼性の高いソースとして使用)
217
+ const actualVersion = manifest.version || targetVersion;
218
+ return actualVersion;
198
219
  }
199
220
 
200
221
  async fetchLatestReleaseVersion(repo) {
@@ -17,23 +17,28 @@ export class LspProcessManager {
17
17
  if (this.state.proc && !this.state.proc.killed) return this.state.proc;
18
18
  if (this.state.starting) return this.state.starting;
19
19
  this.state.starting = (async () => {
20
- const rid = this.utils.detectRid();
21
- const bin = await this.utils.ensureLocal(rid);
22
- const proc = spawn(bin, { stdio: ['pipe', 'pipe', 'pipe'] });
23
- proc.on('error', e => logger.error(`[csharp-lsp] process error: ${e.message}`));
24
- proc.on('close', (code, sig) => {
25
- logger.warn(`[csharp-lsp] exited code=${code} signal=${sig || ''}`);
26
- if (this.state.proc === proc) {
27
- this.state.proc = null;
28
- }
29
- });
30
- proc.stderr.on('data', d => {
31
- const s = String(d || '').trim();
32
- if (s) logger.debug(`[csharp-lsp] ${s}`);
33
- });
34
- this.state.proc = proc;
35
- logger.info(`[csharp-lsp] started (pid=${proc.pid})`);
36
- return proc;
20
+ try {
21
+ const rid = this.utils.detectRid();
22
+ const bin = await this.utils.ensureLocal(rid);
23
+ const proc = spawn(bin, { stdio: ['pipe', 'pipe', 'pipe'] });
24
+ proc.on('error', e => logger.error(`[csharp-lsp] process error: ${e.message}`));
25
+ proc.on('close', (code, sig) => {
26
+ logger.warn(`[csharp-lsp] exited code=${code} signal=${sig || ''}`);
27
+ if (this.state.proc === proc) {
28
+ this.state.proc = null;
29
+ }
30
+ });
31
+ proc.stderr.on('data', d => {
32
+ const s = String(d || '').trim();
33
+ if (s) logger.debug(`[csharp-lsp] ${s}`);
34
+ });
35
+ this.state.proc = proc;
36
+ logger.info(`[csharp-lsp] started (pid=${proc.pid})`);
37
+ return proc;
38
+ } catch (e) {
39
+ logger.error(`[csharp-lsp] failed to start: ${e.message}`);
40
+ throw e;
41
+ }
37
42
  })();
38
43
  try {
39
44
  return await this.state.starting;
@@ -64,9 +64,17 @@ export class LspRpcClient {
64
64
  }
65
65
 
66
66
  writeMessage(obj) {
67
+ if (!this.proc || this.proc.killed) {
68
+ throw new Error('LSP process not available');
69
+ }
67
70
  const json = JSON.stringify(obj);
68
71
  const payload = `Content-Length: ${Buffer.byteLength(json, 'utf8')}\r\n\r\n${json}`;
69
- this.proc.stdin.write(payload, 'utf8');
72
+ try {
73
+ this.proc.stdin.write(payload, 'utf8');
74
+ } catch (e) {
75
+ logger.error(`[csharp-lsp] writeMessage failed: ${e.message}`);
76
+ throw e;
77
+ }
70
78
  }
71
79
 
72
80
  async initialize() {