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,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\View\View;
|
||||
|
||||
class DocsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Show the documentation index page.
|
||||
*/
|
||||
public function index(): View
|
||||
{
|
||||
return view('docs.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the quick start guide.
|
||||
*/
|
||||
public function quickstart(): View
|
||||
{
|
||||
return view('docs.quickstart');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the full documentation.
|
||||
*/
|
||||
public function documentation(): View
|
||||
{
|
||||
return view('docs.documentation');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Prompts;
|
||||
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Prompt;
|
||||
|
||||
#[Description('Add ESX or QBCore framework integration to existing resource')]
|
||||
class AddFrameworkIntegration extends Prompt
|
||||
{
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$code = $request->get('code', '');
|
||||
$currentFramework = $request->get('current_framework', 'standalone');
|
||||
$targetFramework = $request->get('target_framework', 'esx');
|
||||
|
||||
$parts = [sprintf(
|
||||
"Convert this FiveM resource from %s to %s:\n\n",
|
||||
$currentFramework,
|
||||
$targetFramework
|
||||
)];
|
||||
|
||||
if ($code) {
|
||||
$parts[] = sprintf("Current Code:\n```\n%s\n```\n\n", $code);
|
||||
}
|
||||
|
||||
$parts[] = sprintf(
|
||||
"%s\n%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n%s",
|
||||
"Please:",
|
||||
"1. Update the fxmanifest.lua with framework dependencies",
|
||||
"2. Replace custom player systems with framework functions",
|
||||
"3. Convert money/inventory operations to framework equivalents",
|
||||
"4. Update event handlers to use framework events",
|
||||
"5. Add framework-specific features if beneficial",
|
||||
"6. Maintain backward compatibility where possible",
|
||||
"7. Add comments explaining the integration changes",
|
||||
"Use the GetEventReference tool to find relevant framework events."
|
||||
);
|
||||
|
||||
return Response::prompt(implode('', $parts));
|
||||
}
|
||||
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'code' => $schema->string()
|
||||
->description('Current resource code')
|
||||
->default(''),
|
||||
'current_framework' => $schema->enum(['standalone', 'esx', 'qbcore'])
|
||||
->description('Current framework')
|
||||
->default('standalone'),
|
||||
'target_framework' => $schema->enum(['esx', 'qbcore'])
|
||||
->description('Target framework')
|
||||
->default('esx'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Prompts;
|
||||
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Prompt;
|
||||
|
||||
#[Description('Convert code between Lua and JavaScript')]
|
||||
class ConvertLanguage extends Prompt
|
||||
{
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$code = $request->get('code', '');
|
||||
$from = $request->get('from', 'lua');
|
||||
$to = $request->get('to', 'js');
|
||||
|
||||
$parts = [sprintf("Convert this FiveM code from %s to %s:\n\n", $from, $to)];
|
||||
|
||||
if ($code) {
|
||||
$parts[] = sprintf("```%s\n%s\n```\n\n", $from, $code);
|
||||
}
|
||||
|
||||
$parts[] = sprintf(
|
||||
"%s\n%s\n%s\n%s\n%s\n%s\n%s\n\n%s\n%s\n%s\n%s\n%s\n%s",
|
||||
"Please:",
|
||||
"1. Convert the code while maintaining functionality",
|
||||
"2. Use idiomatic patterns for the target language",
|
||||
"3. Update native function calls to match language syntax",
|
||||
"4. Adjust event handlers and callbacks",
|
||||
"5. Explain major differences in the conversion",
|
||||
"6. Ensure FiveM compatibility in the target language",
|
||||
"Key differences to consider:",
|
||||
"- Array/table indexing (0 vs 1-based)",
|
||||
"- String formatting",
|
||||
"- Event registration syntax",
|
||||
"- Async patterns",
|
||||
"- Native return values"
|
||||
);
|
||||
|
||||
return Response::prompt(implode('', $parts));
|
||||
}
|
||||
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'code' => $schema->string()
|
||||
->description('Code to convert')
|
||||
->required(),
|
||||
'from' => $schema->enum(['lua', 'js'])
|
||||
->description('Source language')
|
||||
->default('lua'),
|
||||
'to' => $schema->enum(['lua', 'js'])
|
||||
->description('Target language')
|
||||
->default('js'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Prompts;
|
||||
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Prompt;
|
||||
|
||||
#[Description('Create a new FiveM resource with framework and language selection')]
|
||||
class CreateNewResource extends Prompt
|
||||
{
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$resourceName = $request->get('resource_name', 'my-resource');
|
||||
$framework = $request->get('framework', 'standalone');
|
||||
$language = $request->get('language', 'lua');
|
||||
|
||||
return Response::prompt(sprintf(
|
||||
"Create a new FiveM resource called '%s' with the following requirements:\n\n" .
|
||||
"Framework: %s\n" .
|
||||
"Language: %s\n\n" .
|
||||
"Please:\n" .
|
||||
"1. Generate a complete fxmanifest.lua\n" .
|
||||
"2. Create a config file with common settings\n" .
|
||||
"3. Generate boilerplate client and server files\n" .
|
||||
"4. Include proper error handling and validation\n" .
|
||||
"5. Follow FiveM best practices\n" .
|
||||
"6. Add helpful comments explaining the code structure\n\n" .
|
||||
"Use the available tools to generate the manifest and boilerplate code.",
|
||||
$resourceName,
|
||||
$framework,
|
||||
$language
|
||||
));
|
||||
}
|
||||
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'resource_name' => $schema->string()
|
||||
->description('Name of the resource to create')
|
||||
->default('my-resource'),
|
||||
'framework' => $schema->enum(['standalone', 'esx', 'qbcore'])
|
||||
->description('Framework to use')
|
||||
->default('standalone'),
|
||||
'language' => $schema->enum(['lua', 'js'])
|
||||
->description('Scripting language')
|
||||
->default('lua'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Prompts;
|
||||
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Prompt;
|
||||
|
||||
#[Description('Debug common FiveM issues and errors')]
|
||||
class DebugIssues extends Prompt
|
||||
{
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$issue = $request->get('issue', '');
|
||||
$errorMessage = $request->get('error_message', '');
|
||||
|
||||
$parts = ["Help me debug a FiveM issue:\n\n"];
|
||||
|
||||
if ($issue) {
|
||||
$parts[] = sprintf("Issue Description: %s\n\n", $issue);
|
||||
}
|
||||
|
||||
if ($errorMessage) {
|
||||
$parts[] = sprintf("Error Message: %s\n\n", $errorMessage);
|
||||
}
|
||||
|
||||
$parts[] = sprintf(
|
||||
"%s\n%s\n%s\n%s\n%s\n%s\n\n%s",
|
||||
"Please analyze this issue and:",
|
||||
"1. Identify the likely cause",
|
||||
"2. Suggest fixes with code examples",
|
||||
"3. Explain common mistakes that lead to this issue",
|
||||
"4. Provide preventive measures",
|
||||
"5. Reference FiveM best practices if applicable",
|
||||
"Use the SearchFiveMDocs and GetNativeFunction tools to find relevant information."
|
||||
);
|
||||
|
||||
return Response::prompt(implode('', $parts));
|
||||
}
|
||||
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'issue' => $schema->string()
|
||||
->description('Description of the issue or problem')
|
||||
->default(''),
|
||||
'error_message' => $schema->string()
|
||||
->description('Error message from console or logs')
|
||||
->default(''),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Prompts;
|
||||
|
||||
use Illuminate\Contracts\JsonSchema\JsonSchema;
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Prompt;
|
||||
|
||||
#[Description('Optimize FiveM script performance')]
|
||||
class OptimizePerformance extends Prompt
|
||||
{
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
$code = $request->get('code', '');
|
||||
$scriptType = $request->get('script_type', 'client');
|
||||
|
||||
$parts = ["Review and optimize this FiveM script for better performance:\n\n"];
|
||||
|
||||
if ($code) {
|
||||
$parts[] = sprintf("```\n%s\n```\n\n", $code);
|
||||
}
|
||||
|
||||
$parts[] = sprintf(
|
||||
"Script Type: %s\n\n%s\n%s\n%s\n%s\n%s\n%s\n\n%s\n%s\n%s\n%s\n%s\n%s",
|
||||
$scriptType,
|
||||
"Please analyze the code and:",
|
||||
"1. Identify performance issues (unnecessary loops, missing waits, etc.)",
|
||||
"2. Suggest optimizations with code examples",
|
||||
"3. Explain why each optimization improves performance",
|
||||
"4. Provide the optimized version of the code",
|
||||
"5. Reference FiveM best practices for performance",
|
||||
"Focus on:",
|
||||
"- Proper Citizen.Wait() usage",
|
||||
"- Distance checks before expensive operations",
|
||||
"- Caching frequently accessed values",
|
||||
"- Reducing server-client communication",
|
||||
"- Efficient event handling"
|
||||
);
|
||||
|
||||
return Response::prompt(implode('', $parts));
|
||||
}
|
||||
|
||||
public function schema(JsonSchema $schema): array
|
||||
{
|
||||
return [
|
||||
'code' => $schema->string()
|
||||
->description('The code to optimize')
|
||||
->default(''),
|
||||
'script_type' => $schema->enum(['client', 'server', 'shared'])
|
||||
->description('Type of script')
|
||||
->default('client'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Resources;
|
||||
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Resource;
|
||||
|
||||
#[Description('FiveM development best practices and optimization tips')]
|
||||
class BestPractices extends Resource
|
||||
{
|
||||
public function uri(): string
|
||||
{
|
||||
return 'fivem://guides/best-practices';
|
||||
}
|
||||
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
return Response::text(view('mcp.resources.best-practices')->render());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Resources;
|
||||
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Resource;
|
||||
|
||||
#[Description('Common FiveM code patterns and snippets for quick reference')]
|
||||
class CodeSnippets extends Resource
|
||||
{
|
||||
public function uri(): string
|
||||
{
|
||||
return 'fivem://snippets/common';
|
||||
}
|
||||
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
return Response::text(view('mcp.resources.code-snippets')->render());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Resources;
|
||||
|
||||
use Laravel\Mcp\Request;
|
||||
use Laravel\Mcp\Response;
|
||||
use Laravel\Mcp\Server\Attributes\Description;
|
||||
use Laravel\Mcp\Server\Resource;
|
||||
|
||||
#[Description('Comparison of FiveM frameworks: Standalone, ESX, and QBCore')]
|
||||
class FrameworkComparison extends Resource
|
||||
{
|
||||
public function uri(): string
|
||||
{
|
||||
return 'fivem://guides/framework-comparison';
|
||||
}
|
||||
|
||||
public function handle(Request $request): Response
|
||||
{
|
||||
return Response::text(view('mcp.resources.framework-comparison')->render());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace App\Mcp\Servers;
|
||||
|
||||
use App\Mcp\Prompts\AddFrameworkIntegration;
|
||||
use App\Mcp\Prompts\ConvertLanguage;
|
||||
use App\Mcp\Prompts\CreateNewResource;
|
||||
use App\Mcp\Prompts\DebugIssues;
|
||||
use App\Mcp\Prompts\OptimizePerformance;
|
||||
use App\Mcp\Resources\BestPractices;
|
||||
use App\Mcp\Resources\CodeSnippets;
|
||||
use App\Mcp\Resources\FrameworkComparison;
|
||||
use App\Mcp\Tools\GenerateManifest;
|
||||
use App\Mcp\Tools\GenerateResourceBoilerplate;
|
||||
use App\Mcp\Tools\GetEventReference;
|
||||
use App\Mcp\Tools\GetNativeFunction;
|
||||
use App\Mcp\Tools\SearchFiveMDocs;
|
||||
use Laravel\Mcp\Server;
|
||||
use Laravel\Mcp\Server\Attributes\Instructions;
|
||||
use Laravel\Mcp\Server\Attributes\Name;
|
||||
use Laravel\Mcp\Server\Attributes\Version;
|
||||
|
||||
#[Name('FiveM Development Server')]
|
||||
#[Version('1.0.0')]
|
||||
#[Instructions(<<<'INSTRUCTIONS'
|
||||
This MCP server provides comprehensive tools for FiveM (GTA5) script development.
|
||||
|
||||
Available features:
|
||||
- Search FiveM documentation and native functions
|
||||
- Generate resource manifests (fxmanifest.lua)
|
||||
- Look up game natives for client, server, and shared scripts
|
||||
- Get code examples and best practices
|
||||
- Access event documentation
|
||||
- Generate boilerplate code for resources
|
||||
|
||||
Use these tools to accelerate your FiveM development workflow.
|
||||
INSTRUCTIONS)]
|
||||
class FiveMServer extends Server
|
||||
{
|
||||
protected array $tools = [
|
||||
SearchFiveMDocs::class,
|
||||
GetNativeFunction::class,
|
||||
GenerateManifest::class,
|
||||
GetEventReference::class,
|
||||
GenerateResourceBoilerplate::class,
|
||||
];
|
||||
|
||||
protected array $resources = [
|
||||
CodeSnippets::class,
|
||||
BestPractices::class,
|
||||
FrameworkComparison::class,
|
||||
];
|
||||
|
||||
protected array $prompts = [
|
||||
CreateNewResource::class,
|
||||
DebugIssues::class,
|
||||
OptimizePerformance::class,
|
||||
ConvertLanguage::class,
|
||||
AddFrameworkIntegration::class,
|
||||
];
|
||||
}
|
||||
@@ -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'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user