@el4cteo/rbx-studio-mcp 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +203 -0
- package/dist/bridge/rpc.js +243 -0
- package/dist/bridge/rpc.js.map +1 -0
- package/dist/bridge/server.js +281 -0
- package/dist/bridge/server.js.map +1 -0
- package/dist/index.js +104 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/apidump.js +269 -0
- package/dist/lib/apidump.js.map +1 -0
- package/dist/lib/errors.js +38 -0
- package/dist/lib/errors.js.map +1 -0
- package/dist/lib/format.js +191 -0
- package/dist/lib/format.js.map +1 -0
- package/dist/lib/pluginbuild.js +83 -0
- package/dist/lib/pluginbuild.js.map +1 -0
- package/dist/lib/png.js +84 -0
- package/dist/lib/png.js.map +1 -0
- package/dist/lib/protocol.js +22 -0
- package/dist/lib/protocol.js.map +1 -0
- package/dist/lib/tool.js +27 -0
- package/dist/lib/tool.js.map +1 -0
- package/dist/resources.js +70 -0
- package/dist/resources.js.map +1 -0
- package/dist/tools/api.js +78 -0
- package/dist/tools/api.js.map +1 -0
- package/dist/tools/character.js +94 -0
- package/dist/tools/character.js.map +1 -0
- package/dist/tools/debug.js +211 -0
- package/dist/tools/debug.js.map +1 -0
- package/dist/tools/device.js +74 -0
- package/dist/tools/device.js.map +1 -0
- package/dist/tools/discover.js +217 -0
- package/dist/tools/discover.js.map +1 -0
- package/dist/tools/exec.js +191 -0
- package/dist/tools/exec.js.map +1 -0
- package/dist/tools/input.js +96 -0
- package/dist/tools/input.js.map +1 -0
- package/dist/tools/instances.js +261 -0
- package/dist/tools/instances.js.map +1 -0
- package/dist/tools/perf.js +367 -0
- package/dist/tools/perf.js.map +1 -0
- package/dist/tools/playtest.js +153 -0
- package/dist/tools/playtest.js.map +1 -0
- package/dist/tools/screenshot.js +75 -0
- package/dist/tools/screenshot.js.map +1 -0
- package/dist/tools/scripts.js +316 -0
- package/dist/tools/scripts.js.map +1 -0
- package/dist/tools/session.js +152 -0
- package/dist/tools/session.js.map +1 -0
- package/dist/tools/world.js +281 -0
- package/dist/tools/world.js.map +1 -0
- package/package.json +62 -0
- package/plugin/default.project.json +6 -0
- package/plugin/src/Config.luau +59 -0
- package/plugin/src/Console.luau +657 -0
- package/plugin/src/Context.luau +35 -0
- package/plugin/src/Dispatch.luau +90 -0
- package/plugin/src/Editor.luau +142 -0
- package/plugin/src/Emulation.luau +151 -0
- package/plugin/src/LogBuffer.luau +277 -0
- package/plugin/src/Net.luau +102 -0
- package/plugin/src/Paths.luau +255 -0
- package/plugin/src/Phrase.luau +465 -0
- package/plugin/src/Png.luau +238 -0
- package/plugin/src/Scope.luau +78 -0
- package/plugin/src/ScriptEdit.luau +100 -0
- package/plugin/src/Serialize.luau +287 -0
- package/plugin/src/TextEdit.luau +296 -0
- package/plugin/src/Transport.luau +328 -0
- package/plugin/src/Undo.luau +72 -0
- package/plugin/src/Visuals.luau +710 -0
- package/plugin/src/handlers/Api.luau +242 -0
- package/plugin/src/handlers/Assets.luau +145 -0
- package/plugin/src/handlers/Capture.luau +187 -0
- package/plugin/src/handlers/Character.luau +361 -0
- package/plugin/src/handlers/Debug.luau +391 -0
- package/plugin/src/handlers/Device.luau +119 -0
- package/plugin/src/handlers/Discover.luau +289 -0
- package/plugin/src/handlers/Exec.luau +270 -0
- package/plugin/src/handlers/Geometry.luau +261 -0
- package/plugin/src/handlers/Input.luau +287 -0
- package/plugin/src/handlers/Instances.luau +389 -0
- package/plugin/src/handlers/Perf.luau +645 -0
- package/plugin/src/handlers/Playtest.luau +205 -0
- package/plugin/src/handlers/Scripts.luau +387 -0
- package/plugin/src/handlers/Session.luau +168 -0
- package/plugin/src/handlers/Viewport.luau +302 -0
- package/plugin/src/handlers/World.luau +176 -0
- package/plugin/src/init.server.luau +317 -0
- package/scripts/build-plugin.mjs +157 -0
- package/scripts/check-plugin.mjs +97 -0
- package/scripts/install-plugin.mjs +39 -0
- package/scripts/latency.mjs +201 -0
- package/scripts/locate-luau.mjs +51 -0
- package/scripts/sourcemap.mjs +58 -0
- package/scripts/test-plugin.mjs +82 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
Thin HttpService wrapper.
|
|
4
|
+
|
|
5
|
+
Plugins reach 127.0.0.1 through a per-plugin permission grant rather than the
|
|
6
|
+
experience-wide "Allow HTTP Requests" setting, so the first request after
|
|
7
|
+
install pops a permission dialog. That failure mode is turned into a message
|
|
8
|
+
the user can act on instead of a raw Luau error.
|
|
9
|
+
]]
|
|
10
|
+
|
|
11
|
+
local HttpService = game:GetService("HttpService")
|
|
12
|
+
|
|
13
|
+
local Config = require(script.Parent.Config)
|
|
14
|
+
|
|
15
|
+
local Net = {}
|
|
16
|
+
|
|
17
|
+
export type Response = {
|
|
18
|
+
ok: boolean,
|
|
19
|
+
statusCode: number,
|
|
20
|
+
body: string,
|
|
21
|
+
error: string?,
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
--[[
|
|
25
|
+
Performs a request and never throws. Callers branch on `ok`; `error` carries
|
|
26
|
+
a user-facing explanation when the request could not be made at all.
|
|
27
|
+
]]
|
|
28
|
+
function Net.request(method: string, path: string, body: string?): Response
|
|
29
|
+
local ok, result = pcall(function()
|
|
30
|
+
return HttpService:RequestAsync({
|
|
31
|
+
Url = Config.baseUrl() .. path,
|
|
32
|
+
Method = method,
|
|
33
|
+
Headers = Config.headers(),
|
|
34
|
+
Body = body,
|
|
35
|
+
})
|
|
36
|
+
end)
|
|
37
|
+
|
|
38
|
+
if not ok then
|
|
39
|
+
return {
|
|
40
|
+
ok = false,
|
|
41
|
+
statusCode = 0,
|
|
42
|
+
body = "",
|
|
43
|
+
error = Net.explain(tostring(result)),
|
|
44
|
+
}
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
local response = result :: any
|
|
48
|
+
return {
|
|
49
|
+
ok = response.Success,
|
|
50
|
+
statusCode = response.StatusCode,
|
|
51
|
+
body = response.Body,
|
|
52
|
+
}
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
function Net.postJson(path: string, value: any): Response
|
|
56
|
+
return Net.request("POST", path, HttpService:JSONEncode(value))
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
--[[
|
|
60
|
+
Turns HttpService's terse errors into something the user can act on. These
|
|
61
|
+
strings surface in the plugin widget, so they are written for a person, not
|
|
62
|
+
for the agent.
|
|
63
|
+
]]
|
|
64
|
+
function Net.explain(message: string): string
|
|
65
|
+
local lowered = string.lower(message)
|
|
66
|
+
|
|
67
|
+
if string.find(lowered, "not enabled") or string.find(lowered, "permission") then
|
|
68
|
+
return "Studio blocked the request. Open Plugins -> Manage Plugins, find "
|
|
69
|
+
.. "Studio MCP, and allow it to reach 127.0.0.1."
|
|
70
|
+
end
|
|
71
|
+
if
|
|
72
|
+
string.find(lowered, "connectfail")
|
|
73
|
+
or string.find(lowered, "curl")
|
|
74
|
+
or string.find(lowered, "could not connect")
|
|
75
|
+
or string.find(lowered, "connection refused")
|
|
76
|
+
then
|
|
77
|
+
return string.format(
|
|
78
|
+
"Nothing is listening on port %d. Start the server with "
|
|
79
|
+
.. "`npx -y roblox-studio-mcp` (or check --port if you changed it).",
|
|
80
|
+
Config.getPort()
|
|
81
|
+
)
|
|
82
|
+
end
|
|
83
|
+
if string.find(lowered, "timedout") or string.find(lowered, "timeout") then
|
|
84
|
+
return "The server stopped responding. It may have been restarted; "
|
|
85
|
+
.. "the plugin will keep retrying."
|
|
86
|
+
end
|
|
87
|
+
return message
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
--[[
|
|
91
|
+
Decodes a JSON body, returning nil rather than throwing on malformed input.
|
|
92
|
+
A truncated frame is a transport hiccup, not a reason to kill the plugin.
|
|
93
|
+
]]
|
|
94
|
+
function Net.decode(body: string): any?
|
|
95
|
+
local ok, value = pcall(HttpService.JSONDecode, HttpService, body)
|
|
96
|
+
if not ok then
|
|
97
|
+
return nil
|
|
98
|
+
end
|
|
99
|
+
return value
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
return Net
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
--!strict
|
|
2
|
+
--[[
|
|
3
|
+
Dot-notation instance paths, e.g. "Workspace.Map.Spawn".
|
|
4
|
+
|
|
5
|
+
Paths are the address format for every tool, so resolution failures are the
|
|
6
|
+
most common error an agent will hit. Each failure says which segment broke
|
|
7
|
+
and what does exist at that level, which is usually enough for the model to
|
|
8
|
+
fix the path itself instead of falling back to a blind tree dump.
|
|
9
|
+
]]
|
|
10
|
+
|
|
11
|
+
local Dispatch = require(script.Parent.Dispatch)
|
|
12
|
+
|
|
13
|
+
local Paths = {}
|
|
14
|
+
|
|
15
|
+
--[[
|
|
16
|
+
Splits a path into segments. A leading "game." is optional and stripped, so
|
|
17
|
+
both "game.Workspace.Part" and "Workspace.Part" resolve identically.
|
|
18
|
+
]]
|
|
19
|
+
function Paths.split(path: string): { string }
|
|
20
|
+
local segments: { string } = {}
|
|
21
|
+
for segment in string.gmatch(path, "[^%.]+") do
|
|
22
|
+
table.insert(segments, segment)
|
|
23
|
+
end
|
|
24
|
+
if segments[1] == "game" then
|
|
25
|
+
table.remove(segments, 1)
|
|
26
|
+
end
|
|
27
|
+
return segments
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
--[[
|
|
31
|
+
Splits "Part[3]" into ("Part", 3), or ("Part", nil) when unindexed.
|
|
32
|
+
|
|
33
|
+
Sibling names are not unique in Roblox -- a Workspace with 77 parts all named
|
|
34
|
+
"Part" is completely ordinary -- so a bare dotted path is ambiguous and
|
|
35
|
+
`FindFirstChild` would silently pick the first match. Every path this module
|
|
36
|
+
emits therefore carries a 1-based index whenever the name is shared, and
|
|
37
|
+
`resolve` honours it.
|
|
38
|
+
]]
|
|
39
|
+
local function parseSegment(segment: string): (string, number?)
|
|
40
|
+
local name, index = string.match(segment, "^(.*)%[(%d+)%]$")
|
|
41
|
+
if name and index then
|
|
42
|
+
return name, tonumber(index)
|
|
43
|
+
end
|
|
44
|
+
return segment, nil
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
export type NameIndex = { [Instance]: { [string]: { Instance } } }
|
|
48
|
+
|
|
49
|
+
--[[
|
|
50
|
+
Groups a parent's children by name, memoised across one request. Without the
|
|
51
|
+
memo, formatting paths for N same-named siblings is O(N^2); a listing of a
|
|
52
|
+
few thousand parts would stall Studio's main thread.
|
|
53
|
+
]]
|
|
54
|
+
local function childrenByName(parent: Instance, memo: NameIndex?): { [string]: { Instance } }
|
|
55
|
+
local cached = if memo then memo[parent] else nil
|
|
56
|
+
if cached then
|
|
57
|
+
return cached
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
local byName: { [string]: { Instance } } = {}
|
|
61
|
+
for _, child in parent:GetChildren() do
|
|
62
|
+
local list = byName[child.Name]
|
|
63
|
+
if not list then
|
|
64
|
+
list = {}
|
|
65
|
+
byName[child.Name] = list
|
|
66
|
+
end
|
|
67
|
+
table.insert(list, child)
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
if memo then
|
|
71
|
+
memo[parent] = byName
|
|
72
|
+
end
|
|
73
|
+
return byName
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
--[[
|
|
77
|
+
1-based position among identically named siblings, or nil when the name is
|
|
78
|
+
already unique and no index is needed.
|
|
79
|
+
]]
|
|
80
|
+
local function siblingIndex(instance: Instance, memo: NameIndex?): number?
|
|
81
|
+
local parent = instance.Parent
|
|
82
|
+
if not parent then
|
|
83
|
+
return nil
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
local list = childrenByName(parent, memo)[instance.Name]
|
|
87
|
+
if not list or #list <= 1 then
|
|
88
|
+
return nil
|
|
89
|
+
end
|
|
90
|
+
for index, child in list do
|
|
91
|
+
if child == instance then
|
|
92
|
+
return index
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
return nil
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
local function childNames(parent: Instance, limit: number): string
|
|
99
|
+
local names: { string } = {}
|
|
100
|
+
for _, child in parent:GetChildren() do
|
|
101
|
+
table.insert(names, child.Name)
|
|
102
|
+
if #names >= limit then
|
|
103
|
+
table.insert(names, "...")
|
|
104
|
+
break
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
if #names == 0 then
|
|
108
|
+
return "(no children)"
|
|
109
|
+
end
|
|
110
|
+
return table.concat(names, ", ")
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
--[[
|
|
114
|
+
Resolves a path to an Instance, or raises a NOT_FOUND with the failing
|
|
115
|
+
segment and its siblings. `FindFirstChild` is used rather than indexing so a
|
|
116
|
+
missing child never throws a bare Luau error.
|
|
117
|
+
]]
|
|
118
|
+
function Paths.resolve(path: string): Instance
|
|
119
|
+
if typeof(path) ~= "string" or path == "" then
|
|
120
|
+
Dispatch.fail(
|
|
121
|
+
"BAD_PATH",
|
|
122
|
+
"An instance path is required.",
|
|
123
|
+
'Paths are dot-separated from the DataModel root, e.g. "Workspace.Map.Spawn". '
|
|
124
|
+
.. "Use `find` or `tree` to discover valid paths."
|
|
125
|
+
)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
local segments = Paths.split(path)
|
|
129
|
+
if #segments == 0 then
|
|
130
|
+
return game
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
local current: Instance = game
|
|
134
|
+
for index, segment in segments do
|
|
135
|
+
local name, ordinal = parseSegment(segment)
|
|
136
|
+
local nextInstance: Instance? = nil
|
|
137
|
+
|
|
138
|
+
if ordinal then
|
|
139
|
+
-- Explicit disambiguation: take the nth child with this exact name.
|
|
140
|
+
local list = childrenByName(current, nil)[name]
|
|
141
|
+
nextInstance = if list then list[ordinal] else nil
|
|
142
|
+
elseif index == 1 then
|
|
143
|
+
-- Services must be fetched by class name, and are not always
|
|
144
|
+
-- present as children until first accessed.
|
|
145
|
+
local ok, service = pcall(function()
|
|
146
|
+
return game:GetService(name :: any)
|
|
147
|
+
end)
|
|
148
|
+
nextInstance = if ok then service else current:FindFirstChild(name)
|
|
149
|
+
else
|
|
150
|
+
nextInstance = current:FindFirstChild(name)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
if not nextInstance then
|
|
154
|
+
local partial = table.concat(segments, ".", 1, index)
|
|
155
|
+
-- `fail` never returns; returning its result keeps that visible to
|
|
156
|
+
-- the type checker so `current` stays non-optional below.
|
|
157
|
+
return Dispatch.fail(
|
|
158
|
+
"NOT_FOUND",
|
|
159
|
+
string.format('No instance at "%s".', partial),
|
|
160
|
+
string.format(
|
|
161
|
+
'"%s" has no child named "%s". It does have: %s',
|
|
162
|
+
current:GetFullName(),
|
|
163
|
+
segment,
|
|
164
|
+
childNames(current, 25)
|
|
165
|
+
)
|
|
166
|
+
)
|
|
167
|
+
end
|
|
168
|
+
current = nextInstance
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
return current
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
--[[
|
|
175
|
+
Resolves many paths at once, collecting failures instead of stopping at the
|
|
176
|
+
first one. Batch tools report every bad path in a single response so the
|
|
177
|
+
agent can fix them all in one retry rather than one call per mistake.
|
|
178
|
+
]]
|
|
179
|
+
function Paths.resolveMany(paths: { string }): ({ Instance }, { string })
|
|
180
|
+
local resolved: { Instance } = {}
|
|
181
|
+
local failures: { string } = {}
|
|
182
|
+
for _, path in paths do
|
|
183
|
+
local ok, result = pcall(Paths.resolve, path)
|
|
184
|
+
if ok then
|
|
185
|
+
table.insert(resolved, result :: Instance)
|
|
186
|
+
else
|
|
187
|
+
local err = result :: any
|
|
188
|
+
table.insert(
|
|
189
|
+
failures,
|
|
190
|
+
string.format("%s: %s", path, if typeof(err) == "table" then err.message else tostring(err))
|
|
191
|
+
)
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
return resolved, failures
|
|
195
|
+
end
|
|
196
|
+
|
|
197
|
+
--[[
|
|
198
|
+
Formats an instance into a path that resolves back to that exact instance.
|
|
199
|
+
|
|
200
|
+
`GetFullName` is deliberately not used: it emits "Workspace.Part" for every
|
|
201
|
+
one of 77 parts named "Part", so the paths it produces are not addresses at
|
|
202
|
+
all. Here each segment gains a [n] suffix when its name is shared with a
|
|
203
|
+
sibling.
|
|
204
|
+
|
|
205
|
+
Pass a shared `memo` when formatting many instances in one request.
|
|
206
|
+
|
|
207
|
+
The index is positional, so it shifts if same-named siblings are inserted or
|
|
208
|
+
removed between calls. Read a fresh path after any structural change.
|
|
209
|
+
]]
|
|
210
|
+
function Paths.of(instance: Instance, memo: NameIndex?): string
|
|
211
|
+
--[[
|
|
212
|
+
Refuses anything that is not an Instance, rather than duck-typing it.
|
|
213
|
+
|
|
214
|
+
This walks `.Name` and `.Parent`, which a plain table can also have -- so
|
|
215
|
+
handed a table carrying those two fields it used to return a perfectly
|
|
216
|
+
well-formed path for an object that exists nowhere in the data model.
|
|
217
|
+
That happened: `GeometryService:FragmentAsync` returns `{Index, Instance}`
|
|
218
|
+
wrappers, a handler assigned `.Name` and `.Parent` to the wrapper, and
|
|
219
|
+
this function reported eight new parts by full path when none had been
|
|
220
|
+
created. A fabricated path is worse than an error, because everything
|
|
221
|
+
downstream treats it as real.
|
|
222
|
+
]]
|
|
223
|
+
if typeof(instance) ~= "Instance" then
|
|
224
|
+
error(
|
|
225
|
+
string.format(
|
|
226
|
+
"Paths.of expects an Instance, got %s. This is a bug in the caller, "
|
|
227
|
+
.. "not in the request.",
|
|
228
|
+
typeof(instance)
|
|
229
|
+
),
|
|
230
|
+
2
|
|
231
|
+
)
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
if instance == game then
|
|
235
|
+
return "game"
|
|
236
|
+
end
|
|
237
|
+
|
|
238
|
+
local segments: { string } = {}
|
|
239
|
+
local current: Instance? = instance
|
|
240
|
+
|
|
241
|
+
while current ~= nil and current ~= game do
|
|
242
|
+
local node = current :: Instance
|
|
243
|
+
local ordinal = siblingIndex(node, memo)
|
|
244
|
+
table.insert(
|
|
245
|
+
segments,
|
|
246
|
+
1,
|
|
247
|
+
if ordinal then string.format("%s[%d]", node.Name, ordinal) else node.Name
|
|
248
|
+
)
|
|
249
|
+
current = node.Parent
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
return table.concat(segments, ".")
|
|
253
|
+
end
|
|
254
|
+
|
|
255
|
+
return Paths
|