Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1475,3 +1475,10 @@ jobs:
composer require api-platform/laravel:"@dev" -W
php ./artisan api-platform:install
working-directory: 'test-api-platform-install'
- name: Smoke test
run: |
php ./artisan serve &
sleep 2
curl -f http://127.0.0.1:8000/api || exit 1
kill %1
working-directory: 'test-api-platform-install'
14 changes: 11 additions & 3 deletions src/Laravel/ApiPlatformDeferredProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,18 @@ public function register(): void
return new CallableProvider(new ServiceLocator($tagged));
});

$providers = [ItemProvider::class, CollectionProvider::class, ErrorProvider::class];

if (class_exists(ToolProvider::class)) {
$this->app->singleton(ToolProvider::class, static function (Application $app) {
return new ToolProvider(
$app->make(ObjectMapper::class)
);
});
$providers[] = ToolProvider::class;
}

$this->autoconfigure($classes, ProviderInterface::class, [ItemProvider::class, CollectionProvider::class, ErrorProvider::class, ToolProvider::class]);
$this->autoconfigure($classes, ProviderInterface::class, $providers);

$this->app->singleton(ResourceMetadataCollectionFactoryInterface::class, function (Application $app) {
/** @var ConfigRepository $config */
Expand Down Expand Up @@ -377,7 +380,7 @@ private function autoconfigure(array $classes, string $interface, array $apiPlat
*/
public function provides(): array
{
return [
$provides = [
CallableProvider::class,
CallableProcessor::class,
ItemProvider::class,
Expand All @@ -390,7 +393,12 @@ public function provides(): array
'api_platform.graphql.state_provider.parameter',
FieldsBuilderEnumInterface::class,
ExceptionHandlerInterface::class,
ToolProvider::class,
];

if (class_exists(ToolProvider::class)) {
$provides[] = ToolProvider::class;
}

return $provides;
}
}
8 changes: 3 additions & 5 deletions src/Laravel/ApiPlatformProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,9 @@ public function register(): void
$this->registerGraphQl();
}

$this->registerMcp();
if (class_exists(McpController::class)) {
$this->registerMcp();
}

$this->app->singleton(JsonApiEntrypointNormalizer::class, static function (Application $app) {
return new JsonApiEntrypointNormalizer(
Expand Down Expand Up @@ -1096,10 +1098,6 @@ public function register(): void

private function registerMcp(): void
{
if (!class_exists(McpController::class)) {
return;
}

$this->app->singleton(Registry::class, static function (Application $app) {
return new Registry(
null, // event dispatcher (todo)
Expand Down
3 changes: 2 additions & 1 deletion src/Laravel/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"api-platform/json-schema": "^4.3",
"api-platform/jsonld": "^4.3",
"api-platform/metadata": "^4.3",
"api-platform/mcp": "^4.3",
"api-platform/openapi": "^4.3",
"api-platform/serializer": "^4.3",
"api-platform/state": "^4.3",
Expand All @@ -56,6 +55,7 @@
"require-dev": {
"api-platform/graphql": "^4.3",
"api-platform/http-cache": "^4.3",
"api-platform/mcp": "^4.3",
"doctrine/dbal": "^4.0",
"larastan/larastan": "^2.0 || ^3.0",
"laravel/sanctum": "^4.0",
Expand Down Expand Up @@ -86,6 +86,7 @@
"suggest": {
"api-platform/graphql": "Enable GraphQl support.",
"api-platform/http-cache": "Enable HTTP Cache support.",
"api-platform/mcp": "Enable MCP (Model Context Protocol) support for AI agents.",
"phpstan/phpdoc-parser": "To support extracting metadata from PHPDoc."
},
"extra": {
Expand Down
1 change: 1 addition & 0 deletions src/Mcp/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"api-platform/metadata": "^4.3",
"api-platform/json-schema": "^4.3",
"mcp/sdk": "^0.4.0",
"symfony/object-mapper": "^7.4 || ^8.0",
"symfony/polyfill-php85": "^1.32"
},
"require-dev": {
Expand Down
Loading