CakeDC Blog

TIPS, INSIGHTS AND THE LATEST FROM THE EXPERTS BEHIND CAKEPHP

Upgrading to CakePHP 4

As you know, CakePHP announced the version 4.x last December.I recommend that you consider upgrading your applications to the next version, to keep up to date and get all the benefits. Now, let's see how to bake!

 

Step 1: Upgrade PHP

First things first, if you are not running on PHP 7.2 or higher, you will need to upgrade PHP before updating CakePHP. CakePHP 4.0 requires a minimum of PHP 7.2.

 

Step 2: Upgrade Templates and Resources

There is an upgrade CLI tool for rename and moving the templates and resources:

 

Templates and Resources must have been moved and renamed, check the result below:

* This project doesn't have Resources files

 

Now, let's create a new constant for Resources on /config/paths.php:

Finally, update the paths on config/app.php:

 

Step 3: Upgrade CakePHP

The next step is optional (and the Migration Guide included this) - run the rector command to automatically fix many deprecated method calls:

The rector applied on codebase some return type declarations:

https://github.com/rafaelqueiroz/cakephp-upgrade-sample/commit/d7e5c2ecc5dc28045700a270721f07098a8e189c?branch=d7e5c2ecc5dc28045700a270721f07098a8e189c&diff=split

Pay attention: It is important to apply rector before you upgrade your dependencies.

 

Upgrade CakePHP and PHPUnit:

PHPUnit can be upgraded easily. Most of the time, the --update-with-dependencies doesn’t work with me for CakePHP:

The root of the issue is the packages using Caret Version Range, so let’s update debug_kit, migrations and bake using editor:

 

Here we go:

 

Now, let see how the project looks:

Here, we have few deprecations and warnings. Do you remember I mentioned the rector is optional? So, the question is the rector and it's not always able to handle these issues.

 

I will use the PHPStan to fix this - we will install with composer:

Now, we can run the phpstan analyse and fix the issues:

 

It's up to you how much effort you will put in with PHPStan issues. I recommend fixing everything. For this post, I did fix only what was needed to run the project after the update, you can check the fixes on this commit.

 

After the last fixes, the project is running well: 

That’s all? No. But we upgraded CakePHP? Yes.

Real applications probably use many plugins, and if these plugins don't have a version for CakePHP 4, you will need to update. Depending on the size and level of complexity of the project, the upgrade could be hard, but never impossible. 

 

If you do not feel confident or your company would like to outsource support for this, don't hesitate to contact us at Cake Development Corporation.

Our team is offering a full upgrade from CakePHP 2/3 to CakePHP 4. This will be a migration of your current application code to make it compatible with CakePHP 4 features, plugins, security settings, etc. We will be doing these migration services for a special rate - something we have never done before! Learn more about our Upgrade Services

You can check the codebase of the examples on this repository. The branch upgrade has all steps by commit. 

With every release CakePHP gets better, and version 4.x is no exception. There are many benefits that come with upgrading, and it makes baking a lot easier.

Latest articles

CakePHP and the Power of Artificial Intelligence

This article is part of the CakeDC Advent Calendar 2025 (December 2th 2025)

Bringing smart automation to modern web development

When we talk about Artificial Intelligence today, we are not talking about the future, we are talking about tools we already use every day, such as our phones, code editors, browsers and productivity apps. For developers, AI represents a new wave of innovation that allows us to embed intelligence directly into our projects to build smarter, more adaptive, and more valuable digital products. At CakeDC, we’ve been exploring how CakePHP 5 can be seamlessly integrated with AI to deliver powerful, automated, and intelligent solutions.

Why combine CakePHP and AI?

Both technologies share a core philosophy: efficiency and structure. CakePHP offers a clean MVC framework, robust validation, and an ORM that keeps your data organized and secure. On the other hand, AI brings reasoning, summarization, and contextual understanding to your application. By combining them, we can:
  • Automate repetitive processes.
  • Enhance user experience.
  • Add value to existing products.
  • Unlock new opportunities for digital innovation.
The result? Smarter apps with a strong core.

What AI means today

AI enhances productivity not by replacing people, but by amplifying human capabilities. It helps analyze data, generate content, automate workflows, and make better decisions faster. And thanks to APIs like OpenAI’s, this power is now accessible to every PHP developer. Imagine a world where your CakePHP app can:
  • Understand natural language input.
  • Summarize uploaded reports.
  • Classify customer feedback.
  • Generate tailored content or recommendations.
That work is already here.

Real use cases with CakePHP + AI

