Add documentation links, refactor tools, and implement new tests
- Added links to QBCore and COX MySQL documentation in the main docs index. - Refactored GenerateManifest and GenerateResourceBoilerplate tools to use the correct namespaces. - Updated tests for GenerateManifest and GenerateResourceBoilerplate tools to remove unnecessary parentheses. - Refactored COX event and function tools to use the correct namespaces and updated related tests. - Introduced new tests for GetEventClientReference and GetEventServerReference tools. - Added tests for inventory client and server functions, ensuring they handle various scenarios. - Created tests for native client and server functions, including case insensitivity and example support. - Implemented QBCore client and server event/function reference tests, ensuring proper functionality and error handling. - Removed outdated tests for GetEventReference and GetQBCoreEventReference tools. - Updated SearchFiveMDocs tool to use the correct namespace and improved test coverage.
This commit is contained in:
38 files changed
+2248
-818
No files matched your search
@@ -0,0 +1,178 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\COX\Inventory\Client;
|
||||
|
||||
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_inventory client functions by name. Returns function signature, parameters, return type, and usage examples for client-side inventory management.')]
|
||||
class GetInventoryClientFunction 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_inventory client function '%s' not found. Check ox_inventory documentation at https://coxdocs.dev/ox_inventory", $functionName));
|
||||
}
|
||||
|
||||
$output = $this->formatFunctionInfo($function, $language);
|
||||
|
||||
return Response::text($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find an ox_inventory client function.
|
||||
*/
|
||||
protected function findFunction(string $name): ?array
|
||||
{
|
||||
$functions = [
|
||||
'openInventory' => [
|
||||
'namespace' => 'Client',
|
||||
'description' => 'Opens an inventory using the passed data',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'invType', 'type' => 'string', 'description' => "Type: 'player', 'shop', 'stash', 'crafting', 'container', 'drop', 'glovebox', 'trunk', 'dumpster'"],
|
||||
['name' => 'data', 'type' => 'number|string|table', 'description' => 'Inventory data (playerId, stash name, etc.)'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "exports.ox_inventory:openInventory('player', 3)",
|
||||
'js_example' => "exports.ox_inventory.openInventory('player', 3);",
|
||||
],
|
||||
'SearchPlayer' => [
|
||||
'namespace' => 'Client',
|
||||
'description' => 'Searches the player inventory for an item. Can return slots or count.',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'search', 'type' => 'string', 'description' => "'slots' or 'count'"],
|
||||
['name' => 'item', 'type' => 'table|string', 'description' => 'Item name or array of items'],
|
||||
['name' => 'metadata', 'type' => 'table|string|nil', 'description' => 'Metadata filter'],
|
||||
],
|
||||
'returns' => ['type' => 'table|number', 'description' => 'Slots or count depending on search type'],
|
||||
'lua_example' => "local count = exports.ox_inventory:SearchPlayer('count', 'water')\nprint('You have '..count..' water')",
|
||||
'js_example' => "const count = exports.ox_inventory.SearchPlayer('count', 'water');\nconsole.log(`You have \${count} water`);",
|
||||
],
|
||||
'GetCurrentWeapon' => [
|
||||
'namespace' => 'Client',
|
||||
'description' => 'Get data for the currently equipped weapon',
|
||||
'side' => 'client',
|
||||
'parameters' => [],
|
||||
'returns' => ['type' => 'table|nil', 'description' => 'Weapon data or nil if no weapon equipped'],
|
||||
'lua_example' => "local weapon = exports.ox_inventory:GetCurrentWeapon()\nif weapon then\n print('Current weapon: '..weapon.name)\nend",
|
||||
'js_example' => "const weapon = exports.ox_inventory.GetCurrentWeapon();\nif (weapon) {\n console.log('Current weapon: ' + weapon.name);\n}",
|
||||
],
|
||||
'closeInventory' => [
|
||||
'namespace' => 'Client',
|
||||
'description' => 'Closes the currently open inventory',
|
||||
'side' => 'client',
|
||||
'parameters' => [],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => 'exports.ox_inventory:closeInventory()',
|
||||
'js_example' => 'exports.ox_inventory.closeInventory();',
|
||||
],
|
||||
'useItem' => [
|
||||
'namespace' => 'Client',
|
||||
'description' => 'Uses an item in the inventory. Triggers server-side item use callback.',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'item', 'type' => 'table', 'description' => 'Item data with slot and name'],
|
||||
['name' => 'cb', 'type' => 'function|nil', 'description' => 'Callback function after use'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "local item = {slot = 1, name = 'water'}\nexports.ox_inventory:useItem(item)",
|
||||
'js_example' => "const item = {slot: 1, name: 'water'};\nexports.ox_inventory.useItem(item);",
|
||||
],
|
||||
'displayMetadata' => [
|
||||
'namespace' => 'Client',
|
||||
'description' => 'Shows metadata information for an item',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'metadata', 'type' => 'table', 'description' => 'Metadata table to display'],
|
||||
],
|
||||
'returns' => ['type' => 'table', 'description' => 'Formatted metadata for display'],
|
||||
'lua_example' => "local formatted = exports.ox_inventory:displayMetadata({serial = 'ABC123', owner = 'John'})",
|
||||
'js_example' => "const formatted = exports.ox_inventory.displayMetadata({serial: 'ABC123', owner: 'John'});",
|
||||
],
|
||||
'Items' => [
|
||||
'namespace' => 'Client',
|
||||
'description' => 'Register client-side usable items with callbacks',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'itemName', 'type' => 'string', 'description' => 'Name of the item to register'],
|
||||
['name' => 'callback', 'type' => 'function', 'description' => 'Function(data, slot) called when item is used'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "exports.ox_inventory:Items('bandage', function(data, slot)\n -- Apply bandage healing logic\n print('Used bandage from slot '..slot)\nend)",
|
||||
'js_example' => "exports.ox_inventory.Items('bandage', (data, slot) => {\n // Apply bandage healing logic\n console.log(`Used bandage from slot \${slot}`);\n});",
|
||||
],
|
||||
'getCurrentWeight' => [
|
||||
'namespace' => 'Client',
|
||||
'description' => 'Returns the current total weight of the player inventory',
|
||||
'side' => 'client',
|
||||
'parameters' => [],
|
||||
'returns' => ['type' => 'number', 'description' => 'Current weight in grams'],
|
||||
'lua_example' => "local weight = exports.ox_inventory:getCurrentWeight()\nprint('Current inventory weight: '..weight..'g')",
|
||||
'js_example' => "const weight = exports.ox_inventory.getCurrentWeight();\nconsole.log(`Current inventory weight: \${weight}g`);",
|
||||
],
|
||||
'getPlayerInventory' => [
|
||||
'namespace' => 'Client',
|
||||
'description' => 'Returns the full player inventory data',
|
||||
'side' => 'client',
|
||||
'parameters' => [],
|
||||
'returns' => ['type' => 'table', 'description' => 'Complete inventory data'],
|
||||
'lua_example' => "local inventory = exports.ox_inventory:getPlayerInventory()\nprint(json.encode(inventory, {indent=true}))",
|
||||
'js_example' => "const inventory = exports.ox_inventory.getPlayerInventory();\nconsole.log(JSON.stringify(inventory, null, 2));",
|
||||
],
|
||||
];
|
||||
|
||||
$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-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_inventory client function to look up (e.g., "openInventory", "SearchPlayer", "useItem", "closeInventory")')
|
||||
->required(),
|
||||
'language' => $schema
|
||||
->string()
|
||||
->enum(['lua', 'js'])
|
||||
->description('The scripting language for code examples')
|
||||
->default('lua'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\COX\Inventory\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_inventory server functions by name. Returns function signature, parameters, return type, and usage examples for server-side inventory management.')]
|
||||
class GetInventoryServerFunction 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_inventory server function '%s' not found. Check ox_inventory documentation at https://coxdocs.dev/ox_inventory", $functionName));
|
||||
}
|
||||
|
||||
$output = $this->formatFunctionInfo($function, $language);
|
||||
|
||||
return Response::text($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find an ox_inventory server function.
|
||||
*/
|
||||
protected function findFunction(string $name): ?array
|
||||
{
|
||||
$functions = [
|
||||
'AddItem' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Adds an item into the specified inventory. Should be used alongside CanCarryItem.',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory unique id, playerId, or table with id and owner'],
|
||||
['name' => 'item', 'type' => 'string', 'description' => 'Name of the item to add'],
|
||||
['name' => 'count', 'type' => 'number', 'description' => 'Number of items to add'],
|
||||
['name' => 'metadata', 'type' => 'table|string|nil', 'description' => 'Unique data to attach to item. String creates table with "type" field'],
|
||||
['name' => 'slot', 'type' => 'number|nil', 'description' => 'Specific slot to add item to'],
|
||||
['name' => 'cb', 'type' => 'function|nil', 'description' => 'Callback function(success, response)'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean, string|table', 'description' => 'success and response (or via callback)'],
|
||||
'lua_example' => "local success, response = exports.ox_inventory:AddItem('gloveVGH283', 'bread', 4)\nif not success then\n return print(response) -- 'invalid_item', 'invalid_inventory', 'inventory_full'\nend\nprint(json.encode(response, {indent=true}))",
|
||||
'js_example' => "const [success, response] = exports.ox_inventory.AddItem('gloveVGH283', 'bread', 4);\nif (!success) {\n return console.log(response);\n}\nconsole.log(JSON.stringify(response, null, 2));",
|
||||
],
|
||||
'RemoveItem' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Removes the specified item from the specified inventory',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory unique id, playerId, or table'],
|
||||
['name' => 'item', 'type' => 'string', 'description' => 'Name of the item to remove'],
|
||||
['name' => 'count', 'type' => 'number', 'description' => 'Number of items to remove'],
|
||||
['name' => 'metadata', 'type' => 'table|string|nil', 'description' => 'Only remove items with matching metadata'],
|
||||
['name' => 'slot', 'type' => 'number|nil', 'description' => 'Specific slot to remove from'],
|
||||
['name' => 'ignoreTotal', 'type' => 'boolean|nil', 'description' => 'Removes as many as possible up to count'],
|
||||
['name' => 'strict', 'type' => 'boolean|nil', 'description' => 'Exact match on metadata (default true)'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean, string', 'description' => 'success and optional error message'],
|
||||
'lua_example' => "local success = exports.ox_inventory:RemoveItem('gloveVGH283', 'water', 2)\nif not success then\n print('Failed to remove item')\nend",
|
||||
'js_example' => "const success = exports.ox_inventory.RemoveItem('gloveVGH283', 'water', 2);\nif (!success) {\n console.log('Failed to remove item');\n}",
|
||||
],
|
||||
'GetItem' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Returns generic item data from the specified inventory with total count',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
['name' => 'item', 'type' => 'table|string', 'description' => 'Item name or array of item names'],
|
||||
['name' => 'metadata', 'type' => 'any|nil', 'description' => 'Only count items matching metadata'],
|
||||
['name' => 'returnsCount', 'type' => 'boolean|nil', 'description' => 'If true, returns count only'],
|
||||
],
|
||||
'returns' => ['type' => 'table|number', 'description' => 'Item data with count, or just count if returnsCount=true'],
|
||||
'lua_example' => "local item = ox_inventory:GetItem(source, 'water', nil, false)\nprint(json.encode(item, {indent=true}))",
|
||||
'js_example' => "const item = ox_inventory.GetItem(source, 'water', null, false);\nconsole.log(JSON.stringify(item, null, 2));",
|
||||
],
|
||||
'CanCarryItem' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Returns true or false depending if inventory can carry the specified item. Checks weight and slots.',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
['name' => 'item', 'type' => 'table|string', 'description' => 'Item name or array of items'],
|
||||
['name' => 'count', 'type' => 'number', 'description' => 'Number of items'],
|
||||
['name' => 'metadata', 'type' => 'table|string|nil', 'description' => 'Item metadata'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean', 'description' => 'True if can carry, false otherwise'],
|
||||
'lua_example' => "if exports.ox_inventory:CanCarryItem(source, 'water', 3) then\n -- Do stuff if can carry\nelse\n -- Do stuff if can't carry\nend",
|
||||
'js_example' => "if (exports.ox_inventory.CanCarryItem(source, 'water', 3)) {\n // Do stuff if can carry\n} else {\n // Do stuff if can't carry\n}",
|
||||
],
|
||||
'GetInventory' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Returns the inventory associated with the ID and owner. Returns null if not found.',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'number|table', 'description' => 'Inventory identifier'],
|
||||
['name' => 'owner', 'type' => 'string|boolean|nil', 'description' => 'Owner identifier'],
|
||||
],
|
||||
'returns' => ['type' => 'table|nil', 'description' => 'Inventory data or nil'],
|
||||
'lua_example' => "local inventory = exports.ox_inventory:GetInventory('example_stash', false)\nprint(json.encode(inventory, {indent = true}))",
|
||||
'js_example' => "const inventory = exports.ox_inventory.GetInventory('example_stash', false);\nconsole.log(JSON.stringify(inventory, null, 2));",
|
||||
],
|
||||
'RegisterStash' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Creates a new custom stash. Must be called before player can open the stash.',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'id', 'type' => 'string|number', 'description' => 'Stash identifier for database'],
|
||||
['name' => 'label', 'type' => 'string', 'description' => 'Display name when inventory is open'],
|
||||
['name' => 'slots', 'type' => 'number', 'description' => 'Number of slots'],
|
||||
['name' => 'maxWeight', 'type' => 'number', 'description' => 'Maximum weight in grams'],
|
||||
['name' => 'owner', 'type' => 'string|boolean|nil', 'description' => 'Owner: string=specific, true=per-player, nil=shared'],
|
||||
['name' => 'groups', 'type' => 'table|nil', 'description' => 'Table of jobs with minimum grades'],
|
||||
['name' => 'coords', 'type' => 'vector3|table|nil', 'description' => 'Coordinates for proximity check'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "exports.ox_inventory:RegisterStash('policestash', 'Police Storage', 50, 100000, false, {['police'] = 0})",
|
||||
'js_example' => "exports.ox_inventory.RegisterStash('policestash', 'Police Storage', 50, 100000, false, {police: 0});",
|
||||
],
|
||||
'Search' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Searches an inventory for a specified item. Can return slots or count.',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
['name' => 'search', 'type' => 'string', 'description' => "'slots' or 'count'"],
|
||||
['name' => 'item', 'type' => 'table|string', 'description' => 'Item name or array of names'],
|
||||
['name' => 'metadata', 'type' => 'table|string|nil', 'description' => 'Item metadata filter'],
|
||||
],
|
||||
'returns' => ['type' => 'table|number', 'description' => 'Slots data or count depending on search type'],
|
||||
'lua_example' => "local slots = exports.ox_inventory:Search(source, 'slots', 'water')\nfor k, v in pairs(slots) do\n print(v.slot..' contains '..v.count..' water')\nend",
|
||||
'js_example' => "const slots = exports.ox_inventory.Search(source, 'slots', 'water');\nfor (const [k, v] of Object.entries(slots)) {\n console.log(`\${v.slot} contains \${v.count} water`);\n}",
|
||||
],
|
||||
'SetItem' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Sets data for a specific item slot in an inventory',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
['name' => 'slot', 'type' => 'number', 'description' => 'Slot number to modify'],
|
||||
['name' => 'item', 'type' => 'table', 'description' => 'Item data to set'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean', 'description' => 'Success status'],
|
||||
'lua_example' => "exports.ox_inventory:SetItem(source, 1, {name = 'water', count = 5})",
|
||||
'js_example' => "exports.ox_inventory.SetItem(source, 1, {name: 'water', count: 5});",
|
||||
],
|
||||
'ClearInventory' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Removes all items from the specified inventory',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
['name' => 'filterItem', 'type' => 'string|nil', 'description' => 'Optional item name to keep'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "exports.ox_inventory:ClearInventory(source) -- Clear all items\nexports.ox_inventory:ClearInventory(source, 'id_card') -- Clear all except id_card",
|
||||
'js_example' => "exports.ox_inventory.ClearInventory(source); // Clear all items\nexports.ox_inventory.ClearInventory(source, 'id_card'); // Clear all except id_card",
|
||||
],
|
||||
'ConfiscateInventory' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Temporarily removes all items from inventory and stores them for later return',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean', 'description' => 'Success status'],
|
||||
'lua_example' => "local success = exports.ox_inventory:ConfiscateInventory(source)\nif success then\n print('Inventory confiscated')\nend",
|
||||
'js_example' => "const success = exports.ox_inventory.ConfiscateInventory(source);\nif (success) {\n console.log('Inventory confiscated');\n}",
|
||||
],
|
||||
'ReturnInventory' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Returns previously confiscated items to the inventory',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean', 'description' => 'Success status'],
|
||||
'lua_example' => "local success = exports.ox_inventory:ReturnInventory(source)\nif success then\n print('Inventory returned')\nend",
|
||||
'js_example' => "const success = exports.ox_inventory.ReturnInventory(source);\nif (success) {\n console.log('Inventory returned');\n}",
|
||||
],
|
||||
'SetDurability' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Sets the durability value for an item in a specific slot',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
['name' => 'slot', 'type' => 'number', 'description' => 'Slot number'],
|
||||
['name' => 'durability', 'type' => 'number', 'description' => 'Durability value (0-100)'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean', 'description' => 'Success status'],
|
||||
'lua_example' => 'exports.ox_inventory:SetDurability(source, 1, 50) -- Set to 50% durability',
|
||||
'js_example' => 'exports.ox_inventory.SetDurability(source, 1, 50); // Set to 50% durability',
|
||||
],
|
||||
'SetMetadata' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Updates metadata for an item in a specific slot',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
['name' => 'slot', 'type' => 'number', 'description' => 'Slot number'],
|
||||
['name' => 'metadata', 'type' => 'table', 'description' => 'New metadata table'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean, table', 'description' => 'Success status and updated item data'],
|
||||
'lua_example' => "local success, item = exports.ox_inventory:SetMetadata(source, 1, {serial = 'ABC123', registered = 'John Doe'})",
|
||||
'js_example' => "const [success, item] = exports.ox_inventory.SetMetadata(source, 1, {serial: 'ABC123', registered: 'John Doe'});",
|
||||
],
|
||||
'SwapSlots' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Swaps items between two slots in an inventory',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
['name' => 'fromSlot', 'type' => 'number', 'description' => 'Source slot number'],
|
||||
['name' => 'toSlot', 'type' => 'number', 'description' => 'Destination slot number'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean', 'description' => 'Success status'],
|
||||
'lua_example' => 'exports.ox_inventory:SwapSlots(source, 1, 5) -- Swap items in slots 1 and 5',
|
||||
'js_example' => 'exports.ox_inventory.SwapSlots(source, 1, 5); // Swap items in slots 1 and 5',
|
||||
],
|
||||
'SetMaxWeight' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Sets the maximum weight capacity for an inventory',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
['name' => 'maxWeight', 'type' => 'number', 'description' => 'Maximum weight in grams'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean', 'description' => 'Success status'],
|
||||
'lua_example' => 'exports.ox_inventory:SetMaxWeight(source, 50000) -- Set max weight to 50kg',
|
||||
'js_example' => 'exports.ox_inventory.SetMaxWeight(source, 50000); // Set max weight to 50kg',
|
||||
],
|
||||
'GetItemCount' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Returns the total count of a specific item in an inventory',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
['name' => 'item', 'type' => 'string', 'description' => 'Item name'],
|
||||
['name' => 'metadata', 'type' => 'table|nil', 'description' => 'Optional metadata filter'],
|
||||
],
|
||||
'returns' => ['type' => 'number', 'description' => 'Total count of the item'],
|
||||
'lua_example' => "local count = exports.ox_inventory:GetItemCount(source, 'water')\nprint('Player has '..count..' water')",
|
||||
'js_example' => "const count = exports.ox_inventory.GetItemCount(source, 'water');\nconsole.log(`Player has \${count} water`);",
|
||||
],
|
||||
'GetSlotWeight' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Returns the weight of an item in a specific slot',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'inv', 'type' => 'table|string|number', 'description' => 'Inventory identifier'],
|
||||
['name' => 'slot', 'type' => 'number', 'description' => 'Slot number'],
|
||||
],
|
||||
'returns' => ['type' => 'number', 'description' => 'Weight in grams'],
|
||||
'lua_example' => "local weight = exports.ox_inventory:GetSlotWeight(source, 1)\nprint('Slot 1 weight: '..weight..'g')",
|
||||
'js_example' => "const weight = exports.ox_inventory.GetSlotWeight(source, 1);\nconsole.log(`Slot 1 weight: \${weight}g`);",
|
||||
],
|
||||
'CustomDrop' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Creates a custom drop inventory at specific coordinates',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'prefix', 'type' => 'string', 'description' => 'Prefix for drop ID'],
|
||||
['name' => 'items', 'type' => 'table', 'description' => 'Array of items to add'],
|
||||
['name' => 'coords', 'type' => 'vector3', 'description' => 'Drop coordinates'],
|
||||
['name' => 'slots', 'type' => 'number|nil', 'description' => 'Number of slots (default config)'],
|
||||
['name' => 'maxWeight', 'type' => 'number|nil', 'description' => 'Max weight (default config)'],
|
||||
['name' => 'model', 'type' => 'string|number|nil', 'description' => 'Model hash for drop'],
|
||||
],
|
||||
'returns' => ['type' => 'string', 'description' => 'Drop inventory ID'],
|
||||
'lua_example' => "local dropId = exports.ox_inventory:CustomDrop('evidence', {{name='phone', count=1}}, vector3(100.0, 200.0, 30.0))",
|
||||
'js_example' => "const dropId = exports.ox_inventory.CustomDrop('evidence', [{name: 'phone', count: 1}], [100.0, 200.0, 30.0]);",
|
||||
],
|
||||
'ConvertItems' => [
|
||||
'namespace' => 'Server',
|
||||
'description' => 'Converts old items to new items with metadata (for migration)',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'playerId', 'type' => 'number', 'description' => 'Player server ID'],
|
||||
['name' => 'items', 'type' => 'table', 'description' => 'Array of items to convert'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean', 'description' => 'Success status'],
|
||||
'lua_example' => "local items = {{name='old_phone', count=1, info={}}}\nexports.ox_inventory:ConvertItems(source, items)",
|
||||
'js_example' => "const items = [{name: 'old_phone', count: 1, info: {}}];\nexports.ox_inventory.ConvertItems(source, items);",
|
||||
],
|
||||
];
|
||||
|
||||
$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-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_inventory server function to look up (e.g., "AddItem", "RemoveItem", "GetItem", "RegisterStash", "SetDurability", "SetMetadata")')
|
||||
->required(),
|
||||
'language' => $schema
|
||||
->string()
|
||||
->enum(['lua', 'js'])
|
||||
->description('The scripting language for code examples')
|
||||
->default('lua'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,213 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\COX\MySQL;
|
||||
|
||||
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('Get information about COX MySQL events and callbacks.')]
|
||||
class GetCOXEventReference extends Tool
|
||||
{
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$eventName = $request->get('event_name');
|
||||
$eventType = $request->get('event_type', 'all');
|
||||
$language = $request->get('language', 'lua');
|
||||
|
||||
if ($eventName) {
|
||||
return $this->getEventInfo($eventName, $language);
|
||||
}
|
||||
|
||||
return $this->listEvents($eventType, $language);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get specific event information.
|
||||
*/
|
||||
protected function getEventInfo(string $eventName, string $language): Response
|
||||
{
|
||||
$events = $this->getCOXEventsDatabase();
|
||||
|
||||
foreach ($events as $event) {
|
||||
if (strtolower($event['name']) === strtolower($eventName)) {
|
||||
return Response::text($this->formatEventInfo($event, $language));
|
||||
}
|
||||
}
|
||||
|
||||
return Response::text(sprintf("COX event '%s' not found in the database.", $eventName));
|
||||
}
|
||||
|
||||
/**
|
||||
* List events by type.
|
||||
*/
|
||||
protected function listEvents(string $type, string $language): Response
|
||||
{
|
||||
$events = $this->getCOXEventsDatabase();
|
||||
|
||||
if ($type !== 'all') {
|
||||
$events = array_filter($events, fn ($e) => $e['type'] === $type);
|
||||
}
|
||||
|
||||
$eventsByType = [];
|
||||
foreach ($events as $event) {
|
||||
$eventsByType[$event['type']][] = $event;
|
||||
}
|
||||
|
||||
return Response::text(
|
||||
view('mcp.cox-event-list', [
|
||||
'eventsByType' => $eventsByType,
|
||||
])->render()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format event information.
|
||||
*/
|
||||
protected function formatEventInfo(array $event, string $language): string
|
||||
{
|
||||
return view('mcp.cox-event-reference', [
|
||||
'event' => $event,
|
||||
'language' => $language,
|
||||
])->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get COX events database.
|
||||
*/
|
||||
protected function getCOXEventsDatabase(): array
|
||||
{
|
||||
return [
|
||||
// Query Events
|
||||
[
|
||||
'name' => 'coxMySQL:queryCompleted',
|
||||
'type' => 'query',
|
||||
'description' => 'Triggered when a query completes (success or failure)',
|
||||
'parameters' => [
|
||||
['name' => 'sql', 'type' => 'string', 'description' => 'The SQL query that was executed'],
|
||||
['name' => 'result', 'type' => 'table|boolean', 'description' => 'Query result or false if failed'],
|
||||
],
|
||||
'lua_example' => "RegisterNetEvent('coxMySQL:queryCompleted', function(sql, result)\n if result then\n print('Query succeeded')\n else\n print('Query failed: ' .. sql)\n end\nend)",
|
||||
'js_example' => "RegisterNetEvent('coxMySQL:queryCompleted', (sql, result) => {\n if (result) {\n console.log('Query succeeded');\n } else {\n console.log('Query failed: ' + sql);\n }\n});",
|
||||
],
|
||||
[
|
||||
'name' => 'coxMySQL:insertCompleted',
|
||||
'type' => 'query',
|
||||
'description' => 'Triggered when an insert query completes',
|
||||
'parameters' => [
|
||||
['name' => 'insertId', 'type' => 'int', 'description' => 'ID of the inserted row'],
|
||||
['name' => 'affectedRows', 'type' => 'int', 'description' => 'Number of rows affected'],
|
||||
],
|
||||
'lua_example' => "RegisterNetEvent('coxMySQL:insertCompleted', function(insertId, affectedRows)\n print('Inserted ID: ' .. insertId .. ', Rows affected: ' .. affectedRows)\nend)",
|
||||
'js_example' => "RegisterNetEvent('coxMySQL:insertCompleted', (insertId, affectedRows) => {\n console.log(`Inserted ID: \${insertId}, Rows affected: \${affectedRows}`);\n});",
|
||||
],
|
||||
|
||||
// Connection Events
|
||||
[
|
||||
'name' => 'coxMySQL:connected',
|
||||
'type' => 'connection',
|
||||
'description' => 'Triggered when the database connection is established',
|
||||
'parameters' => [],
|
||||
'lua_example' => "RegisterNetEvent('coxMySQL:connected', function()\n print('Database connected successfully!')\nend)",
|
||||
'js_example' => "RegisterNetEvent('coxMySQL:connected', () => {\n console.log('Database connected successfully!');\n});",
|
||||
],
|
||||
[
|
||||
'name' => 'coxMySQL:disconnected',
|
||||
'type' => 'connection',
|
||||
'description' => 'Triggered when the database connection closes',
|
||||
'parameters' => [],
|
||||
'lua_example' => "RegisterNetEvent('coxMySQL:disconnected', function()\n print('Database disconnected')\nend)",
|
||||
'js_example' => "RegisterNetEvent('coxMySQL:disconnected', () => {\n console.log('Database disconnected');\n});",
|
||||
],
|
||||
[
|
||||
'name' => 'coxMySQL:connectionError',
|
||||
'type' => 'connection',
|
||||
'description' => 'Triggered when a database connection error occurs',
|
||||
'parameters' => [
|
||||
['name' => 'error', 'type' => 'string', 'description' => 'Error message'],
|
||||
],
|
||||
'lua_example' => "RegisterNetEvent('coxMySQL:connectionError', function(error)\n print('Connection error: ' .. error)\nend)",
|
||||
'js_example' => "RegisterNetEvent('coxMySQL:connectionError', (error) => {\n console.log('Connection error: ' + error);\n});",
|
||||
],
|
||||
|
||||
// Transaction Events
|
||||
[
|
||||
'name' => 'coxMySQL:transactionBegun',
|
||||
'type' => 'transaction',
|
||||
'description' => 'Triggered when a database transaction begins',
|
||||
'parameters' => [],
|
||||
'lua_example' => "RegisterNetEvent('coxMySQL:transactionBegun', function()\n print('Transaction started')\nend)",
|
||||
'js_example' => "RegisterNetEvent('coxMySQL:transactionBegun', () => {\n console.log('Transaction started');\n});",
|
||||
],
|
||||
[
|
||||
'name' => 'coxMySQL:transactionCommitted',
|
||||
'type' => 'transaction',
|
||||
'description' => 'Triggered when a transaction is successfully committed',
|
||||
'parameters' => [],
|
||||
'lua_example' => "RegisterNetEvent('coxMySQL:transactionCommitted', function()\n print('Transaction committed successfully')\nend)",
|
||||
'js_example' => "RegisterNetEvent('coxMySQL:transactionCommitted', () => {\n console.log('Transaction committed successfully');\n});",
|
||||
],
|
||||
[
|
||||
'name' => 'coxMySQL:transactionRolledBack',
|
||||
'type' => 'transaction',
|
||||
'description' => 'Triggered when a transaction is rolled back',
|
||||
'parameters' => [],
|
||||
'lua_example' => "RegisterNetEvent('coxMySQL:transactionRolledBack', function()\n print('Transaction rolled back')\nend)",
|
||||
'js_example' => "RegisterNetEvent('coxMySQL:transactionRolledBack', () => {\n console.log('Transaction rolled back');\n});",
|
||||
],
|
||||
|
||||
// Error Events
|
||||
[
|
||||
'name' => 'coxMySQL:queryError',
|
||||
'type' => 'error',
|
||||
'description' => 'Triggered when a query execution fails',
|
||||
'parameters' => [
|
||||
['name' => 'sql', 'type' => 'string', 'description' => 'The SQL that failed'],
|
||||
['name' => 'errorMessage', 'type' => 'string', 'description' => 'MySQL error message'],
|
||||
],
|
||||
'lua_example' => "RegisterNetEvent('coxMySQL:queryError', function(sql, errorMessage)\n print('Query error: ' .. errorMessage)\n print('Failed query: ' .. sql)\nend)",
|
||||
'js_example' => "RegisterNetEvent('coxMySQL:queryError', (sql, errorMessage) => {\n console.log('Query error: ' + errorMessage);\n console.log('Failed query: ' + sql);\n});",
|
||||
],
|
||||
[
|
||||
'name' => 'coxMySQL:slowQuery',
|
||||
'type' => 'error',
|
||||
'description' => 'Triggered when a query exceeds the configured timeout',
|
||||
'parameters' => [
|
||||
['name' => 'sql', 'type' => 'string', 'description' => 'The slow SQL query'],
|
||||
['name' => 'duration', 'type' => 'float', 'description' => 'Query duration in milliseconds'],
|
||||
],
|
||||
'lua_example' => "RegisterNetEvent('coxMySQL:slowQuery', function(sql, duration)\n print('Slow query (' .. duration .. 'ms): ' .. sql)\nend)",
|
||||
'js_example' => "RegisterNetEvent('coxMySQL:slowQuery', (sql, duration) => {\n console.log(`Slow query (\${duration}ms): \${sql}`);\n});",
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* 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('Specific COX event name to look up (optional, leave empty to list all events)'),
|
||||
'event_type' => $schema
|
||||
->string()
|
||||
->enum(['all', 'query', 'connection', 'transaction', 'error'])
|
||||
->description('Filter events by type')
|
||||
->default('all'),
|
||||
'language' => $schema
|
||||
->string()
|
||||
->enum(['lua', 'js'])
|
||||
->description('The scripting language for code examples')
|
||||
->default('lua'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\COX\MySQL;
|
||||
|
||||
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 COX MySQL functions and methods by name. Returns function signature, parameters, return type, and usage examples.')]
|
||||
class GetCOXFunction 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("COX function '%s' not found. Check COX documentation at https://coxdocs.dev/", $functionName));
|
||||
}
|
||||
|
||||
$output = $this->formatFunctionInfo($function, $language);
|
||||
|
||||
return Response::text($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a COX function.
|
||||
*/
|
||||
protected function findFunction(string $name): ?array
|
||||
{
|
||||
$functions = [
|
||||
// Query Methods
|
||||
'MySQL.query' => [
|
||||
'namespace' => 'Query',
|
||||
'description' => 'Execute a MySQL query with optional parameters. When selecting data, returns all matching rows; otherwise returns data like insertId, affectedRows, etc.',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'sql', 'type' => 'string', 'description' => 'SQL query with ? placeholders for prepared statements'],
|
||||
['name' => 'params', 'type' => 'table|nil', 'description' => 'Array of parameters to bind to placeholders'],
|
||||
['name' => 'callback', 'type' => 'function|nil', 'description' => 'Optional callback function that receives the query result'],
|
||||
],
|
||||
'returns' => ['type' => 'table|nil', 'description' => 'Query result (rows for SELECT, or metadata for INSERT/UPDATE/DELETE)'],
|
||||
'lua_example' => "MySQL.query('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', {\n identifier\n}, function(response)\n if response then\n for i = 1, #response do\n local row = response[i]\n print(row.firstname, row.lastname)\n end\n end\nend)",
|
||||
'js_example' => "MySQL.query('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', [\n identifier\n], (response) => {\n if (response) {\n response.forEach(row => {\n console.log(row.firstname, row.lastname);\n });\n }\n});",
|
||||
],
|
||||
'MySQL.insert' => [
|
||||
'namespace' => 'Query',
|
||||
'description' => 'Insert a row into the database and get the insert ID',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'sql', 'type' => 'string', 'description' => 'INSERT SQL query with ? placeholders'],
|
||||
['name' => 'params', 'type' => 'table|nil', 'description' => 'Array of parameters to bind to placeholders'],
|
||||
['name' => 'callback', 'type' => 'function|nil', 'description' => 'Optional callback function that receives the insert ID'],
|
||||
],
|
||||
'returns' => ['type' => 'number', 'description' => 'Insert ID (in callback mode) or awaitable insert ID (in promise mode)'],
|
||||
'lua_example' => "MySQL.insert('INSERT INTO `users` (identifier, firstname, lastname) VALUES (?, ?, ?)', {\n identifier, firstName, lastName\n}, function(id)\n print('Inserted with ID: ' .. id)\nend)",
|
||||
'js_example' => "MySQL.insert('INSERT INTO `users` (identifier, firstname, lastname) VALUES (?, ?, ?)', [\n identifier, firstName, lastName\n], (id) => {\n console.log('Inserted with ID: ' + id);\n});",
|
||||
],
|
||||
'MySQL.update' => [
|
||||
'namespace' => 'Query',
|
||||
'description' => 'Update rows in the database and get the number of affected rows',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'sql', 'type' => 'string', 'description' => 'UPDATE SQL query with ? placeholders'],
|
||||
['name' => 'params', 'type' => 'table|nil', 'description' => 'Array of parameters to bind to placeholders'],
|
||||
['name' => 'callback', 'type' => 'function|nil', 'description' => 'Optional callback function that receives affected rows count'],
|
||||
],
|
||||
'returns' => ['type' => 'number', 'description' => 'Number of affected rows (in callback mode) or awaitable affected rows (in promise mode)'],
|
||||
'lua_example' => "MySQL.update('UPDATE users SET firstname = ? WHERE identifier = ?', {\n newName, identifier\n}, function(affectedRows)\n print('Updated ' .. affectedRows .. ' rows')\nend)",
|
||||
'js_example' => "MySQL.update('UPDATE users SET firstname = ? WHERE identifier = ?', [\n newName, identifier\n], (affectedRows) => {\n console.log(`Updated \${affectedRows} rows`);\n});",
|
||||
],
|
||||
'MySQL.scalar' => [
|
||||
'namespace' => 'Query',
|
||||
'description' => 'Returns the first column for a single row',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'sql', 'type' => 'string', 'description' => 'SQL query with ? placeholders'],
|
||||
['name' => 'params', 'type' => 'table|nil', 'description' => 'Query parameters'],
|
||||
['name' => 'callback', 'type' => 'function', 'description' => 'Callback that receives the scalar value'],
|
||||
],
|
||||
'returns' => ['type' => 'any', 'description' => 'Single value from the first column of the first row'],
|
||||
'lua_example' => "MySQL.scalar('SELECT `firstname` FROM `users` WHERE `identifier` = ? LIMIT 1', {\n identifier\n}, function(firstName)\n print(firstName)\nend)",
|
||||
'js_example' => "MySQL.scalar('SELECT `firstname` FROM `users` WHERE `identifier` = ? LIMIT 1', [\n identifier\n], (firstName) => {\n console.log(firstName);\n});",
|
||||
],
|
||||
'MySQL.single' => [
|
||||
'namespace' => 'Query',
|
||||
'description' => 'Returns all selected columns for a single row',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'sql', 'type' => 'string', 'description' => 'SQL query with ? placeholders'],
|
||||
['name' => 'params', 'type' => 'table|nil', 'description' => 'Query parameters'],
|
||||
['name' => 'callback', 'type' => 'function', 'description' => 'Callback that receives the row data'],
|
||||
],
|
||||
'returns' => ['type' => 'table|nil', 'description' => 'Single row object or nil if no results'],
|
||||
'lua_example' => "MySQL.single('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ? LIMIT 1', {\n identifier\n}, function(row)\n if not row then return end\n print(row.firstname, row.lastname)\nend)",
|
||||
'js_example' => "MySQL.single('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ? LIMIT 1', [\n identifier\n], (row) => {\n if (!row) return;\n console.log(row.firstname, row.lastname);\n});",
|
||||
],
|
||||
|
||||
// Transaction Methods
|
||||
'MySQL.transaction' => [
|
||||
'namespace' => 'Transaction',
|
||||
'description' => 'Execute multiple queries as a transaction. If one fails, none are committed. Returns boolean indicating success.',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'queries', 'type' => 'table', 'description' => 'Array of query objects with query and values/parameters'],
|
||||
['name' => 'values', 'type' => 'table|function|nil', 'description' => 'Shared parameters for all queries (optional) or callback function'],
|
||||
['name' => 'callback', 'type' => 'function|nil', 'description' => 'Optional callback that receives boolean success result'],
|
||||
],
|
||||
'returns' => ['type' => 'boolean', 'description' => 'True if transaction succeeded, false otherwise'],
|
||||
'lua_example' => "-- Specific format (unique params per query)\nlocal queries = {\n { query = 'INSERT INTO `test` (id) VALUES (?)', values = { 1 } },\n { query = 'INSERT INTO `test` (id, name) VALUES (?, ?)', values = { 2, 'bob' } },\n}\nMySQL.transaction(queries, function(success)\n print(success)\nend)",
|
||||
'js_example' => "// Specific format (unique params per query)\nconst queries = [\n { query: 'INSERT INTO `test` (id) VALUES (?)', values: [1] },\n { query: 'INSERT INTO `test` (id, name) VALUES (?, ?)', values: [2, 'bob'] },\n];\nMySQL.transaction(queries, (success) => {\n console.log(success);\n});",
|
||||
],
|
||||
|
||||
// Prepared Statements
|
||||
'MySQL.prepare' => [
|
||||
'namespace' => 'Prepared',
|
||||
'description' => 'Execute frequently called queries faster. Accepts multiple sets of parameters. Only supports ? value placeholders. Return format matches query/single/scalar based on result shape.',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'sql', 'type' => 'string', 'description' => 'SQL with ? value placeholders (no ?? column or named placeholders)'],
|
||||
['name' => 'params', 'type' => 'table', 'description' => 'Parameters to bind'],
|
||||
['name' => 'callback', 'type' => 'function', 'description' => 'Callback that receives results'],
|
||||
],
|
||||
'returns' => ['type' => 'any', 'description' => 'Returns column, row, or array of rows depending on SELECT result shape'],
|
||||
'lua_example' => "MySQL.prepare('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', {\n identifier\n}, function(response)\n print(json.encode(response, { indent = true, sort_keys = true }))\nend)",
|
||||
'js_example' => "MySQL.prepare('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', [\n identifier\n], (response) => {\n console.log(JSON.stringify(response, null, 2));\n});",
|
||||
],
|
||||
'MySQL.rawExecute' => [
|
||||
'namespace' => 'Prepared',
|
||||
'description' => 'Execute frequently called queries faster. Unlike prepare, SELECT always returns array of rows. Only supports ? value placeholders. Date and TINYINT/BIT types are not converted.',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'sql', 'type' => 'string', 'description' => 'SQL with ? value placeholders only'],
|
||||
['name' => 'params', 'type' => 'table', 'description' => 'Parameters to bind'],
|
||||
['name' => 'callback', 'type' => 'function', 'description' => 'Callback that receives results'],
|
||||
],
|
||||
'returns' => ['type' => 'table', 'description' => 'Always returns array of rows for SELECT'],
|
||||
'lua_example' => "MySQL.rawExecute('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', {\n identifier\n}, function(response)\n print(json.encode(response, { indent = true, sort_keys = true }))\nend)",
|
||||
'js_example' => "MySQL.rawExecute('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', [\n identifier\n], (response) => {\n console.log(JSON.stringify(response, null, 2));\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-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 COX function to look up (e.g., "MySQL.query", "MySQL.insert", "MySQL.transaction.begin")')
|
||||
->required(),
|
||||
'language' => $schema
|
||||
->string()
|
||||
->enum(['lua', 'js'])
|
||||
->description('The scripting language for code examples')
|
||||
->default('lua'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user