feat: Add write_script and read_script tools for script management#52
Closed
kevinswint wants to merge 2 commits intoRoblox:mainfrom
Closed
feat: Add write_script and read_script tools for script management#52kevinswint wants to merge 2 commits intoRoblox:mainfrom
kevinswint wants to merge 2 commits intoRoblox:mainfrom
Conversation
c07a213 to
afec379
Compare
Adds a new MCP tool that creates or updates Script, LocalScript, or
ModuleScript instances with provided Luau source code.
Why this matters:
The official MCP server can only execute code via run_code, but cannot
create or modify script source directly. This is because Roblox blocks
direct Script.Source access. This tool uses ScriptEditorService:UpdateSourceAsync()
- the officially supported method for writing script source in Studio plugins.
Features:
- Creates scripts in any service (ServerScriptService, ReplicatedStorage, etc.)
- Automatically creates intermediate folders for nested paths
- Updates existing scripts with new source code
- Supports Script, LocalScript, and ModuleScript types
- Optional script_type parameter (defaults to "Script")
Plugin changes:
- New WriteScript.luau tool handler
- Updated Types.luau with WriteScriptArgs
Usage:
write_script({
path: "ServerScriptService.GameManager",
source: "print('Hello!')",
script_type: "Script"
})
afec379 to
ce154a2
Compare
Adds read_script tool that reads source code from existing scripts using ScriptEditorService:GetEditorSource(). This enables diff/patch workflows and allows Claude to understand existing code before modifying it. Returns source code with metadata (script type, path, character count, line count). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Contributor
|
Hi! We added community contribution guidelines to help us triage and accept PRs. This PR adds several tools which would be better described as tools executed with Thank you for understanding! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds MCP tools for reading and writing script source code:
write_script- Creates or updates Script, LocalScript, or ModuleScript with provided Luau sourceread_script- Reads source code from existing scripts (enables diff/patch workflows)Both tools use
ScriptEditorServicefor safe, Studio-integrated script access.Motivation
AI assistants need to both read existing code (to understand before modifying) and write new code. The
run_codetool can execute Luau but cannot access script source directly due to Roblox security restrictions.ScriptEditorServiceprovides the officially supported methods:UpdateSourceAsync()for writingGetEditorSource()for readingChanges
Rust Server:
WriteScriptandReadScriptstructsPlugin:
WriteScript.luau- Creates scripts, handles nested paths, writes sourceReadScript.luau- Navigates to script, reads source with metadataTypes:
WriteScriptArgsandReadScriptArgstype definitionsTest plan
Example Usage
🤖 Generated with Claude Code