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,181 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\FiveM\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('Get information about FiveM client-side events including framework events (ESX, QBCore).')]
|
||||
class GetEventClientReference 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->getEventsDatabase();
|
||||
|
||||
foreach ($events as $event) {
|
||||
if (strtolower($event['name']) === strtolower($eventName)) {
|
||||
return Response::text($this->formatEventInfo($event, $language));
|
||||
}
|
||||
}
|
||||
|
||||
return Response::text(sprintf("Client event '%s' not found in the database.", $eventName));
|
||||
}
|
||||
|
||||
/**
|
||||
* List events by type.
|
||||
*/
|
||||
protected function listEvents(string $type, string $language): Response
|
||||
{
|
||||
$events = $this->getEventsDatabase();
|
||||
|
||||
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.event-list', [
|
||||
'eventsByType' => $eventsByType,
|
||||
])->render()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format event information.
|
||||
*/
|
||||
protected function formatEventInfo(array $event, string $language): string
|
||||
{
|
||||
return view('mcp.event-reference', [
|
||||
'event' => $event,
|
||||
'language' => $language,
|
||||
])->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get client events database.
|
||||
*/
|
||||
protected function getEventsDatabase(): array
|
||||
{
|
||||
return [
|
||||
// Core FiveM Client Events
|
||||
[
|
||||
'name' => 'onResourceStart',
|
||||
'type' => 'core',
|
||||
'side' => 'client',
|
||||
'description' => 'Triggered when a resource starts (client-side)',
|
||||
'parameters' => [
|
||||
['name' => 'resourceName', 'type' => 'string', 'description' => 'The name of the resource that started'],
|
||||
],
|
||||
'lua_example' => "AddEventHandler('onResourceStart', function(resourceName)\n if resourceName == GetCurrentResourceName() then\n print('Resource started on client!')\n end\nend)",
|
||||
'js_example' => "on('onResourceStart', (resourceName) => {\n if (resourceName === GetCurrentResourceName()) {\n console.log('Resource started on client!');\n }\n});",
|
||||
'documentation' => 'https://docs.fivem.net/docs/scripting-reference/events/list/onResourceStart/',
|
||||
],
|
||||
[
|
||||
'name' => 'onResourceStop',
|
||||
'type' => 'core',
|
||||
'side' => 'client',
|
||||
'description' => 'Triggered when a resource stops (client-side)',
|
||||
'parameters' => [
|
||||
['name' => 'resourceName', 'type' => 'string', 'description' => 'The name of the resource that stopped'],
|
||||
],
|
||||
'lua_example' => "AddEventHandler('onResourceStop', function(resourceName)\n if resourceName == GetCurrentResourceName() then\n print('Resource stopped on client!')\n end\nend)",
|
||||
'js_example' => "on('onResourceStop', (resourceName) => {\n if (resourceName === GetCurrentResourceName()) {\n console.log('Resource stopped on client!');\n }\n});",
|
||||
'documentation' => 'https://docs.fivem.net/docs/scripting-reference/events/list/onResourceStop/',
|
||||
],
|
||||
// ESX Client Events
|
||||
[
|
||||
'name' => 'esx:playerLoaded',
|
||||
'type' => 'esx',
|
||||
'side' => 'client',
|
||||
'description' => 'Triggered when ESX player data is loaded on client',
|
||||
'parameters' => [
|
||||
['name' => 'xPlayer', 'type' => 'table', 'description' => 'ESX player object'],
|
||||
],
|
||||
'lua_example' => "RegisterNetEvent('esx:playerLoaded', function(xPlayer)\n ESX.PlayerData = xPlayer\n -- Player is loaded\nend)",
|
||||
'js_example' => "RegisterNetEvent('esx:playerLoaded', (xPlayer) => {\n ESX.PlayerData = xPlayer;\n // Player is loaded\n});",
|
||||
],
|
||||
[
|
||||
'name' => 'esx:setJob',
|
||||
'type' => 'esx',
|
||||
'side' => 'client',
|
||||
'description' => 'Triggered when player job changes',
|
||||
'parameters' => [
|
||||
['name' => 'job', 'type' => 'table', 'description' => 'New job object'],
|
||||
],
|
||||
'lua_example' => "RegisterNetEvent('esx:setJob', function(job)\n ESX.PlayerData.job = job\n print('Job changed to: ' .. job.name)\nend)",
|
||||
'js_example' => "RegisterNetEvent('esx:setJob', (job) => {\n ESX.PlayerData.job = job;\n console.log(`Job changed to: \${job.name}`);\n});",
|
||||
],
|
||||
// QBCore Client Events
|
||||
[
|
||||
'name' => 'QBCore:Client:OnPlayerLoaded',
|
||||
'type' => 'qbcore',
|
||||
'side' => 'client',
|
||||
'description' => 'Triggered when QBCore player data is loaded on client',
|
||||
'parameters' => [],
|
||||
'lua_example' => "RegisterNetEvent('QBCore:Client:OnPlayerLoaded', function()\n local PlayerData = QBCore.Functions.GetPlayerData()\n -- Player is loaded\nend)",
|
||||
'js_example' => "RegisterNetEvent('QBCore:Client:OnPlayerLoaded', () => {\n const PlayerData = QBCore.Functions.GetPlayerData();\n // Player is loaded\n});",
|
||||
],
|
||||
[
|
||||
'name' => 'QBCore:Client:OnJobUpdate',
|
||||
'type' => 'qbcore',
|
||||
'side' => 'client',
|
||||
'description' => 'Triggered when player job changes in QBCore',
|
||||
'parameters' => [
|
||||
['name' => 'job', 'type' => 'table', 'description' => 'New job object'],
|
||||
],
|
||||
'lua_example' => "RegisterNetEvent('QBCore:Client:OnJobUpdate', function(job)\n PlayerData.job = job\n print('Job changed to: ' .. job.name)\nend)",
|
||||
'js_example' => "RegisterNetEvent('QBCore:Client:OnJobUpdate', (job) => {\n PlayerData.job = job;\n console.log(`Job changed to: \${job.name}`);\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 client event name to look up (optional, leave empty to list all events)'),
|
||||
'event_type' => $schema
|
||||
->string()
|
||||
->enum(['all', 'core', 'esx', 'qbcore'])
|
||||
->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,221 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\FiveM\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 GTA5/FiveM client-side native functions by name. Returns function signature, parameters, return type, and usage examples.')]
|
||||
class GetNativeClientFunction extends Tool
|
||||
{
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$functionName = $request->get('function_name');
|
||||
$language = $request->get('language', 'lua');
|
||||
|
||||
$native = $this->findNative($functionName);
|
||||
|
||||
if (! $native) {
|
||||
return Response::text(sprintf("Client native function '%s' not found. Try searching at https://docs.fivem.net/natives/", $functionName));
|
||||
}
|
||||
|
||||
$output = $this->formatNativeInfo($native, $language);
|
||||
|
||||
return Response::text($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a client native function.
|
||||
*/
|
||||
protected function findNative(string $name): ?array
|
||||
{
|
||||
// Client-side only FiveM natives
|
||||
$natives = [
|
||||
// Player/Ped natives
|
||||
'GetPlayerPed' => [
|
||||
'namespace' => 'PLAYER',
|
||||
'description' => 'Gets the local or specified player\'s ped handle',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'playerId', 'type' => 'int', 'description' => 'The player ID, or -1 for local player'],
|
||||
],
|
||||
'returns' => ['type' => 'int', 'description' => 'The player ped handle'],
|
||||
'lua_example' => 'local playerPed = GetPlayerPed(-1)',
|
||||
'js_example' => 'const playerPed = GetPlayerPed(-1);',
|
||||
],
|
||||
'PlayerPedId' => [
|
||||
'namespace' => 'PLAYER',
|
||||
'description' => 'Returns the ped ID of the local player',
|
||||
'side' => 'client',
|
||||
'parameters' => [],
|
||||
'returns' => ['type' => 'int', 'description' => 'The local player ped ID'],
|
||||
'lua_example' => 'local playerPed = PlayerPedId()',
|
||||
'js_example' => 'const playerPed = PlayerPedId();',
|
||||
],
|
||||
'GetPlayerName' => [
|
||||
'namespace' => 'PLAYER',
|
||||
'description' => 'Returns the name of a player (client-side lookup)',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'playerId', 'type' => 'int', 'description' => 'The player ID'],
|
||||
],
|
||||
'returns' => ['type' => 'string', 'description' => 'The player name'],
|
||||
'lua_example' => 'local name = GetPlayerName(PlayerId())',
|
||||
'js_example' => 'const name = GetPlayerName(PlayerId());',
|
||||
],
|
||||
'PlayerId' => [
|
||||
'namespace' => 'PLAYER',
|
||||
'description' => 'Gets the local player ID on client',
|
||||
'side' => 'client',
|
||||
'parameters' => [],
|
||||
'returns' => ['type' => 'int', 'description' => 'The local player ID'],
|
||||
'lua_example' => 'local playerId = PlayerId()',
|
||||
'js_example' => 'const playerId = PlayerId();',
|
||||
],
|
||||
'SetEntityCoords' => [
|
||||
'namespace' => 'ENTITY',
|
||||
'description' => 'Sets the coordinates of an entity (client-side)',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'entity', 'type' => 'int', 'description' => 'The entity handle'],
|
||||
['name' => 'x', 'type' => 'float', 'description' => 'X coordinate'],
|
||||
['name' => 'y', 'type' => 'float', 'description' => 'Y coordinate'],
|
||||
['name' => 'z', 'type' => 'float', 'description' => 'Z coordinate'],
|
||||
['name' => 'alive', 'type' => 'boolean', 'description' => 'Keep entity alive during teleport'],
|
||||
['name' => 'deadFlag', 'type' => 'boolean', 'description' => 'Teleport even if dead'],
|
||||
['name' => 'ragdollFlag', 'type' => 'boolean', 'description' => 'Teleport even in ragdoll'],
|
||||
['name' => 'clearArea', 'type' => 'boolean', 'description' => 'Clear area at destination'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => 'SetEntityCoords(PlayerPedId(), 0.0, 0.0, 72.0, true, false, false, true)',
|
||||
'js_example' => 'SetEntityCoords(PlayerPedId(), 0.0, 0.0, 72.0, true, false, false, true);',
|
||||
],
|
||||
'GetEntityCoords' => [
|
||||
'namespace' => 'ENTITY',
|
||||
'description' => 'Gets the coordinates of an entity',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'entity', 'type' => 'int', 'description' => 'The entity handle'],
|
||||
['name' => 'alive', 'type' => 'boolean', 'description' => 'Whether to get alive coordinates only'],
|
||||
],
|
||||
'returns' => ['type' => 'vector3', 'description' => 'The entity coordinates'],
|
||||
'lua_example' => 'local coords = GetEntityCoords(PlayerPedId(), true)',
|
||||
'js_example' => 'const coords = GetEntityCoords(PlayerPedId(), true);',
|
||||
],
|
||||
'DeleteEntity' => [
|
||||
'namespace' => 'ENTITY',
|
||||
'description' => 'Deletes an entity (network delete for networked entities)',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'entity', 'type' => 'int', 'description' => 'The entity handle to delete'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => 'DeleteEntity(ped)',
|
||||
'js_example' => 'DeleteEntity(ped);',
|
||||
],
|
||||
'TriggerServerEvent' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Triggers an event on the server from client',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'eventName', 'type' => 'string', 'description' => 'The name of the event'],
|
||||
['name' => '...args', 'type' => 'any', 'description' => 'Event arguments'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "TriggerServerEvent('myResource:serverEvent', arg1, arg2)",
|
||||
'js_example' => "TriggerServerEvent('myResource:serverEvent', arg1, arg2);",
|
||||
],
|
||||
'RegisterNetEvent' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Registers a network event handler (client-side)',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'eventName', 'type' => 'string', 'description' => 'The name of the event'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "RegisterNetEvent('myResource:clientEvent')\nAddEventHandler('myResource:clientEvent', function(param1, param2)\n -- Handle event\nend)",
|
||||
'js_example' => "RegisterNetEvent('myResource:clientEvent');\nAddEventHandler('myResource:clientEvent', (param1, param2) => {\n // Handle event\n});",
|
||||
],
|
||||
'AddEventHandler' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Adds an event handler for local events',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'eventName', 'type' => 'string', 'description' => 'The name of the event'],
|
||||
['name' => 'callback', 'type' => 'function', 'description' => 'The handler function'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "AddEventHandler('onResourceStart', function(resourceName)\n if resourceName == GetCurrentResourceName() then\n print('Resource started!')\n end\nend)",
|
||||
'js_example' => "AddEventHandler('onResourceStart', (resourceName) => {\n if (resourceName === GetCurrentResourceName()) {\n console.log('Resource started!');\n }\n});",
|
||||
],
|
||||
'GetCurrentResourceName' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Returns the name of the currently executing resource',
|
||||
'side' => 'client',
|
||||
'parameters' => [],
|
||||
'returns' => ['type' => 'string', 'description' => 'The resource name'],
|
||||
'lua_example' => "local resName = GetCurrentResourceName()\nprint('Current resource: ' .. resName)",
|
||||
'js_example' => "const resName = GetCurrentResourceName();\nconsole.log('Current resource: ' + resName);",
|
||||
],
|
||||
'TriggerEvent' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Triggers a local event on the current client',
|
||||
'side' => 'client',
|
||||
'parameters' => [
|
||||
['name' => 'eventName', 'type' => 'string', 'description' => 'The name of the event'],
|
||||
['name' => '...args', 'type' => 'any', 'description' => 'Event arguments'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "TriggerEvent('myEvent', 'arg1', 'arg2')",
|
||||
'js_example' => "TriggerEvent('myEvent', 'arg1', 'arg2');",
|
||||
],
|
||||
];
|
||||
|
||||
$nameLower = strtolower($name);
|
||||
|
||||
foreach ($natives as $nativeName => $nativeData) {
|
||||
if (strtolower($nativeName) === $nameLower) {
|
||||
return array_merge(['name' => $nativeName], $nativeData);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format native function info.
|
||||
*/
|
||||
protected function formatNativeInfo(array $native, string $language): string
|
||||
{
|
||||
return view('mcp.native-function', [
|
||||
'native' => $native,
|
||||
'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 client-side native function to look up (e.g., "PlayerPedId", "SetEntityCoords", "TriggerServerEvent")')
|
||||
->required(),
|
||||
'language' => $schema
|
||||
->string()
|
||||
->enum(['lua', 'js'])
|
||||
->description('The scripting language for code examples')
|
||||
->default('lua'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\FiveM;
|
||||
|
||||
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('Generate a fxmanifest.lua file for a FiveM resource with the specified configuration options.')]
|
||||
class GenerateManifest extends Tool
|
||||
{
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$resourceName = $request->get('resource_name');
|
||||
$author = $request->get('author', 'Unknown');
|
||||
$description = $request->get('description', 'A FiveM resource');
|
||||
$version = $request->get('version', '1.0.0');
|
||||
$scriptType = $request->get('script_type', 'lua');
|
||||
$includeClient = $request->get('include_client', true);
|
||||
$includeServer = $request->get('include_server', true);
|
||||
$framework = $request->get('framework', 'standalone');
|
||||
|
||||
return Response::text(
|
||||
view('mcp.templates.fxmanifest', [
|
||||
'resourceName' => $resourceName,
|
||||
'author' => $author,
|
||||
'description' => $description,
|
||||
'version' => $version,
|
||||
'scriptExt' => $scriptType === 'js' ? 'js' : 'lua',
|
||||
'includeClient' => $includeClient,
|
||||
'includeServer' => $includeServer,
|
||||
'framework' => $framework,
|
||||
])->render()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tool's input schema.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\JsonSchema\JsonSchema>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'resource_name' => $schema
|
||||
->string()
|
||||
->description('The name of the FiveM resource')
|
||||
->required(),
|
||||
'author' => $schema
|
||||
->string()
|
||||
->description('The author name')
|
||||
->default('Unknown'),
|
||||
'description' => $schema
|
||||
->string()
|
||||
->description('Resource description')
|
||||
->default('A FiveM resource'),
|
||||
'version' => $schema
|
||||
->string()
|
||||
->description('Resource version (e.g., "1.0.0")')
|
||||
->default('1.0.0'),
|
||||
'script_type' => $schema
|
||||
->string()
|
||||
->enum(['lua', 'js'])
|
||||
->description('Scripting language (Lua or JavaScript)')
|
||||
->default('lua'),
|
||||
'include_client' => $schema
|
||||
->boolean()
|
||||
->description('Include client-side scripts')
|
||||
->default(true),
|
||||
'include_server' => $schema
|
||||
->boolean()
|
||||
->description('Include server-side scripts')
|
||||
->default(true),
|
||||
'framework' => $schema
|
||||
->string()
|
||||
->enum(['standalone', 'esx', 'qbcore'])
|
||||
->description('Framework type (standalone, ESX, or QBCore)')
|
||||
->default('standalone'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\FiveM;
|
||||
|
||||
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('Generate boilerplate code for a FiveM resource including client, server, config, and manifest files.')]
|
||||
class GenerateResourceBoilerplate extends Tool
|
||||
{
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$resourceName = $request->get('resource_name');
|
||||
$framework = $request->get('framework', 'standalone');
|
||||
$scriptType = $request->get('script_type', 'lua');
|
||||
$includeNUI = $request->get('include_nui', false);
|
||||
|
||||
$files = $this->generateBoilerplate([
|
||||
'resource_name' => $resourceName,
|
||||
'framework' => $framework,
|
||||
'script_type' => $scriptType,
|
||||
'include_nui' => $includeNUI,
|
||||
]);
|
||||
|
||||
return Response::text(
|
||||
view('mcp.resource-boilerplate', [
|
||||
'resourceName' => $resourceName,
|
||||
'files' => $files,
|
||||
])->render()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate boilerplate files.
|
||||
*/
|
||||
protected function generateBoilerplate(array $config): array
|
||||
{
|
||||
$files = [];
|
||||
$ext = $config['script_type'] === 'js' ? 'js' : 'lua';
|
||||
|
||||
// Config file
|
||||
$files[sprintf('config.%s', $ext)] = $this->generateConfig($config);
|
||||
|
||||
// Client file
|
||||
$files[sprintf('client/main.%s', $ext)] = $this->generateClient($config);
|
||||
|
||||
// Server file
|
||||
$files[sprintf('server/main.%s', $ext)] = $this->generateServer($config);
|
||||
|
||||
// NUI files if requested
|
||||
if ($config['include_nui']) {
|
||||
$files['html/index.html'] = $this->generateNUIHTML();
|
||||
$files['html/style.css'] = $this->generateNUICSS();
|
||||
$files[sprintf('html/script.%s', $ext)] = $this->generateNUIScript($config);
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate config file.
|
||||
*/
|
||||
protected function generateConfig(array $config): string
|
||||
{
|
||||
$template = $config['script_type'] === 'js' ? 'config-js' : 'config-lua';
|
||||
|
||||
return view(sprintf('mcp.templates.%s', $template))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate client file.
|
||||
*/
|
||||
protected function generateClient(array $config): string
|
||||
{
|
||||
$template = $config['script_type'] === 'js' ? 'client-js' : 'client-lua';
|
||||
|
||||
return view(sprintf('mcp.templates.%s', $template), [
|
||||
'framework' => $config['framework'],
|
||||
])->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate server file.
|
||||
*/
|
||||
protected function generateServer(array $config): string
|
||||
{
|
||||
$template = $config['script_type'] === 'js' ? 'server-js' : 'server-lua';
|
||||
|
||||
return view(sprintf('mcp.templates.%s', $template), [
|
||||
'framework' => $config['framework'],
|
||||
])->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate NUI HTML.
|
||||
*/
|
||||
protected function generateNUIHTML(): string
|
||||
{
|
||||
return view('mcp.templates.nui-html')->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate NUI CSS.
|
||||
*/
|
||||
protected function generateNUICSS(): string
|
||||
{
|
||||
return view('mcp.templates.nui-css')->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate NUI script.
|
||||
*/
|
||||
protected function generateNUIScript(array $config): string
|
||||
{
|
||||
$template = $config['script_type'] === 'js' ? 'nui-script-js' : 'nui-script-lua';
|
||||
|
||||
return view(sprintf('mcp.templates.%s', $template))->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tool's input schema.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\JsonSchema\JsonSchema>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'resource_name' => $schema
|
||||
->string()
|
||||
->description('The name of the resource to generate boilerplate for')
|
||||
->required(),
|
||||
'framework' => $schema
|
||||
->string()
|
||||
->enum(['standalone', 'esx', 'qbcore'])
|
||||
->description('Framework type (standalone, ESX, or QBCore)')
|
||||
->default('standalone'),
|
||||
'script_type' => $schema
|
||||
->string()
|
||||
->enum(['lua', 'js'])
|
||||
->description('Scripting language (Lua or JavaScript)')
|
||||
->default('lua'),
|
||||
'include_nui' => $schema
|
||||
->boolean()
|
||||
->description('Include NUI (UI) files')
|
||||
->default(false),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\FiveM;
|
||||
|
||||
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('Search FiveM documentation for specific topics, concepts, or features. Returns relevant documentation URLs and summaries.')]
|
||||
class SearchFiveMDocs extends Tool
|
||||
{
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$query = $request->get('query');
|
||||
$category = $request->get('category', 'all');
|
||||
|
||||
$results = $this->searchDocs($query, $category);
|
||||
|
||||
if (empty($results)) {
|
||||
return Response::text(sprintf('No documentation found for query: %s', $query));
|
||||
}
|
||||
|
||||
return Response::text(
|
||||
view('mcp.search-results', [
|
||||
'query' => $query,
|
||||
'results' => $results,
|
||||
])->render()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Search the FiveM documentation.
|
||||
*/
|
||||
protected function searchDocs(string $query, string $category): array
|
||||
{
|
||||
$baseUrl = 'https://docs.fivem.net/docs/';
|
||||
|
||||
// Common documentation pages organized by category
|
||||
$docs = [
|
||||
'scripting' => [
|
||||
[
|
||||
'title' => 'Scripting Introduction',
|
||||
'url' => sprintf('%sscripting-manual/introduction/', $baseUrl),
|
||||
'description' => 'Learn the basics of FiveM scripting with Lua and JavaScript',
|
||||
'keywords' => ['script', 'introduction', 'basics', 'getting started', 'lua', 'javascript'],
|
||||
],
|
||||
[
|
||||
'title' => 'Client Functions',
|
||||
'url' => sprintf('%sscripting-reference/client-functions/', $baseUrl),
|
||||
'description' => 'Client-side native functions for game interaction',
|
||||
'keywords' => ['client', 'native', 'function', 'game', 'player'],
|
||||
],
|
||||
[
|
||||
'title' => 'Server Functions',
|
||||
'url' => sprintf('%sscripting-reference/server-functions/', $baseUrl),
|
||||
'description' => 'Server-side functions for player management and game logic',
|
||||
'keywords' => ['server', 'function', 'player', 'management'],
|
||||
],
|
||||
[
|
||||
'title' => 'Resource Manifest',
|
||||
'url' => sprintf('%sscripting-reference/resource-manifest/resource-manifest/', $baseUrl),
|
||||
'description' => 'Configure your resource with fxmanifest.lua',
|
||||
'keywords' => ['manifest', 'fxmanifest', 'resource', 'config', 'configuration'],
|
||||
],
|
||||
],
|
||||
'natives' => [
|
||||
[
|
||||
'title' => 'Native Reference',
|
||||
'url' => sprintf('%snatives/', $baseUrl),
|
||||
'description' => 'Complete reference of GTA5 native functions',
|
||||
'keywords' => ['native', 'reference', 'gta', 'function'],
|
||||
],
|
||||
[
|
||||
'title' => 'CFX Natives',
|
||||
'url' => sprintf('%snatives/?n_CFX', $baseUrl),
|
||||
'description' => 'FiveM-specific native functions (CFX namespace)',
|
||||
'keywords' => ['cfx', 'native', 'fivem', 'custom'],
|
||||
],
|
||||
],
|
||||
'networking' => [
|
||||
[
|
||||
'title' => 'Network Events',
|
||||
'url' => sprintf('%sscripting-manual/networking/events/', $baseUrl),
|
||||
'description' => 'Client-server communication using events',
|
||||
'keywords' => ['event', 'network', 'trigger', 'client', 'server', 'communication'],
|
||||
],
|
||||
[
|
||||
'title' => 'State Bags',
|
||||
'url' => sprintf('%sscripting-manual/networking/state-bags/', $baseUrl),
|
||||
'description' => 'Synchronized state management across clients and server',
|
||||
'keywords' => ['state', 'bag', 'sync', 'data', 'shared'],
|
||||
],
|
||||
],
|
||||
'resources' => [
|
||||
[
|
||||
'title' => 'Creating Resources',
|
||||
'url' => sprintf('%sscripting-manual/introduction/creating-your-first-script/', $baseUrl),
|
||||
'description' => 'Step-by-step guide to creating your first FiveM resource',
|
||||
'keywords' => ['create', 'resource', 'first', 'tutorial', 'guide'],
|
||||
],
|
||||
[
|
||||
'title' => 'Resource Structure',
|
||||
'url' => sprintf('%sscripting-manual/introduction/about-resources/', $baseUrl),
|
||||
'description' => 'Understanding FiveM resource folder structure and organization',
|
||||
'keywords' => ['structure', 'folder', 'organization', 'resource', 'files'],
|
||||
],
|
||||
],
|
||||
'qbcore' => [
|
||||
[
|
||||
'title' => 'QBCore Documentation',
|
||||
'url' => 'https://docs.qbcore.org/qbcore-documentation/',
|
||||
'description' => 'Official QBCore framework documentation and guides',
|
||||
'keywords' => ['qbcore', 'framework', 'documentation', 'guide'],
|
||||
],
|
||||
[
|
||||
'title' => 'QBCore Getting Started',
|
||||
'url' => 'https://docs.qbcore.org/qbcore-documentation/get-started',
|
||||
'description' => 'Getting started with QBCore framework setup and basics',
|
||||
'keywords' => ['qbcore', 'getting started', 'setup', 'installation', 'begin'],
|
||||
],
|
||||
[
|
||||
'title' => 'QBCore Callbacks & Exports',
|
||||
'url' => 'https://docs.qbcore.org/qbcore-documentation/core-concepts/callbacks-exports',
|
||||
'description' => 'Learn about QBCore callbacks and exports for inter-resource communication',
|
||||
'keywords' => ['qbcore', 'callback', 'export', 'function', 'communication'],
|
||||
],
|
||||
[
|
||||
'title' => 'QBCore Items & Inventory',
|
||||
'url' => 'https://docs.qbcore.org/qbcore-documentation/core-concepts/items',
|
||||
'description' => 'Item system and inventory management in QBCore',
|
||||
'keywords' => ['qbcore', 'items', 'inventory', 'item', 'database'],
|
||||
],
|
||||
[
|
||||
'title' => 'QBCore Jobs & Grades',
|
||||
'url' => 'https://docs.qbcore.org/qbcore-documentation/core-concepts/jobs',
|
||||
'description' => 'Job system and player grades in QBCore',
|
||||
'keywords' => ['qbcore', 'job', 'grades', 'employment', 'boss'],
|
||||
],
|
||||
[
|
||||
'title' => 'QBCore Player Management',
|
||||
'url' => 'https://docs.qbcore.org/qbcore-documentation/core-concepts/player',
|
||||
'description' => 'Managing player data and interactions in QBCore',
|
||||
'keywords' => ['qbcore', 'player', 'data', 'management', 'character'],
|
||||
],
|
||||
[
|
||||
'title' => 'QBCore Vehicles',
|
||||
'url' => 'https://docs.qbcore.org/qbcore-documentation/core-concepts/vehicles',
|
||||
'description' => 'Vehicle system and ownership in QBCore',
|
||||
'keywords' => ['qbcore', 'vehicle', 'car', 'ownership', 'garage'],
|
||||
],
|
||||
[
|
||||
'title' => 'QBCore Events',
|
||||
'url' => 'https://docs.qbcore.org/qbcore-documentation/core-concepts/events',
|
||||
'description' => 'QBCore framework events for player and game actions',
|
||||
'keywords' => ['qbcore', 'event', 'trigger', 'listener'],
|
||||
],
|
||||
],
|
||||
'coxdocs' => [
|
||||
[
|
||||
'title' => 'COX Docs - MySQL',
|
||||
'url' => 'https://coxdocs.dev/',
|
||||
'description' => 'Complete MySQL documentation for FiveM - required component for database operations',
|
||||
'keywords' => ['cox', 'mysql', 'database', 'query', 'sql', 'required'],
|
||||
],
|
||||
[
|
||||
'title' => 'COX Docs - Getting Started',
|
||||
'url' => 'https://coxdocs.dev/getting-started',
|
||||
'description' => 'Getting started with COX MySQL library setup and configuration',
|
||||
'keywords' => ['cox', 'mysql', 'getting started', 'setup', 'installation'],
|
||||
],
|
||||
[
|
||||
'title' => 'COX Docs - Query Methods',
|
||||
'url' => 'https://coxdocs.dev/methods',
|
||||
'description' => 'COX library query methods for database operations (SELECT, INSERT, UPDATE, DELETE)',
|
||||
'keywords' => ['cox', 'mysql', 'query', 'method', 'select', 'insert', 'update', 'delete'],
|
||||
],
|
||||
[
|
||||
'title' => 'COX Docs - Events',
|
||||
'url' => 'https://coxdocs.dev/events',
|
||||
'description' => 'COX library events and callbacks for database operations',
|
||||
'keywords' => ['cox', 'mysql', 'event', 'callback', 'listener'],
|
||||
],
|
||||
[
|
||||
'title' => 'COX Docs - Transactions',
|
||||
'url' => 'https://coxdocs.dev/transactions',
|
||||
'description' => 'Database transaction handling with COX MySQL library',
|
||||
'keywords' => ['cox', 'mysql', 'transaction', 'commit', 'rollback'],
|
||||
],
|
||||
[
|
||||
'title' => 'COX Docs - Prepared Statements',
|
||||
'url' => 'https://coxdocs.dev/prepared-statements',
|
||||
'description' => 'Prepared statements for secure SQL queries and SQL injection prevention',
|
||||
'keywords' => ['cox', 'mysql', 'prepared', 'statement', 'security', 'injection'],
|
||||
],
|
||||
[
|
||||
'title' => 'COX Docs - Connection Pooling',
|
||||
'url' => 'https://coxdocs.dev/connection-pooling',
|
||||
'description' => 'Connection pooling and management for optimal database performance',
|
||||
'keywords' => ['cox', 'mysql', 'connection', 'pool', 'pooling', 'performance'],
|
||||
],
|
||||
[
|
||||
'title' => 'COX Docs - Common Patterns',
|
||||
'url' => 'https://coxdocs.dev/patterns',
|
||||
'description' => 'Common database patterns (CRUD operations, async queries, error handling)',
|
||||
'keywords' => ['cox', 'mysql', 'pattern', 'crud', 'create', 'read', 'update', 'delete'],
|
||||
],
|
||||
[
|
||||
'title' => 'COX Docs - Debugging & Performance',
|
||||
'url' => 'https://coxdocs.dev/debugging',
|
||||
'description' => 'Debugging MySQL queries, performance optimization, and troubleshooting',
|
||||
'keywords' => ['cox', 'mysql', 'debug', 'performance', 'optimize', 'slow', 'error'],
|
||||
],
|
||||
[
|
||||
'title' => 'COX Docs - Best Practices',
|
||||
'url' => 'https://coxdocs.dev/best-practices',
|
||||
'description' => 'Database best practices and conventions for FiveM development',
|
||||
'keywords' => ['cox', 'mysql', 'best', 'practice', 'convention', 'standard'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$results = [];
|
||||
$searchIn = $category === 'all' ? array_merge(...array_values($docs)) : ($docs[$category] ?? []);
|
||||
$queryLower = strtolower($query);
|
||||
|
||||
foreach ($searchIn as $doc) {
|
||||
$matchScore = 0;
|
||||
|
||||
// Check title
|
||||
if (str_contains(strtolower($doc['title']), $queryLower)) {
|
||||
$matchScore += 10;
|
||||
}
|
||||
|
||||
// Check keywords
|
||||
foreach ($doc['keywords'] as $keyword) {
|
||||
if (str_contains(strtolower($keyword), $queryLower) || str_contains($queryLower, strtolower($keyword))) {
|
||||
$matchScore += 5;
|
||||
}
|
||||
}
|
||||
|
||||
// Check description
|
||||
if (str_contains(strtolower($doc['description']), $queryLower)) {
|
||||
$matchScore += 3;
|
||||
}
|
||||
|
||||
if ($matchScore > 0) {
|
||||
$results[] = array_merge($doc, ['score' => $matchScore]);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by score descending
|
||||
usort($results, fn ($a, $b) => $b['score'] <=> $a['score']);
|
||||
|
||||
return array_slice($results, 0, 5);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the tool's input schema.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\JsonSchema\JsonSchema>
|
||||
*/
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'query' => $schema
|
||||
->string()
|
||||
->description('The search query for FiveM documentation (e.g., "events", "natives", "manifest")')
|
||||
->required(),
|
||||
'category' => $schema
|
||||
->string()
|
||||
->enum(['all', 'scripting', 'natives', 'networking', 'resources', 'qbcore', 'coxdocs'])
|
||||
->description('Filter results by documentation category')
|
||||
->default('all'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\FiveM\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('Get information about FiveM server-side events including framework events (ESX, QBCore).')]
|
||||
class GetEventServerReference 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->getEventsDatabase();
|
||||
|
||||
foreach ($events as $event) {
|
||||
if (strtolower($event['name']) === strtolower($eventName)) {
|
||||
return Response::text($this->formatEventInfo($event, $language));
|
||||
}
|
||||
}
|
||||
|
||||
return Response::text(sprintf("Server event '%s' not found in the database.", $eventName));
|
||||
}
|
||||
|
||||
/**
|
||||
* List events by type.
|
||||
*/
|
||||
protected function listEvents(string $type, string $language): Response
|
||||
{
|
||||
$events = $this->getEventsDatabase();
|
||||
|
||||
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.event-list', [
|
||||
'eventsByType' => $eventsByType,
|
||||
])->render()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Format event information.
|
||||
*/
|
||||
protected function formatEventInfo(array $event, string $language): string
|
||||
{
|
||||
return view('mcp.event-reference', [
|
||||
'event' => $event,
|
||||
'language' => $language,
|
||||
])->render();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get server events database.
|
||||
*/
|
||||
protected function getEventsDatabase(): array
|
||||
{
|
||||
return [
|
||||
// Core FiveM Server Events
|
||||
[
|
||||
'name' => 'onResourceStart',
|
||||
'type' => 'core',
|
||||
'side' => 'server',
|
||||
'description' => 'Triggered when a resource starts (server-side)',
|
||||
'parameters' => [
|
||||
['name' => 'resourceName', 'type' => 'string', 'description' => 'The name of the resource that started'],
|
||||
],
|
||||
'lua_example' => "AddEventHandler('onResourceStart', function(resourceName)\n if resourceName == GetCurrentResourceName() then\n print('Resource started on server!')\n end\nend)",
|
||||
'js_example' => "on('onResourceStart', (resourceName) => {\n if (resourceName === GetCurrentResourceName()) {\n console.log('Resource started on server!');\n }\n});",
|
||||
'documentation' => 'https://docs.fivem.net/docs/scripting-reference/events/list/onResourceStart/',
|
||||
],
|
||||
[
|
||||
'name' => 'onResourceStop',
|
||||
'type' => 'core',
|
||||
'side' => 'server',
|
||||
'description' => 'Triggered when a resource stops (server-side)',
|
||||
'parameters' => [
|
||||
['name' => 'resourceName', 'type' => 'string', 'description' => 'The name of the resource that stopped'],
|
||||
],
|
||||
'lua_example' => "AddEventHandler('onResourceStop', function(resourceName)\n if resourceName == GetCurrentResourceName() then\n print('Resource stopped on server!')\n end\nend)",
|
||||
'js_example' => "on('onResourceStop', (resourceName) => {\n if (resourceName === GetCurrentResourceName()) {\n console.log('Resource stopped on server!');\n }\n});",
|
||||
'documentation' => 'https://docs.fivem.net/docs/scripting-reference/events/list/onResourceStop/',
|
||||
],
|
||||
[
|
||||
'name' => 'playerConnecting',
|
||||
'type' => 'core',
|
||||
'side' => 'server',
|
||||
'description' => 'Triggered when a player is connecting to the server',
|
||||
'parameters' => [
|
||||
['name' => 'name', 'type' => 'string', 'description' => 'Player name'],
|
||||
['name' => 'setKickReason', 'type' => 'function', 'description' => 'Function to deny connection'],
|
||||
['name' => 'deferrals', 'type' => 'object', 'description' => 'Deferrals object for async connection'],
|
||||
],
|
||||
'lua_example' => "AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)\n local source = source\n deferrals.defer()\n -- Check player\n deferrals.done()\nend)",
|
||||
'js_example' => "on('playerConnecting', (name, setKickReason, deferrals) => {\n const source = global.source;\n deferrals.defer();\n // Check player\n deferrals.done();\n});",
|
||||
'documentation' => 'https://docs.fivem.net/docs/scripting-reference/events/list/playerConnecting/',
|
||||
],
|
||||
[
|
||||
'name' => 'playerDropped',
|
||||
'type' => 'core',
|
||||
'side' => 'server',
|
||||
'description' => 'Triggered when a player disconnects from the server',
|
||||
'parameters' => [
|
||||
['name' => 'reason', 'type' => 'string', 'description' => 'Disconnect reason'],
|
||||
],
|
||||
'lua_example' => "AddEventHandler('playerDropped', function(reason)\n local source = source\n print('Player ' .. GetPlayerName(source) .. ' dropped: ' .. reason)\nend)",
|
||||
'js_example' => "on('playerDropped', (reason) => {\n const source = global.source;\n console.log(`Player \${GetPlayerName(source)} dropped: \${reason}`);\n});",
|
||||
'documentation' => 'https://docs.fivem.net/docs/scripting-reference/events/list/playerDropped/',
|
||||
],
|
||||
// ESX Server Events
|
||||
[
|
||||
'name' => 'esx:playerLoaded',
|
||||
'type' => 'esx',
|
||||
'side' => 'server',
|
||||
'description' => 'Triggered on server when ESX player loads',
|
||||
'parameters' => [
|
||||
['name' => 'xPlayer', 'type' => 'table', 'description' => 'ESX player object'],
|
||||
],
|
||||
'lua_example' => "AddEventHandler('esx:playerLoaded', function(source, xPlayer)\n -- Server-side player loaded\nend)",
|
||||
'js_example' => "on('esx:playerLoaded', (source, xPlayer) => {\n // Server-side player loaded\n});",
|
||||
],
|
||||
// QBCore Server Events
|
||||
[
|
||||
'name' => 'QBCore:Server:PlayerLoaded',
|
||||
'type' => 'qbcore',
|
||||
'side' => 'server',
|
||||
'description' => 'Triggered on server when QBCore player loads',
|
||||
'parameters' => [
|
||||
['name' => 'Player', 'type' => 'table', 'description' => 'QBCore player object'],
|
||||
],
|
||||
'lua_example' => "AddEventHandler('QBCore:Server:PlayerLoaded', function(Player)\n -- Server-side player loaded\nend)",
|
||||
'js_example' => "on('QBCore:Server:PlayerLoaded', (Player) => {\n // Server-side player loaded\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 server event name to look up (optional, leave empty to list all events)'),
|
||||
'event_type' => $schema
|
||||
->string()
|
||||
->enum(['all', 'core', 'esx', 'qbcore'])
|
||||
->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,210 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools\FiveM\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 GTA5/FiveM server-side native functions by name. Returns function signature, parameters, return type, and usage examples.')]
|
||||
class GetNativeServerFunction extends Tool
|
||||
{
|
||||
/**
|
||||
* Handle the tool request.
|
||||
*/
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$functionName = $request->get('function_name');
|
||||
$language = $request->get('language', 'lua');
|
||||
|
||||
$native = $this->findNative($functionName);
|
||||
|
||||
if (! $native) {
|
||||
return Response::text(sprintf("Server native function '%s' not found. Try searching at https://docs.fivem.net/natives/", $functionName));
|
||||
}
|
||||
|
||||
$output = $this->formatNativeInfo($native, $language);
|
||||
|
||||
return Response::text($output);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a server native function.
|
||||
*/
|
||||
protected function findNative(string $name): ?array
|
||||
{
|
||||
// Server-side only FiveM natives
|
||||
$natives = [
|
||||
'TriggerClientEvent' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Triggers an event on a client from server',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'eventName', 'type' => 'string', 'description' => 'The name of the event'],
|
||||
['name' => 'playerId', 'type' => 'int|string', 'description' => 'The player server ID or -1 for all'],
|
||||
['name' => '...args', 'type' => 'any', 'description' => 'Event arguments'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "TriggerClientEvent('myResource:clientEvent', playerId, arg1, arg2)",
|
||||
'js_example' => "TriggerClientEvent('myResource:clientEvent', playerId, arg1, arg2);",
|
||||
],
|
||||
'TriggerClientEventReliable' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Triggers an event on a client with guaranteed delivery',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'eventName', 'type' => 'string', 'description' => 'The name of the event'],
|
||||
['name' => 'playerId', 'type' => 'int|string', 'description' => 'The player server ID'],
|
||||
['name' => '...args', 'type' => 'any', 'description' => 'Event arguments'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "TriggerClientEventReliable('myResource:clientEvent', playerId, arg1, arg2)",
|
||||
'js_example' => "TriggerClientEventReliable('myResource:clientEvent', playerId, arg1, arg2);",
|
||||
],
|
||||
'GetPlayerName' => [
|
||||
'namespace' => 'PLAYER',
|
||||
'description' => 'Returns the name of a player (server-side)',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'playerId', 'type' => 'int', 'description' => 'The player server ID'],
|
||||
],
|
||||
'returns' => ['type' => 'string', 'description' => 'The player name'],
|
||||
'lua_example' => 'local name = GetPlayerName(source)',
|
||||
'js_example' => 'const name = GetPlayerName(global.source);',
|
||||
],
|
||||
'GetPlayerIdentifier' => [
|
||||
'namespace' => 'PLAYER',
|
||||
'description' => 'Gets a specific identifier for a player',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'playerId', 'type' => 'int', 'description' => 'The player server ID'],
|
||||
['name' => 'type', 'type' => 'int', 'description' => 'Identifier type (0 = license, 1 = steam, etc.)'],
|
||||
],
|
||||
'returns' => ['type' => 'string', 'description' => 'The player identifier'],
|
||||
'lua_example' => "local license = GetPlayerIdentifier(source, 0)\nlocal steam = GetPlayerIdentifier(source, 1)",
|
||||
'js_example' => "const license = GetPlayerIdentifier(global.source, 0);\nconst steam = GetPlayerIdentifier(global.source, 1);",
|
||||
],
|
||||
'GetPlayerPing' => [
|
||||
'namespace' => 'PLAYER',
|
||||
'description' => 'Gets the ping of a player in milliseconds',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'playerId', 'type' => 'int', 'description' => 'The player server ID'],
|
||||
],
|
||||
'returns' => ['type' => 'int', 'description' => 'Player ping in ms'],
|
||||
'lua_example' => 'local ping = GetPlayerPing(source)',
|
||||
'js_example' => 'const ping = GetPlayerPing(global.source);',
|
||||
],
|
||||
'DropPlayer' => [
|
||||
'namespace' => 'PLAYER',
|
||||
'description' => 'Disconnects a player from the server',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'playerId', 'type' => 'int', 'description' => 'The player server ID'],
|
||||
['name' => 'reason', 'type' => 'string', 'description' => 'Reason for dropping the player'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "DropPlayer(source, 'You were kicked by admin')",
|
||||
'js_example' => "DropPlayer(global.source, 'You were kicked by admin');",
|
||||
],
|
||||
'GetPlayers' => [
|
||||
'namespace' => 'PLAYER',
|
||||
'description' => 'Gets a list of all player server IDs on the server',
|
||||
'side' => 'server',
|
||||
'parameters' => [],
|
||||
'returns' => ['type' => 'table', 'description' => 'Array of player IDs'],
|
||||
'lua_example' => "local players = GetPlayers()\nfor _, playerId in ipairs(players) do\n print('Player: ' .. playerId)\nend",
|
||||
'js_example' => "const players = GetPlayers();\nfor (const playerId of players) {\n console.log('Player: ' + playerId);\n}",
|
||||
],
|
||||
'AddEventHandler' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Adds a server-side event handler',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'eventName', 'type' => 'string', 'description' => 'The name of the event'],
|
||||
['name' => 'callback', 'type' => 'function', 'description' => 'The handler function'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "AddEventHandler('playerConnecting', function(name, setKickReason, deferrals)\n -- Handle player connecting\nend)",
|
||||
'js_example' => "AddEventHandler('playerConnecting', (name, setKickReason, deferrals) => {\n // Handle player connecting\n});",
|
||||
],
|
||||
'TriggerEvent' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Triggers a server-side event',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'eventName', 'type' => 'string', 'description' => 'The name of the event'],
|
||||
['name' => '...args', 'type' => 'any', 'description' => 'Event arguments'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "TriggerEvent('myEvent', arg1, arg2)",
|
||||
'js_example' => "TriggerEvent('myEvent', arg1, arg2);",
|
||||
],
|
||||
'ESX.GetPlayerFromId' => [
|
||||
'namespace' => 'ESX',
|
||||
'description' => 'Get ESX player object from server ID (server-side only)',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'source', 'type' => 'int', 'description' => 'The player server ID'],
|
||||
],
|
||||
'returns' => ['type' => 'table', 'description' => 'ESX player object'],
|
||||
'lua_example' => 'local xPlayer = ESX.GetPlayerFromId(source)',
|
||||
'js_example' => 'const xPlayer = ESX.GetPlayerFromId(global.source);',
|
||||
],
|
||||
'QBCore.Functions.GetPlayer' => [
|
||||
'namespace' => 'QBCore',
|
||||
'description' => 'Get QBCore player object from server ID (server-side only)',
|
||||
'side' => 'server',
|
||||
'parameters' => [
|
||||
['name' => 'source', 'type' => 'int', 'description' => 'The player server ID'],
|
||||
],
|
||||
'returns' => ['type' => 'table', 'description' => 'QBCore player object'],
|
||||
'lua_example' => 'local Player = QBCore.Functions.GetPlayer(source)',
|
||||
'js_example' => 'const Player = QBCore.Functions.GetPlayer(global.source);',
|
||||
],
|
||||
];
|
||||
|
||||
$nameLower = strtolower($name);
|
||||
|
||||
foreach ($natives as $nativeName => $nativeData) {
|
||||
if (strtolower($nativeName) === $nameLower) {
|
||||
return array_merge(['name' => $nativeName], $nativeData);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format native function info.
|
||||
*/
|
||||
protected function formatNativeInfo(array $native, string $language): string
|
||||
{
|
||||
return view('mcp.native-function', [
|
||||
'native' => $native,
|
||||
'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 server-side native function to look up (e.g., "TriggerClientEvent", "GetPlayers", "DropPlayer")')
|
||||
->required(),
|
||||
'language' => $schema
|
||||
->string()
|
||||
->enum(['lua', 'js'])
|
||||
->description('The scripting language for code examples')
|
||||
->default('lua'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user