get_script_source
Retrieve the source code of a script object (LocalScript, Script, or ModuleScript) by specifying the instance path using the MCP server in Roblox Studio. Enables direct access to script data for development and debugging purposes.
Instructions
Get the source code of a script object (LocalScript, Script, or ModuleScript)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instancePath | Yes | Path to the script instance (e.g., "game.ServerScriptService.MainScript") |
Input Schema (JSON Schema)
{
"properties": {
"instancePath": {
"description": "Path to the script instance (e.g., \"game.ServerScriptService.MainScript\")",
"type": "string"
}
},
"required": [
"instancePath"
],
"type": "object"
}
Implementation Reference
- src/tools/index.ts:415-428 (handler)The core handler function for the 'get_script_source' tool. It validates the instancePath, fetches the script source via an API request to '/api/get-script-source', formats the response as JSON text content, and returns it in MCP format.async getScriptSource(instancePath: string) { if (!instancePath) { throw new Error('Instance path is required for get_script_source'); } const response = await this.client.request('/api/get-script-source', { instancePath }); return { content: [ { type: 'text', text: JSON.stringify(response, null, 2) } ] }; }
- src/index.ts:606-619 (schema)Defines the tool schema including name, description, and input schema requiring 'instancePath' string for the get_script_source tool in the listTools response.{ name: 'get_script_source', description: 'Get the source code of a script object (LocalScript, Script, or ModuleScript)', inputSchema: { type: 'object', properties: { instancePath: { type: 'string', description: 'Path to the script instance (e.g., "game.ServerScriptService.MainScript")' } }, required: ['instancePath'] } },
- src/index.ts:712-713 (registration)MCP tool registration in the CallToolRequest handler switch statement, dispatching to this.tools.getScriptSource.case 'get_script_source': return await this.tools.getScriptSource((args as any)?.instancePath as string);
- src/http-server.ts:277-284 (registration)HTTP endpoint registration for '/mcp/get_script_source' that forwards requests to tools.getScriptSource and handles errors.app.post('/mcp/get_script_source', async (req, res) => { try { const result = await tools.getScriptSource(req.body.instancePath); res.json(result); } catch (error) { res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' }); } });