Expose your CakePHP application functionality via the Model Context Protocol (MCP).
- Overview
- Features
- Installation
- Quick Start
- Configuration
- Creating MCP Tools
- Built-in Tools
- Running the Server
- Discovery Caching
- Testing
- Contributing
- License
Synapse is a CakePHP plugin that implements the Model Context Protocol (MCP), allowing AI assistants and other MCP clients to interact with your CakePHP application through a standardized interface.
Warning
This plugin uses the MCP PHP SDK which is currently in active development. Features and APIs may change as the SDK evolves.
The Model Context Protocol is an open protocol that enables seamless integration between AI assistants (like Claude) and your application's data and functionality. With Synapse, you can expose:
- Tools: Functions that AI assistants can call (e.g., database queries, route inspection)
- Resources: Data sources that can be read (coming soon)
- Prompts: Pre-configured templates for common tasks (coming soon)
- 🚀 Easy Integration: Add MCP capabilities to your CakePHP app in minutes
- 🔍 Auto-Discovery: Automatically discovers MCP elements using PHP 8 attributes
- 🛠️ Built-in Tools: Pre-built tools for system info, database inspection, and route management
- 📚 Documentation Search: Full-text search powered by SQLite FTS5 with BM25 ranking (indexes CakePHP's official markdown documentation)
- 📦 Extensible: Create custom tools using simple PHP attributes
- PHP 8.2 or higher
- CakePHP 5.2 or higher
Install via Composer as a development dependency:
composer require --dev josbeir/cakephp-synapseNote
This plugin is typically used as a development tool to allow AI assistants to interact with your application during development. It should not be installed in production environments.
cake plugin load --only-cli --optional Synapse The plugin will automatically register itself and discover MCP elements in your application.
-
Install the plugin (see above)
-
Start the MCP server:
bin/cake synapse server-
Connect an MCP client (like Claude Desktop or another MCP-compatible tool) to
stdiotransport -
Try it out - The AI assistant can now:
- Query your database schema
- Inspect routes
- Read configuration
- And more!
Create a configuration file at config/synapse.php:
<?php
return [
'Synapse' => [
// Server information sent to MCP clients
'serverInfo' => [
'name' => 'My App MCP Server',
'version' => '1.0.0',
],
// MCP protocol version
'protocolVersion' => '2024-11-05',
// Discovery settings
'discovery' => [
'scanDirs' => ['src', 'plugins'],
'excludeDirs' => ['tests', 'vendor', 'tmp'],
],
],
];You can also configure using environment variables:
MCP_SERVER_NAME="My App MCP Server"
MCP_SERVER_VERSION="1.0.0"
MCP_PROTOCOL_VERSION="2024-11-05"Create custom tools by adding the #[McpTool] attribute to public methods:
<?php
namespace App\Mcp;
use Mcp\Capability\Attribute\McpTool;
class MyTools
{
#[McpTool(
name: 'get_user',
description: 'Fetch a user by ID'
)]
public function getUser(int $id): array
{
$usersTable = $this->fetchTable('Users');
$user = $usersTable->get($id);
return [
'id' => $user->id,
'email' => $user->email,
'name' => $user->name,
];
}
#[McpTool(name: 'list_users')]
public function listUsers(int $limit = 10): array
{
$usersTable = $this->fetchTable('Users');
$users = $usersTable->find()
->limit($limit)
->toArray();
return [
'total' => count($users),
'users' => $users,
];
}
}The plugin will automatically discover these tools and make them available to MCP clients.
Tools support typed parameters with automatic validation:
#[McpTool(name: 'search_articles')]
public function searchArticles(
string $query,
int $limit = 20,
bool $publishedOnly = true
): array {
// Implementation
}Synapse includes several built-in tools for common operations:
Access system information and configuration:
system_info- Get CakePHP version, PHP version, debug mode, etc.config_read- Read configuration valuesdebug_status- Check if debug mode is enabled
Inspect and query your database:
list_connections- List all configured database connectionsdescribe_schema- Get detailed schema information for tables- View all tables in a connection
- Inspect columns, constraints, indexes
- Understand foreign key relationships
Inspect and analyze your application routes:
list_routes- List all routes with filtering and sortingget_route- Get detailed information about a specific routematch_url- Find which route matches a given URLreverse_route- Generate URLs from route names or parametersdetect_route_collisions- Find potential route conflicts
Search CakePHP documentation with full-text search powered by SQLite FTS5:
search_docs- Search documentation with relevance ranking, fuzzy matching, and filteringdocs_stats- View index statistics and available sourcesdocs://search/{query}- Resource for accessing formatted search results
Note
Documentation is indexed from the official CakePHP markdown documentation. The index is built locally using SQLite FTS5 for fast, dependency-free full-text search.
Use the CLI to manage and search the index:
# Index all sources
bin/cake index_docs
# Index specific source
bin/cake index_docs --source cakephp-5x
# Force re-index and optimize
bin/cake index_docs --force --optimize
# Search documentation from CLI
bin/cake search_docs "authentication"
# Search with options
bin/cake search_docs "database queries" --limit 5 --fuzzy --detailedStart the MCP server using the CLI command:
# Start with default settings (stdio transport)
bin/cake synapse server
# Start with verbose output
bin/cake synapse server --verbose
# Enable logging to debug log engine
bin/cake synapse server --log debug
# Disable caching and enable logging
bin/cake synapse server --no-cache --log debug
# View help
bin/cake synapse server --help--transport,-t- Transport type (currently onlystdiois supported)--log,-l- Enable MCP server logging to specified log engine (e.g.,debug,error)--no-cache,-n- Disable discovery caching for this run--clear-cache,-c- Clear discovery cache before starting--verbose,-v- Enable verbose output--quiet,-q- Suppress all output except errors
Currently, Synapse supports:
- stdio - Standard input/output (default, recommended for most MCP clients)
Future versions may include HTTP/SSE transport.
To connect Claude Desktop or other MCP clients:
- Configure the client to use stdio transport
- Point it to your CakePHP bin directory:
/path/to/your/app/bin/cake synapse server - The client will communicate with your app via the MCP protocol
Example IDE/Tool configuration (VSCode/Claude/Zed/...)
{
"my-cakephp-app": {
"command": "bin/cake",
"args": ["synapse", "server"]
}
}Or run inside your DDEV instance
{
"cakephp-synapse": {
"command": "ddev",
"args": ["cake","synapse","server"],
}
}The MCP server supports PSR-3 logging via CakePHP's logging system. This logs server activity including discovery, protocol messages, and handler execution.
Use the --log option to enable logging to any configured log engine:
# Log to 'debug' log engine
bin/cake synapse server --log debug
# Log to 'error' log engine
bin/cake synapse server --log error
# Log to custom engine
bin/cake synapse server --log mcpConfigure your log engines in config/app.php:
'Log' => [
'debug' => [
'className' => 'File',
'path' => LOGS,
'file' => 'debug',
'levels' => ['notice', 'info', 'debug'],
'scopes' => false,
],
'mcp' => [
'className' => 'File',
'path' => LOGS,
'file' => 'mcp',
'levels' => ['notice', 'info', 'debug', 'error', 'warning'],
],
],When logging is enabled, the MCP server logs:
- Server startup and initialization
- Discovery process and found elements
- Protocol messages (requests/responses)
- Tool/resource handler execution
- Errors and warnings
This is useful for debugging and understanding how your MCP server interacts with clients.
Discovery caching dramatically improves server startup performance by caching the discovered MCP elements (tools, resources, prompts). This can reduce startup time by up to 99%!
Note
While caching improves performance, remember that this plugin is intended for development use. The caching feature is most useful when running the MCP server frequently during development sessions.
Synapse uses CakePHP's built-in PSR-16 cache system. Configure caching in config/synapse.php:
return [
'Synapse' => [
'discovery' => [
'scanDirs' => ['src', 'plugins/Synapse/src'],
'excludeDirs' => ['tests', 'vendor', 'tmp', 'logs', 'webroot'],
// Cache configuration (defaults to 'default')
'cache' => 'default', // or 'mcp', or any cache config name
],
],
];Or use an environment variable:
# Use default cache engine
MCP_DISCOVERY_CACHE=default
# Use a custom cache engine
MCP_DISCOVERY_CACHE=mcp# Disable caching for this run
bin/cake synapse server --no-cache
bin/cake synapse server -n
# Clear cache before starting
bin/cake synapse server --clear-cache
bin/cake synapse server -c
# Combine options
bin/cake synapse server --clear-cache --verbose- Without cache: ~100-500ms startup time (depending on codebase size)
- With cache: ~1-5ms startup time (99% improvement!)
- Recommendation: Enable caching for faster startup times during development
Run the test suite:
# Run all tests
composer test
# Run with coverage
composer test-coverage
# Run PHPStan analysis
composer phpstan
# Check code style
composer cs-check
# Fix code style
composer cs-fixContributions are welcome! Please follow these guidelines:
- Code Standards: Follow CakePHP coding standards
- Tests: Add tests for new features
- PHPStan: Ensure level 8 compliance
- Documentation: Update README for new features
# Clone the repository
git clone https://github.com/josbeir/cakephp-synapse.git
cd synapse
# Install dependencies
composer install
# Run tests
composer test
# Run static analysis
composer phpstanThis plugin is open-sourced software licensed under the MIT license.
- Built with CakePHP
- Implements Model Context Protocol
- Uses the MCP PHP SDK
Note
The MCP PHP SDK is in active development and APIs may change.