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:
Adrian Mejias committed 2026-03-01 14:30:24 -06:00
1 parent a2591c2209
commit 4a4d9822e7
38 files changed
+2248 -818

No files matched your search

@@ -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'),
];
}
}
+191
View File
@@ -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'),
];
}
}