Implement get_script command for improved script retrieval in MCP

- Introduced a new `get_script` command to allow agents to read script source code directly from Roblox Studio, enhancing conflict resolution during sync operations.
- Updated the MCP stream handling to support the new command, including error handling for missing or invalid parameters.
- Enhanced the App component to manage the `get_script` command and its response, ensuring proper integration with the existing MCP functionality.
- Updated the TODO list to reflect the addition of the `get_script` command and its associated documentation requirements.

These changes aim to improve the overall functionality and user experience of the MCP integration, particularly in script management.
This commit is contained in:
Joe 2026-03-01 09:41:20 -06:00
parent 9aa3145b06
commit fd49602adb
8 changed files with 1487 additions and 207 deletions

View file

@ -17,6 +17,7 @@ function McpStream.new(options)
local self = setmetatable({}, McpStream)
self._onSyncCommand = options.onSyncCommand
self._onGetScriptCommand = options.onGetScriptCommand
self._getPluginConfig = options.getPluginConfig
self._wsClient = nil
self._running = false
@ -125,6 +126,33 @@ function McpStream:_tryConnect()
end)
end
end)
elseif data.type == "getScript" and data.requestId then
Log.info("MCP stream: received getScript command (requestId={})", data.requestId)
local resultPromise = self._onGetScriptCommand(data.requestId, data)
resultPromise
:andThen(function(result)
if self._wsClient then
local json = HttpService:JSONEncode(result)
pcall(function()
self._wsClient:Send(json)
end)
end
end)
:catch(function(err)
Log.warn("MCP stream: getScript command failed: {}", tostring(err))
if self._wsClient then
local errorResult = HttpService:JSONEncode({
requestId = data.requestId,
status = "error",
message = tostring(err),
})
pcall(function()
self._wsClient:Send(errorResult)
end)
end
end)
end
end)