Enhance MCP tool functionality and improve logging capabilities

- Introduced new MCP tools for executing Luau code, inserting models, and retrieving console output, enhancing the plugin's capabilities for user interaction.
- Implemented a logging system to capture console output and provide detailed feedback during code execution and play mode operations.
- Updated the MCP stream to handle passthrough commands, allowing for better integration of tool commands and improved error handling.
- Enhanced the TODO list to reflect new tasks related to documentation for the added MCP tools and logging features.

These changes aim to improve the overall functionality and user experience of the MCP integration, particularly in script execution and model management.
This commit is contained in:
Joe 2026-03-01 11:56:05 -06:00
parent fd49602adb
commit fd990b86c6
24 changed files with 1464 additions and 12 deletions

View file

@ -10,6 +10,15 @@ local strict = require(script.Parent.strict)
local RECONNECT_INTERVAL = 5
local PASSTHROUGH_TOOLS = {
run_code = true,
insert_model = true,
get_console_output = true,
get_studio_mode = true,
start_stop_play = true,
run_script_in_play_mode = true,
}
local McpStream = {}
McpStream.__index = McpStream
@ -18,6 +27,7 @@ function McpStream.new(options)
self._onSyncCommand = options.onSyncCommand
self._onGetScriptCommand = options.onGetScriptCommand
self._onToolCommand = options.onToolCommand
self._getPluginConfig = options.getPluginConfig
self._wsClient = nil
self._running = false
@ -153,6 +163,33 @@ function McpStream:_tryConnect()
end)
end
end)
elseif data.type and data.requestId and PASSTHROUGH_TOOLS[data.type] then
Log.info("MCP stream: received {} command (requestId={})", data.type, data.requestId)
local resultPromise = self._onToolCommand(data.requestId, data.type, data.args or {})
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: {} command failed: {}", data.type, tostring(err))
if self._wsClient then
local errorResult = HttpService:JSONEncode({
requestId = data.requestId,
status = "error",
response = tostring(err),
})
pcall(function()
self._wsClient:Send(errorResult)
end)
end
end)
end
end)