@akiojin/unity-mcp-server 2.45.2 → 2.45.4

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.45.2",
3
+ "version": "2.45.4",
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",
@@ -72,8 +72,17 @@ export class CodeIndex {
72
72
 
73
73
  // Use shared connection for all CodeIndex instances
74
74
  if (sharedConnections.db && sharedConnections.dbPath === dbPath) {
75
- this.db = sharedConnections.db;
76
- return this.db;
75
+ // Verify the DB file still exists before returning cached connection
76
+ if (!fs.existsSync(dbPath)) {
77
+ // File was deleted or never created, invalidate cache
78
+ logger.info('[index] DB file missing, invalidating cached connection');
79
+ sharedConnections.db = null;
80
+ sharedConnections.dbPath = null;
81
+ sharedConnections.schemaInitialized = false;
82
+ } else {
83
+ this.db = sharedConnections.db;
84
+ return this.db;
85
+ }
77
86
  }
78
87
 
79
88
  try {
@@ -31,9 +31,24 @@ function saveDatabase(db, dbPath) {
31
31
  try {
32
32
  const data = db.exportDb();
33
33
  const buffer = Buffer.from(data);
34
+
35
+ // Ensure parent directory exists
36
+ const dir = path.dirname(dbPath);
37
+ if (!fs.existsSync(dir)) {
38
+ fs.mkdirSync(dir, { recursive: true });
39
+ }
40
+
34
41
  fs.writeFileSync(dbPath, buffer);
42
+
43
+ // Verify file was written
44
+ if (!fs.existsSync(dbPath)) {
45
+ throw new Error('Database file was not created');
46
+ }
47
+
48
+ log('info', `[worker] Database saved successfully: ${dbPath} (${buffer.length} bytes)`);
35
49
  } catch (e) {
36
- log('warn', `[worker] Failed to save database: ${e.message}`);
50
+ log('error', `[worker] Failed to save database: ${e.message}`);
51
+ throw e; // Re-throw to fail the build
37
52
  }
38
53
  }
39
54
 
@@ -184,23 +199,25 @@ async function runBuild() {
184
199
  let db = null;
185
200
 
186
201
  try {
187
- // Dynamic import fast-sql in worker thread (hybrid: better-sqlite3 or sql.js fallback)
188
- let SQL;
202
+ // Dynamic import fast-sql Database class (uses better-sqlite3 when available, sql.js fallback)
203
+ let Database;
189
204
  try {
190
- const initFastSql = (await import('@akiojin/fast-sql')).default;
191
- SQL = await initFastSql();
205
+ const fastSql = await import('@akiojin/fast-sql');
206
+ Database = fastSql.Database;
192
207
  } catch (e) {
193
208
  throw new Error(`fast-sql unavailable in worker: ${e.message}`);
194
209
  }
195
210
 
196
- // Open or create database
211
+ // Open or create database using Database.create() for better-sqlite3 support
197
212
  if (fs.existsSync(dbPath)) {
198
213
  const buffer = fs.readFileSync(dbPath);
199
- db = new SQL.Database(buffer);
214
+ db = await Database.create(buffer);
200
215
  } else {
201
- db = new SQL.Database();
216
+ db = await Database.create();
202
217
  }
203
218
 
219
+ log('info', `[worker] Using backend: ${db.backendType || 'unknown'}`);
220
+
204
221
  // Initialize schema if needed (fast-sql applies optimal PRAGMAs automatically)
205
222
  runSQL(
206
223
  db,