@akiojin/unity-mcp-server 2.14.15 → 2.14.17

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.14.15",
3
+ "version": "2.14.17",
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",
@@ -4,11 +4,81 @@
4
4
  */
5
5
  import { logger } from '../../core/config.js';
6
6
 
7
+ function cloneSchema(schema) {
8
+ if (!schema || typeof schema !== 'object') {
9
+ return schema;
10
+ }
11
+
12
+ if (typeof structuredClone === 'function') {
13
+ return structuredClone(schema);
14
+ }
15
+
16
+ try {
17
+ return JSON.parse(JSON.stringify(schema));
18
+ } catch {
19
+ return schema;
20
+ }
21
+ }
22
+
23
+ function sanitizeSchema(schema) {
24
+ if (!schema) {
25
+ return schema;
26
+ }
27
+
28
+ if (Array.isArray(schema)) {
29
+ schema.forEach(item => sanitizeSchema(item));
30
+ return schema;
31
+ }
32
+
33
+ if (typeof schema !== 'object') {
34
+ return schema;
35
+ }
36
+
37
+ if (Array.isArray(schema.required) && schema.required.length === 0) {
38
+ delete schema.required;
39
+ }
40
+
41
+ if (schema.properties && typeof schema.properties === 'object') {
42
+ Object.values(schema.properties).forEach(value => sanitizeSchema(value));
43
+ }
44
+
45
+ if (schema.items) {
46
+ sanitizeSchema(schema.items);
47
+ }
48
+
49
+ if (Array.isArray(schema.anyOf)) {
50
+ schema.anyOf.forEach(branch => sanitizeSchema(branch));
51
+ }
52
+
53
+ if (Array.isArray(schema.oneOf)) {
54
+ schema.oneOf.forEach(branch => sanitizeSchema(branch));
55
+ }
56
+
57
+ if (Array.isArray(schema.allOf)) {
58
+ schema.allOf.forEach(branch => sanitizeSchema(branch));
59
+ }
60
+
61
+ if (schema.then) {
62
+ sanitizeSchema(schema.then);
63
+ }
64
+
65
+ if (schema.else) {
66
+ sanitizeSchema(schema.else);
67
+ }
68
+
69
+ if (schema.additionalProperties && typeof schema.additionalProperties === 'object') {
70
+ sanitizeSchema(schema.additionalProperties);
71
+ }
72
+
73
+ return schema;
74
+ }
75
+
7
76
  export class BaseToolHandler {
8
77
  constructor(name, description, inputSchema = {}) {
9
78
  this.name = name;
10
79
  this.description = description;
11
- this.inputSchema = inputSchema;
80
+ const clonedSchema = cloneSchema(inputSchema) || {};
81
+ this.inputSchema = sanitizeSchema(clonedSchema);
12
82
  }
13
83
 
14
84
  /**
@@ -56,7 +56,8 @@ export class ScriptSymbolFindToolHandler extends BaseToolHandler {
56
56
  if (await this.index.isReady()) {
57
57
  const rows = await this.index.querySymbols({ name, kind, scope, exact });
58
58
  results = rows.map(r => ({
59
- path: r.path,
59
+ // Index returns project-relative paths already
60
+ path: (r.path || '').replace(/\\\\/g, '/'),
60
61
  symbol: {
61
62
  name: r.name,
62
63
  kind: r.kind,
@@ -73,19 +74,28 @@ export class ScriptSymbolFindToolHandler extends BaseToolHandler {
73
74
  if (!this.lsp) this.lsp = new LspRpcClient(info.projectRoot);
74
75
  const resp = await this.lsp.request('workspace/symbol', { query: String(name) });
75
76
  const arr = resp?.result || [];
76
- results = arr.map(s => ({
77
- path: (s.location?.uri || '').replace('file://',''),
78
- symbol: {
79
- name: s.name,
80
- kind: this.mapKind(s.kind),
81
- namespace: null,
82
- container: null,
83
- startLine: (s.location?.range?.start?.line ?? 0) + 1,
84
- startColumn: (s.location?.range?.start?.character ?? 0) + 1,
85
- endLine: (s.location?.range?.end?.line ?? 0) + 1,
86
- endColumn: (s.location?.range?.end?.character ?? 0) + 1,
87
- }
88
- }));
77
+ const root = String(info.projectRoot || '').replace(/\\\\/g, '/');
78
+ const rootWithSlash = root.endsWith('/') ? root : (root + '/');
79
+ results = arr.map(s => {
80
+ const uri = String(s.location?.uri || '');
81
+ // Normalize to absolute path without scheme
82
+ const abs = uri.replace('file://', '').replace(/\\\\/g, '/');
83
+ // Convert to project-relative if under project root
84
+ const rel = abs.startsWith(rootWithSlash) ? abs.slice(rootWithSlash.length) : abs;
85
+ return {
86
+ path: rel,
87
+ symbol: {
88
+ name: s.name,
89
+ kind: this.mapKind(s.kind),
90
+ namespace: null,
91
+ container: null,
92
+ startLine: (s.location?.range?.start?.line ?? 0) + 1,
93
+ startColumn: (s.location?.range?.start?.character ?? 0) + 1,
94
+ endLine: (s.location?.range?.end?.line ?? 0) + 1,
95
+ endColumn: (s.location?.range?.end?.character ?? 0) + 1,
96
+ }
97
+ };
98
+ });
89
99
  }
90
100
  // Optional post-filtering: scope and exact name
91
101
  if (scope && scope !== 'all') {
@@ -94,7 +104,9 @@ export class ScriptSymbolFindToolHandler extends BaseToolHandler {
94
104
  switch (scope) {
95
105
  case 'assets': return p.startsWith('Assets/');
96
106
  case 'packages': return p.startsWith('Packages/') || p.startsWith('Library/PackageCache/');
97
- case 'embedded': return p.startsWith('Packages/'); }
107
+ case 'embedded': return p.startsWith('Packages/');
108
+ default: return true;
109
+ }
98
110
  });
99
111
  }
100
112
  if (exact) {
@@ -13,7 +13,15 @@ export class SetUIElementValueToolHandler extends BaseToolHandler {
13
13
  description: 'Full hierarchy path to the UI element'
14
14
  },
15
15
  value: {
16
- description: 'New value to set (type depends on element type)'
16
+ anyOf: [
17
+ { type: 'string' },
18
+ { type: 'number' },
19
+ { type: 'boolean' },
20
+ { type: 'object' },
21
+ { type: 'array' },
22
+ { type: 'null' }
23
+ ],
24
+ description: 'New value to set. Supports string, number, boolean, object, array, or null depending on the UI element type.'
17
25
  },
18
26
  triggerEvents: {
19
27
  type: 'boolean',
@@ -46,4 +54,4 @@ export class SetUIElementValueToolHandler extends BaseToolHandler {
46
54
 
47
55
  return result;
48
56
  }
49
- }
57
+ }
@@ -93,32 +93,38 @@ export class CSharpLspUtils {
93
93
  }
94
94
 
95
95
  async downloadTo(url, dest) {
96
- const res = await fetch(url, { headers: { 'User-Agent': 'unity-mcp-server' } });
97
- if (!res.ok) throw new Error(`HTTP ${res.status} for ${url}`);
98
- const file = fs.createWriteStream(dest);
96
+ const headers = { 'User-Agent': 'unity-mcp-server' };
97
+ const fetchOnce = async () => {
98
+ const r = await fetch(url, { headers });
99
+ if (!r.ok) throw new Error(`HTTP ${r.status} for ${url}`);
100
+ return r;
101
+ };
102
+
103
+ const res = await fetchOnce();
99
104
  const body = res.body;
100
- if (body && typeof body.pipe === 'function') {
101
- await new Promise((resolve, reject) => {
102
- body.pipe(file);
103
- body.on('error', reject);
104
- file.on('finish', resolve);
105
- file.on('error', reject);
106
- });
107
- return;
108
- }
109
- try {
110
- const { Readable } = await import('node:stream');
111
- const nodeStream = Readable.fromWeb(body);
112
- await new Promise((resolve, reject) => {
113
- nodeStream.pipe(file);
114
- nodeStream.on('error', reject);
115
- file.on('finish', resolve);
116
- file.on('error', reject);
117
- });
118
- } catch (e) {
119
- const ab = await res.arrayBuffer();
120
- await fs.promises.writeFile(dest, Buffer.from(ab));
105
+
106
+ // Prefer WebStream -> Node stream piping
107
+ if (body) {
108
+ try {
109
+ const file = fs.createWriteStream(dest);
110
+ const { Readable } = await import('node:stream');
111
+ const nodeStream = Readable.fromWeb(body);
112
+ await new Promise((resolve, reject) => {
113
+ nodeStream.pipe(file);
114
+ nodeStream.on('error', reject);
115
+ file.on('finish', resolve);
116
+ file.on('error', reject);
117
+ });
118
+ return;
119
+ } catch (e) {
120
+ // If streaming failed or body was already consumed, re-fetch and fall back to arrayBuffer
121
+ }
121
122
  }
123
+
124
+ // Fallback: re-fetch fresh response and write full buffer
125
+ const res2 = await fetchOnce();
126
+ const ab = await res2.arrayBuffer();
127
+ await fs.promises.writeFile(dest, Buffer.from(ab));
122
128
  }
123
129
 
124
130
  async sha256File(file) {