1. Go to this page and download the library: Download larafony/mcp-assistant library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
larafony / mcp-assistant example snippets
use Larafony\McpAssistant\McpAssistantServiceProvider;
$app->withServiceProviders([
// ... other providers
McpAssistantServiceProvider::class
]);
use Larafony\Framework\Routing\Advanced\Attributes\Route;
class UserController extends Controller
{
#[Route('/users', 'GET')]
public function index(): ResponseInterface { ... }
#[Route('/users/<id:\d+>', 'GET')]
public function show(int $id): ResponseInterface { ... }
}
use Larafony\Framework\Database\ORM\Model;
use Larafony\Framework\Database\ORM\Attributes\BelongsTo;
use Larafony\Framework\Database\ORM\Attributes\HasMany;
class Post extends Model
{
public ?string $title {
get => $this->title ?? null;
set {
$this->title = $value;
$this->markPropertyAsChanged('title');
}
}
#[BelongsTo(related: User::class, foreign_key: 'user_id')]
public ?User $author { get => $this->relations->getRelation('author'); }
#[HasMany(related: Comment::class, foreign_key: 'post_id')]
public array $comments { get => $this->relations->getRelation('comments'); }
}
namespace Larafony\McpAssistant\Tools;
use Mcp\Capability\Attribute\McpTool;
use Mcp\Capability\Attribute\Schema;
use Mcp\Schema\Content\TextContent;
class MyCustomTool
{
#[McpTool(
name: 'my_custom_tool',
description: 'Description for AI',
)]
public function execute(
#[Schema(description: 'Parameter description', type: 'string')]
string $param,
): TextContent {
return new TextContent('Result');
}
}
namespace Larafony\McpAssistant\Resources;
use Mcp\Capability\Attribute\McpResource;
class MyResource
{
#[McpResource(
uri: 'my://resource',
name: 'my-resource', // alphanumeric, underscores, hyphens only
description: 'Description for AI',
mimeType: 'text/plain',
)]
public function getData(): string // Return string, SDK wraps it
{
return 'Resource content';
}
}
namespace Larafony\McpAssistant\Prompts;
use Mcp\Capability\Attribute\McpPrompt;
use Mcp\Capability\Attribute\Schema;
use Mcp\Schema\Content\PromptMessage;
use Mcp\Schema\Content\TextContent;
use Mcp\Schema\Enum\Role;
class MyPrompt
{
/**
* @return array<int, PromptMessage>
*/
#[McpPrompt(
name: 'my_prompt',
description: 'Description for AI',
)]
public function generate(
#[Schema(description: 'Input parameter', type: 'string')]
string $input,
): array {
return [
new PromptMessage(
role: Role::User,
content: new TextContent("Prompt with {$input}"),
),
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.