script_read
Read C# script files from Unity projects to access and review code content directly within the development environment.
Instructions
Read a C# script from Unity project
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Path to the script file |
Implementation Reference
- src/tools/unity-mcp-tools.ts:340-351 (handler)Handler for script_read tool: validates input path, calls adapter.readScript, formats and returns the script content.case 'script_read': { if (!args.path) { throw new Error('path is required'); } const result = await this.adapter.readScript(args.path); return { content: [{ type: 'text', text: `Script content from ${result.path}:\n\n${result.content}` }] }; }
- src/tools/unity-mcp-tools.ts:85-98 (schema)Input schema definition for the script_read tool, specifying the required 'path' parameter.{ name: 'script_read', description: 'Read a C# script from Unity project', inputSchema: { type: 'object', properties: { path: { type: 'string', description: 'Path to the script file' } }, required: ['path'] } },
- src/simple-index.ts:35-37 (registration)Registers the tool list handler which includes script_read via UnityMcpTools.getTools().this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: this.tools.getTools(), }));
- Adapter helper method that sends HTTP POST request to Unity server's 'script/read' endpoint.async readScript(path: string): Promise<any> { return this.call('script/read', { path }); }
- src/embedded-scripts.ts:400-416 (helper)Unity C# implementation (embedded): reads script file content from disk in worker thread for 'script/read' endpoint.static object ReadScriptOnWorkerThread(JObject request) { var path = request["path"]?.ToString(); if (string.IsNullOrEmpty(path)) throw new ArgumentException("path is required"); var fullPath = Path.Combine(Application.dataPath, path.Substring(ASSETS_PREFIX_LENGTH)); if (!File.Exists(fullPath)) throw new FileNotFoundException($"File not found: {path}"); return new { path = path, content = File.ReadAllText(fullPath, new UTF8Encoding(true)), guid = "" // GUID requires AssetDatabase, skip in worker thread }; }