Here are some real examples of how we’re integrating AI into CakePHP projects:
  • Document upload with automatic summaries or data extraction.
  • Customer support chatbots directly embedded in web portals.
  • Image analysis for quality control or content tagging.
  • Smart products or content recommendations.
  • Automated reporting and document generation.
Each of these features leverages the same clean CakePHP architecture (controllers, services, and models) combined with a simple AI API call.

Technical integration made simple

Here’s how easy it is to call an AI model directly from your CakePHP app: use Cake\Http\Client; $http = new \http\Client(); $response = $http->post( 'https://api.openai.com/v1/chat/completions', [ 'model' => 'gpt-4o-mini', 'messages' => [ ['role' => 'system', 'content' => 'You are an assistant.'], ['role' => 'user', 'content' => 'Summarize this text...'], ], ], [ 'headers' => [ 'Authorization' => 'Bearer ' . Configure::Read('OPENAI_API_KEY'), 'Content-Type' => 'application/json', ], ], ); $result = $response->getJson(); From there, you simply parse the JSON response, store or display the data, and integrate it into your workflow. The simplicity of CakePHP’s Http Client makes this process smooth and reliable.

Challenges and best practices

As with any emerging technology, integrating AI comes with responsibilities and considerations:
  • Manage API costs efficiently by batching requests or caching responses.
  • Respect user privacy and comply with GDPR, especially when handling sensitive data.
  • Implement robust error handling and retry logic for API calls.
  • Log and monitor AI interactions for transparency and quality assurance.
  • Use AI responsibly — as a tool to empower developers and users, not to replace them.

Looking ahead

The combination of CakePHP and AI opens exciting possibilities for the next generation of web applications: fast, smart, and secure. AI is not a replacement, it’s an enhancement. And with CakePHP’s solid foundation, developers can bring these intelligent capabilities to life faster than ever. This article is part of the CakeDC Advent Calendar 2025 (December 2th 2025)

The CakeDC Advent Calendar is BACK!

It’s the most wonderful time of the year! I don’t just mean the holidays… I’m talking about the CakeDC Advent Calendar!    If you missed it last year, we put together a series of blog posts in the form of a holiday advent calendar. Each day, you will get to open the gift of a new article written by one of our team members. You can wake up every morning in December with Cake(PHP). Does it get any better?    So what can you expect this year?  Great topics like: 

  • CakePHP upgrades
  • Security tips
  • CakePHP and the power of AI
  • Supabase + CakePHP
  • CakePHP Horizontal Scaling
  • CakePHP and FrankenPHP
  • Advanced Exports in CakePHP 5
  • + so much more! 

  Enjoy our gift to you that lasts the whole month through (maybe I should write poems instead of blogs?).    While you wait, here are some links from last year’s calendar to hold you over: https://www.cakedc.com/yevgeny_tomenko/2024/12/21/cakedc-search-filter-plugin   https://www.cakedc.com/ajibarra/2024/12/12/almost-20-years-a-bit-of-history-about-cakephp   https://www.cakedc.com/jorge_gonzalez/2024/12/20/5-cakephp-security-tips
  See you tomorrow! 

CakePHP AI Integration: Build a CakePHP MCP Server with Claude

Learn how to build a CakePHP MCP server (local) for AI integration.

Intro

Unless your crew left you stranded on a desert island earlier this year, I'm sure you've heard about every big name in the industry integrating their applications and exposing their data to "agents". Model Context Protocol https://modelcontextprotocol.io/docs/getting-started/intro was created to define how the your application could interact and provide features to Agents. These features could be readonly, but also methods (or tools) to allow the Agent operate with your application, for example, creating orders, updating post titles, reordering invoices, or creating reports for your bookings. As a developer, this is a quick win! Providing access, even readonly, could expand the quality of the interaction between your users and your application. In my opinion, the benefits are: Agents deal with context very well, they can use the conversation history, and also extract required data to use the available tools. Agents can transform the data, providing "features" to your users that you didn't implement. For example building charts on the fly, or creating scripts to transform the data for another tool. Quickly after the publication of the MCP protocol, the PHP community started working on a standarized SDK to help with the implementation of MCP servers. Even if the SDK is in active development right now, we are going to explore it and build a local MCP server, connecting Claude Desktop to it. The idea behind the example is to open your application to Claude Desktop, so the Agent (Claude) can connect directly to your code using the specified tools. For production environments, there are many other considerations we should be handling, like authorization, rate limiting, data exchange and privacy, etc. We'll leave all these production grade issues for another day and jump into an example you can implement "today" in your CakePHP application. Development vs. Production: This tutorial focuses on a local development setup for your CakePHP MCP server. Production environments require additional considerations including:
  • Authentication and authorization
  • Rate limiting
  • Data privacy and security
  • Audit logging
  • Input validation and sanitization
  • Error handling and monitoring

