set_script_source
Update script source code safely in Roblox Studio without using loadstring. Input the script instance path and the new source code to modify scripts directly in the Studio environment.
Instructions
Safely set the source code of a script object without using loadstring (Studio only)
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| instancePath | Yes | Path to the script instance (e.g., "game.ServerScriptService.MainScript") | |
| source | Yes | New source code for the script |
Input Schema (JSON Schema)
{
"properties": {
"instancePath": {
"description": "Path to the script instance (e.g., \"game.ServerScriptService.MainScript\")",
"type": "string"
},
"source": {
"description": "New source code for the script",
"type": "string"
}
},
"required": [
"instancePath",
"source"
],
"type": "object"
}
Implementation Reference
- src/tools/index.ts:430-443 (handler)The primary handler function for the 'set_script_source' MCP tool. Validates instancePath and source parameters, makes an API request to '/api/set-script-source', and returns a formatted text response with the result.async setScriptSource(instancePath: string, source: string) { if (!instancePath || typeof source !== 'string') { throw new Error('Instance path and source code string are required for set_script_source'); } const response = await this.client.request('/api/set-script-source', { instancePath, source }); return { content: [ { type: 'text', text: JSON.stringify(response, null, 2) } ] }; }
- src/index.ts:623-636 (schema)Input schema definition for the 'set_script_source' tool, specifying required string properties: instancePath and source.inputSchema: { type: 'object', properties: { instancePath: { type: 'string', description: 'Path to the script instance (e.g., "game.ServerScriptService.MainScript")' }, source: { type: 'string', description: 'New source code for the script' } }, required: ['instancePath', 'source'] }
- src/index.ts:620-637 (registration)Registration of the 'set_script_source' tool in the MCP tools list, including name, description, and input schema for the ListTools endpoint.{ name: 'set_script_source', description: 'Safely set the source code of a script object without using loadstring (Studio only)', inputSchema: { type: 'object', properties: { instancePath: { type: 'string', description: 'Path to the script instance (e.g., "game.ServerScriptService.MainScript")' }, source: { type: 'string', description: 'New source code for the script' } }, required: ['instancePath', 'source'] } }
- src/index.ts:714-715 (registration)Switch case registration that routes 'set_script_source' tool calls to this.tools.setScriptSource in the MCP CallTool handler.case 'set_script_source': return await this.tools.setScriptSource((args as any)?.instancePath as string, (args as any)?.source as string);
- src/http-server.ts:286-293 (handler)Secondary HTTP handler for POST /mcp/set_script_source endpoint, which invokes tools.setScriptSource and returns JSON response.app.post('/mcp/set_script_source', async (req, res) => { try { const result = await tools.setScriptSource(req.body.instancePath, req.body.source); res.json(result); } catch (error) { res.status(500).json({ error: error instanceof Error ? error.message : 'Unknown error' }); } });