Skip to main content
Glama

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
NameRequiredDescriptionDefault
pathYesPath to the script file

Implementation Reference

  • 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}`
        }]
      };
    }
  • 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']
      }
    },
  • 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 });
    }
  • 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
        };
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/zabaglione/mcp-server-unity'

If you have feedback or need assistance with the MCP directory API, please join our Discord server