What is a CakePHP MCP Server?

A CakePHP MCP server is a specialized implementation that allows AI agents like Claude to interact with your CakePHP application through the Model Context Protocol. This CakePHP AI integration creates a bridge between your application logic and AI capabilities, enabling:
  • Natural language interfaces for complex queries
  • Automated content generation and management
  • Real-time data analysis and reporting

Prerequisites

Before starting, ensure you have:
  • PHP 8.1 or higher
  • Composer
  • SQLite or MySQL
  • Claude Desktop (free tier available)

Step 1: Set Up the CakePHP CMS Application

We'll use the official CakePHP CMS tutorial. # Clone the repository git clone https://github.com/cakephp/cms-tutorial cd cms-tutorial # Install dependencies composer install # Run database migrations bin/cake migrations migrate # Start the development server bin/cake server

Create a Test User

  1. Navigate to http://localhost:8765/users/add
  2. Create a new user with your preferred email and password
  3. Log in at http://localhost:8765/users/login
  4. Verify you can create an article via http://localhost:8765/articles/add

Step 2: Install Claude Desktop

Download and install Claude Desktop from https://claude.com/download

Step 3: Install the CakePHP MCP Plugin

To build your CakePHP MCP server, install the MCP utility plugin and SDK in your CakePHP project: composer require cakedc/cakephp-mcp:dev-2.next-cake5 mcp/sdk:'dev-main#4b91567' Note: These packages are in active development.

Step 4: Create the CakePHP MCP Server Script

Create a new file bin/mcp to initialize your CakePHP MCP server: #!/usr/bin/env sh cd /absolute/path/to/your/cms-tutorial && php vendor/cakedc/cakephp-mcp/bin/mcp-server Important: Replace /absolute/path/to/your/cms-tutorial with your actual project path. For example: /home/user/cms-tutorial or C:\Users\YourName\cms-tutorial Make the script executable: chmod +x bin/mcp

Step 5: Create Your First CakePHP MCP Tool

Create the file: src/Mcp/Articles.php <?php namespace App\Mcp; use App\Model\Entity\Article; use Cake\ORM\Locator\LocatorAwareTrait; use Mcp\Capability\Attribute\McpTool; class Articles { use LocatorAwareTrait; #[McpTool(name: 'createArticle')] public function createArticle(string $title, string $body): array { try { $article = new Article([ 'title' => $title, 'body' => $body, 'user_id' => $this->fetchTable('Users')->find()->firstOrFail()->id, // a default user ID for simplicity ]); if (!$this->fetchTable('Articles')->save($article)) { return [ 'success' => false, 'message' => 'Failed to create article: ' . json_encode($article->getErrors()), ]; } return [ 'success' => true, 'message' => 'Article created successfully', ]; } catch (\Throwable $e) { return [ 'success' => false, 'message' => 'Exception to create article: ' . $e->getMessage(), ]; } } } The #[McpTool] Attribute: This PHP 8 attribute registers the method as an MCP tool that Claude can discover and use in your CakePHP AI integration. The name parameter defines how Claude will reference this tool. Simplified User Assignment: For demonstration purposes, we're using the first available user. In production CakePHP AI integrations, you'd implement proper user authentication and context.

Step 6: Configure Claude Desktop for CakePHP MCP Integration

Add your CakePHP MCP server to Claude Desktop's configuration:
  1. Open Claude Desktop
  2. Go to Settings → Developer → Edit Config
  3. Add your MCP server configuration:
{ "mcpServers": { "cakephp-cms": { "command": "/absolute/path/to/your/cms-tutorial/bin/mcp" } } }
  1. Save the configuration and restart Claude Desktop

Step 7: Test Your CakePHP AI Integration

Once Claude Desktop restarts, you should see your CakePHP MCP server connected:
  1. MCP Server Connected: Look for the server indicator in Claude Desktop showing your CakePHP MCP integration is active
  2. Available Tools: You can view available CakePHP MCP tools by clicking the tools icon
  3. The createArticle tool: Should appear in the list of available tools
  4. Now you can use the Claude Desktop prompt to generate articles, that will be saved directly into your CakePHP application!

Wrapping up

You've successfully built a CakePHP MCP server and implemented CakePHP AI integration with Claude! This Model Context Protocol CakePHP implementation opens up powerful possibilities for AI-enhanced user experiences and automation in your web applications.

We Bake with CakePHP