mcp_tools¶
File: lua/ge/extensions/mcp/tools.lua · VM: Game Engine (GE) · 45 lines · BeamNG.drive 0.40.5 (buildbot 302427 on GitLab)
Access: extension mcp_tools: extensions.load("mcp_tools"), then the global mcp_tools
Loader of the MCP tool modules. On load it scans /lua/ge/extensions/mcp/tools/*.lua (level 1), requires them one by one and merges into the mcp_tools extension: the tool functions, the schemas (schemas), the callbacks (cb, exposed under _cb) and the onUpdate, onPreRender, onInstabilityDetected hooks, redistributed to all modules. The server (mcp_server) then exposes as an MCP tool each mcp_tools function that does not start with on+uppercase.
Example¶
-- add a tool: create lua/ge/extensions/mcp/tools/monoutil.lua
local M = {}
function M.dire_bonjour(args) return 'bonjour ' .. tostring(args and args.nom), false end
M.schemas = { dire_bonjour = { description = 'Dit bonjour', inputSchema = { type='object', properties = { nom = { type='string' } } } } }
return M
-- then reload_lua (Ctrl+L) to load it
Notes¶
- A module that fails on require is skipped with an error log
failed to load tool module "name"; the others continue. - If two modules define a tool with the same name, the last one loaded overwrites the previous one (order of FS:findFiles, not guaranteed).
- Changes to tool files are only picked up after a full Lua VM reload (reload_lua tool).
- Depends on core_vehicles and core_vehicle_manager.
Functions¶
| Function | Description | Line |
|---|---|---|
mcp_tools.onInstabilityDetected(vid, returnData) |
Fan-out hook: relays the physics instability detected by the engine to the modules (vehicle.lua logs it). (dynamically assigned) (internal) (hook) | dyn |
mcp_tools.onPreRender(dtReal) |
Fan-out hook: calls the onPreRender of each module that defines one (debug: shape drawing). Called before rendering. (dynamically assigned) (internal) (hook) | dyn |
mcp_tools.onUpdate(dtReal) |
Fan-out hook generated by the loader: calls the onUpdate of each tool module that defines one (camera, input, spawn). Called every frame. (dynamically assigned) (internal) (hook) | dyn |
Parameter details¶
mcp_tools.onInstabilityDetected(vid, returnData)¶
Fan-out hook: relays the physics instability detected by the engine to the modules (vehicle.lua logs it). (dynamically assigned)
vid(integer) : Id of the unstable vehicle (inferred from code).returnData(any) : Data provided by the engine (unused).
mcp_tools.onPreRender(dtReal)¶
Fan-out hook: calls the onPreRender of each module that defines one (debug: shape drawing). Called before rendering. (dynamically assigned)
dtReal(number) : Real duration (s).
mcp_tools.onUpdate(dtReal)¶
Fan-out hook generated by the loader: calls the onUpdate of each tool module that defines one (camera, input, spawn). Called every frame. (dynamically assigned)
dtReal(number) : Real frame time (s).
Fields¶
| Field | Type | Description |
|---|---|---|
_cb |
table |
Callbacks called from the vehicle VM or the UI via extensions.mcp_tools._cb.<name>(...): ai, electrics, vehLua, vueDump, uiEval. They report asynchronous results into mcp/shared asyncResults. |
schemas |
table |
Tool metadata: name -> {description, inputSchema} (JSON Schema), merged from each module. |
Calls into the engine (C++)¶
FS:findFiles
tim19Atlas (Tim0219800) — derived from BeamNG GmbH Lua code (bCDDL 1.1, see LICENSE). Source: lua/ge/extensions/mcp/tools.lua.