73 lines
2.0 KiB
PHP
73 lines
2.0 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Database\Factories\McpServerFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\RouteKey;
|
|
use Illuminate\Database\Eloquent\Attributes\Scope;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Support\Str;
|
|
|
|
#[Fillable([
|
|
'name', 'slug', 'description', 'url', 'docs_url', 'logo_url', 'category',
|
|
'install_command', 'config_example', 'transport', 'language', 'capabilities',
|
|
'tags', 'featured', 'approved', 'user_id',
|
|
])]
|
|
#[RouteKey('slug')]
|
|
class McpServer extends Model
|
|
{
|
|
/** @use HasFactory<McpServerFactory> */
|
|
use HasFactory;
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'capabilities' => 'array',
|
|
'tags' => 'array',
|
|
'featured' => 'boolean',
|
|
'approved' => 'boolean',
|
|
];
|
|
}
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (McpServer $server) {
|
|
if (empty($server->slug)) {
|
|
$server->slug = Str::slug($server->name);
|
|
}
|
|
});
|
|
}
|
|
|
|
/**
|
|
* @return BelongsTo<User, $this>
|
|
*/
|
|
public function user(): BelongsTo
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
/**
|
|
* @param Builder<McpServer> $query
|
|
*/
|
|
#[Scope]
|
|
protected function approved(Builder $query): void
|
|
{
|
|
$query->where('approved', true);
|
|
}
|
|
|
|
protected function categoryLabel(): Attribute
|
|
{
|
|
return Attribute::get(fn () => config("mcp_servers.categories.{$this->category}", $this->category));
|
|
}
|
|
|
|
protected function transportLabel(): Attribute
|
|
{
|
|
return Attribute::get(fn () => $this->transport ? config("mcp_servers.transports.{$this->transport}", $this->transport) : null);
|
|
}
|
|
}
|