Add COX tools for doorlock, fuel, and target functionalities

- Implemented GetOxDoorlockServerFunction and GetOxDoorlockClientFunction for server-side and client-side door management, respectively.
- Created GetOxFuelServerFunction and GetOxFuelClientFunction for handling fuel management on server and client sides.
- Developed GetOxTargetClientFunction to manage targeting interactions, including global options and zone management.
- Added feature tests for all new tools to ensure functionality and error handling for unknown functions.
This commit is contained in:
Adrian Mejias committed 2026-03-01 15:35:04 -06:00
1 parent 29b854fd44
commit 24c53368a7
13 files changed
+1095

No files matched your search

@@ -0,0 +1,94 @@
<?php
namespace App\Mcp\Tools\COX\Doorlock\Server;
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Mcp\Request;
use Laravel\Mcp\Response;
use Laravel\Mcp\Server\Attributes\Description;
use Laravel\Mcp\Server\Tool;
#[Description('Look up ox_doorlock server events by name. Returns event signature, parameters, and usage examples for server-side door events.')]
class GetOxDoorlockServerEvent extends Tool
{
/**
* Handle the tool request.
*/
public function handle(Request $request): Response
{
$eventName = $request->get('event_name');
$language = $request->get('language', 'lua');
$event = $this->findEvent($eventName);
if (! $event) {
return Response::text(sprintf("ox_doorlock server event '%s' not found. Check ox_doorlock documentation at https://coxdocs.dev/ox_doorlock", $eventName));
}
$output = $this->formatEventInfo($event, $language);
return Response::text($output);
}
/**
* Find an ox_doorlock server event.
*/
protected function findEvent(string $name): ?array
{
$events = [
'ox_doorlock:stateChanged' => [
'type' => 'doorlock',
'namespace' => 'Server',
'description' => 'Triggered when a door lock state changes',
'side' => 'server',
'parameters' => [
['name' => 'doorId', 'type' => 'number', 'description' => 'The door ID'],
['name' => 'state', 'type' => 'number', 'description' => 'New door state (0 = unlocked, 1 = locked)'],
],
'lua_example' => "AddEventHandler('ox_doorlock:stateChanged', function(doorId, state)\n local doorName = exports.ox_doorlock:getDoor(doorId)?.name or 'Unknown'\n local stateText = state == 1 and 'locked' or 'unlocked'\n print(('Door %s (ID: %s) is now %s'):format(doorName, doorId, stateText))\nend)",
'js_example' => "on('ox_doorlock:stateChanged', (doorId, state) => {\n const door = exports.ox_doorlock.getDoor(doorId);\n const doorName = door?.name || 'Unknown';\n const stateText = state === 1 ? 'locked' : 'unlocked';\n console.log(`Door \${doorName} (ID: \${doorId}) is now \${stateText}`);\n});",
],
];
$nameLower = strtolower($name);
foreach ($events as $eventName => $eventData) {
if (strtolower($eventName) === $nameLower) {
return array_merge(['name' => $eventName], $eventData);
}
}
return null;
}
/**
* Format event info.
*/
protected function formatEventInfo(array $event, string $language): string
{
return view('mcp.cox.cox-event-reference', [
'event' => $event,
'language' => $language,
])->render();
}
/**
* Get the tool's input schema.
*
* @return array<string, \Illuminate\Contracts\JsonSchema\JsonSchema>
*/
public function schema(JsonSchema $schema): array
{
return [
'event_name' => $schema
->string()
->description('The name of the ox_doorlock server event to look up (e.g., "ox_doorlock:stateChanged")')
->required(),
'language' => $schema
->string()
->enum(['lua', 'js'])
->description('The scripting language for code examples')
->default('lua'),
];
}
}
@@ -0,0 +1,130 @@
<?php
namespace App\Mcp\Tools\COX\Doorlock\Server;
use Illuminate\Contracts\JsonSchema\JsonSchema;
use Laravel\Mcp\Request;
use Laravel\Mcp\Response;
use Laravel\Mcp\Server\Attributes\Description;
use Laravel\Mcp\Server\Tool;
#[Description('Look up ox_doorlock server functions by name. Returns function signature, parameters, return type, and usage examples for server-side door management.')]
class GetOxDoorlockServerFunction extends Tool
{
/**
* Handle the tool request.
*/
public function handle(Request $request): Response
{
$functionName = $request->get('function_name');
$language = $request->get('language', 'lua');
$function = $this->findFunction($functionName);
if (! $function) {
return Response::text(sprintf("ox_doorlock server function '%s' not found. Check ox_doorlock documentation at https://coxdocs.dev/ox_doorlock", $functionName));
}
$output = $this->formatFunctionInfo($function, $language);
return Response::text($output);
}
/**
* Find an ox_doorlock server function.
*/
protected function findFunction(string $name): ?array
{
$functions = [
'getDoor' => [
'namespace' => 'Server',
'description' => 'Get door data by door ID',
'side' => 'server',
'parameters' => [
['name' => 'doorId', 'type' => 'number', 'description' => 'The door ID'],
],
'returns' => ['type' => 'table|nil', 'description' => 'Door data or nil if not found'],
'lua_example' => "local door = exports.ox_doorlock:getDoor(1)\nif door then\n print('Door name: '..door.name)\n print('Door state: '..door.state)\nend",
'js_example' => "const door = exports.ox_doorlock.getDoor(1);\nif (door) {\n console.log('Door name: ' + door.name);\n console.log('Door state: ' + door.state);\n}",
],
'getDoorFromName' => [
'namespace' => 'Server',
'description' => 'Get door data by door name',
'side' => 'server',
'parameters' => [
['name' => 'doorName', 'type' => 'string', 'description' => 'The door name'],
],
'returns' => ['type' => 'table|nil', 'description' => 'Door data or nil if not found'],
'lua_example' => "local door = exports.ox_doorlock:getDoorFromName('mrpd_main')\nif door then\n print('Door ID: '..door.id)\n print('Door is locked: '..tostring(door.state == 1))\nend",
'js_example' => "const door = exports.ox_doorlock.getDoorFromName('mrpd_main');\nif (door) {\n console.log('Door ID: ' + door.id);\n console.log('Door is locked: ' + (door.state === 1));\n}",
],
'editDoor' => [
'namespace' => 'Server',
'description' => 'Edit door properties by door ID',
'side' => 'server',
'parameters' => [
['name' => 'doorId', 'type' => 'number', 'description' => 'The door ID'],
['name' => 'data', 'type' => 'table', 'description' => 'Table with properties to update (state, groups, etc.)'],
['name' => 'playerId', 'type' => 'number|nil', 'description' => 'Optional player ID who triggered the edit'],
],
'returns' => ['type' => 'boolean', 'description' => 'True if door was successfully edited'],
'lua_example' => "local success = exports.ox_doorlock:editDoor(1, {\n state = 0, -- Unlocked\n groups = {police = 0} -- Police can use\n})\nif success then\n print('Door edited successfully')\nend",
'js_example' => "const success = exports.ox_doorlock.editDoor(1, {\n state: 0, // Unlocked\n groups: {police: 0} // Police can use\n});\nif (success) {\n console.log('Door edited successfully');\n}",
],
'setDoorState' => [
'namespace' => 'Server',
'description' => 'Set the lock state of a door',
'side' => 'server',
'parameters' => [
['name' => 'doorId', 'type' => 'number', 'description' => 'The door ID'],
['name' => 'state', 'type' => 'number', 'description' => '0 = unlocked, 1 = locked'],
['name' => 'playerId', 'type' => 'number|nil', 'description' => 'Optional player ID who triggered the state change'],
],
'returns' => ['type' => 'boolean', 'description' => 'True if state was successfully changed'],
'lua_example' => "local success = exports.ox_doorlock:setDoorState(1, 1) -- Lock door ID 1\nif success then\n print('Door locked successfully')\nend",
'js_example' => "const success = exports.ox_doorlock.setDoorState(1, 1); // Lock door ID 1\nif (success) {\n console.log('Door locked successfully');\n}",
],
];
$nameLower = strtolower($name);
foreach ($functions as $functionName => $functionData) {
if (strtolower($functionName) === $nameLower) {
return array_merge(['name' => $functionName], $functionData);
}
}
return null;
}
/**
* Format function info.
*/
protected function formatFunctionInfo(array $function, string $language): string
{
return view('mcp.cox.cox-function', [
'function' => $function,
'language' => $language,
])->render();
}
/**
* Get the tool's input schema.
*
* @return array<string, \Illuminate\Contracts\JsonSchema\JsonSchema>
*/
public function schema(JsonSchema $schema): array
{
return [
'function_name' => $schema
->string()
->description('The name of the ox_doorlock server function to look up (e.g., "getDoor", "getDoorFromName", "editDoor", "setDoorState")')
->required(),
'language' => $schema
->string()
->enum(['lua', 'js'])
->description('The scripting language for code examples')
->default('lua'),
];
}
}