Add FiveM resources and templates for documentation and code snippets
- Introduced a new code snippets resource for common FiveM patterns in Lua and JavaScript. - Added a framework comparison document outlining Standalone, ESX, and QBCore features. - Created search results view for FiveM documentation queries. - Developed client and server template scripts for ESX and QBCore frameworks. - Implemented NUI templates including HTML, CSS, and JavaScript for user interfaces. - Established routes for documentation and console commands. - Added tests for various features including documentation routes and tool functionalities. - Configured Vite for asset management with Laravel. - Updated .gitignore files for storage and framework directories.
This commit is contained in:
112 files changed
+51106
No files matched your search
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools;
|
||||
|
||||
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;
|
||||
|
||||
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,207 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools;
|
||||
|
||||
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 events including built-in and common framework events (ESX, QBCore).')]
|
||||
class GetEventReference 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("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 events database.
|
||||
*/
|
||||
protected function getEventsDatabase(): array
|
||||
{
|
||||
return [
|
||||
// Core FiveM Events
|
||||
[
|
||||
'name' => 'onResourceStart',
|
||||
'type' => 'core',
|
||||
'side' => 'both',
|
||||
'description' => 'Triggered when a resource starts',
|
||||
'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!')\n end\nend)",
|
||||
'js_example' => "on('onResourceStart', (resourceName) => {\n if (resourceName === GetCurrentResourceName()) {\n console.log('Resource started!');\n }\n});",
|
||||
'documentation' => 'https://docs.fivem.net/docs/scripting-reference/events/list/onResourceStart/',
|
||||
],
|
||||
[
|
||||
'name' => 'onResourceStop',
|
||||
'type' => 'core',
|
||||
'side' => 'both',
|
||||
'description' => 'Triggered when a resource stops',
|
||||
'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 stopping!')\n end\nend)",
|
||||
'js_example' => "on('onResourceStop', (resourceName) => {\n if (resourceName === GetCurrentResourceName()) {\n console.log('Resource stopping!');\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 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 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 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,196 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools;
|
||||
|
||||
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 native functions by name. Returns function signature, parameters, return type, and usage examples.')]
|
||||
class GetNativeFunction 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("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 native function.
|
||||
*/
|
||||
protected function findNative(string $name): ?array
|
||||
{
|
||||
// Common FiveM/GTA5 natives database
|
||||
$natives = [
|
||||
// Player/Ped natives
|
||||
'GetPlayerPed' => [
|
||||
'namespace' => 'PLAYER',
|
||||
'description' => 'Gets the local or specified player\'s ped handle',
|
||||
'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);',
|
||||
],
|
||||
'GetPlayerName' => [
|
||||
'namespace' => 'PLAYER',
|
||||
'description' => 'Returns the name of a player',
|
||||
'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());',
|
||||
],
|
||||
'SetEntityCoords' => [
|
||||
'namespace' => 'ENTITY',
|
||||
'description' => 'Sets the coordinates of an entity',
|
||||
'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',
|
||||
'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);',
|
||||
],
|
||||
'RegisterNetEvent' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Registers a network event handler (FiveM-specific)',
|
||||
'parameters' => [
|
||||
['name' => 'eventName', 'type' => 'string', 'description' => 'The name of the event'],
|
||||
],
|
||||
'returns' => ['type' => 'void', 'description' => 'No return value'],
|
||||
'lua_example' => "RegisterNetEvent('myResource:eventName', function(param1, param2)\n -- Handle event\nend)",
|
||||
'js_example' => "RegisterNetEvent('myResource:eventName', (param1, param2) => {\n // Handle event\n});",
|
||||
],
|
||||
'TriggerServerEvent' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Triggers an event on the server from 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);",
|
||||
],
|
||||
'TriggerClientEvent' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Triggers an event on a client from 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);",
|
||||
],
|
||||
'AddEventHandler' => [
|
||||
'namespace' => 'CFX',
|
||||
'description' => 'Adds an event handler for local events',
|
||||
'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});",
|
||||
],
|
||||
'ESX.GetPlayerFromId' => [
|
||||
'namespace' => 'ESX',
|
||||
'description' => 'Get ESX player object from server ID (server-side)',
|
||||
'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(source);',
|
||||
],
|
||||
'QBCore.Functions.GetPlayer' => [
|
||||
'namespace' => 'QBCore',
|
||||
'description' => 'Get QBCore player object from server ID (server-side)',
|
||||
'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(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 native function to look up (e.g., "GetPlayerPed", "SetEntityCoords")')
|
||||
->required(),
|
||||
'language' => $schema
|
||||
->string()
|
||||
->enum(['lua', 'js'])
|
||||
->description('The scripting language for code examples')
|
||||
->default('lua'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Tools;
|
||||
|
||||
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'],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$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'])
|
||||
->description('Filter results by documentation category')
|
||||
->default('all'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user