mako / mcp
MCP package for the Mako Framework
Requires
- php: >=8.5.0
- mako/framework: ^13.0.0@dev
- mcp/sdk: ^0.8.1
- psr/container: ^2.0
- symfony/finder: ^7.4 || ^8.1
Requires (Dev)
- mockery/mockery: ^1.6
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^13.3
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-14 18:22:44 UTC
README
MCP (Model Context Protocol) package for the Mako Framework.
The package is built on top of the official MCP PHP SDK and makes it easy to expose tools, resources and prompts from your Mako application.
Requirements
- Mako ^13.0
Installation
Install the package using the following composer command:
composer require mako/mcp
Next, publish the package configuration to your application using the following reactor command:
php app/reactor package:install mako/mcp
Finally, add the package to the list of packages in your app/config/application.php file:
return [ // ... 'packages' => [ 'cli' => [ mako\mcp\McpPackage::class, ], ], // ... ];
Register the package under
cliif you only want to serve the MCP server overstdio, underwebif you only want to serve it over HTTP, or undercoreif you want to be able to serve it over both.
Usage
The MCP server can be run over stdio using the included reactor command or over HTTP using a controller.
Defining tools, resources and prompts
Tools, resources and prompts are automatically discovered, so all you have to do is create your classes and decorate the methods with the appropriate attributes from the MCP PHP SDK:
<?php namespace app\mcp\tools; use Mcp\Capability\Attribute\McpTool; use function rand; class WeatherTool { #[McpTool(name: 'get_weather', description: 'Get the current weather for a city')] public function getWeather(string $city): array { return ['city' => $city, 'temperature' => rand(-30, 30), 'unit' => 'celsius']; } }
The directories that are scanned during auto discovery can be configured in the published package configuration file.
Visual Studio Code
To use the MCP server with Visual Studio Code, add the following to your .vscode/mcp.json file:
{
"servers": {
"mako-app": {
"type": "stdio",
"command": "php",
"args": [
"${workspaceFolder}/app/reactor",
"mcp:server"
]
}
}
}
HTTP
Serving the MCP server over HTTP requires the PSR HTTP message bridge package along with a PSR-7 and PSR-17 implementation such as nyholm/psr7:
composer require mako/psr-http-message-bridge nyholm/psr7
Sessions are stored using the cache when serving the MCP server over HTTP, so make sure that the CacheService is enabled in the services section of your app/config/application.php file.
You can then serve the MCP server from a controller. Note that the following example demonstrates basic usage without authentication or any other security measures, so make sure to secure the endpoint before exposing it publicly:
<?php namespace app\http\controllers; use mako\bridges\psr\http\message\MakoResponseHydrator; use mako\bridges\psr\http\message\PsrServerRequestFactory; use mako\http\Request; use mako\http\Response; use Mcp\Server; use Mcp\Server\Transport\StreamableHttpTransport; use Nyholm\Psr7\Factory\Psr17Factory; class Mcp { public function __invoke(Request $request, Response $response, Server $server): void { $psr17Factory = new Psr17Factory; $factory = new PsrServerRequestFactory( serverRequestFactory: $psr17Factory, uriFactory: $psr17Factory, streamFactory: $psr17Factory, uploadedFileFactory: $psr17Factory ); $psrRequest = $factory->create($request); $psrResponse = $server->run(new StreamableHttpTransport($psrRequest)); new MakoResponseHydrator()->hydrate($response, $psrResponse, stream: true); } }
Finally, register a route for it in your app/http/routing/routes.php file:
<?php use app\http\controllers\Mcp; $routes->all('/mcp', Mcp::class);