Insights
Connect your AI agent to Flare to automatically fix production and performance problems in PHP and Laravel projects
You can now use our MCP server to connect your AI agent to Flare. This way your AI has all context it needs to diagnose and fix production and performance problems of your PHP, JavaScript and Laravel projects.
In this blog post I’d like to tell you how you can use it, and how it works under the hood.
Fix production and performance problems automatically using AI
In case you don't know us yet: Flare is an exception and performance monitoring service. It collects all exceptions and performance data form PHP, JS and Laravel projects. We offer a beautiful UI that helps you and all your fellow humans to analyse and diagnose erros and performance problems.
MCP (Model Context Protocol) is a standardized way for AI models to connect with external data sources and tools.
Through Flare's MCP server, AI can now fetch all information about exceptions that happen on production and use that information to fix the bugs locally.
With the Flare MCP server, you can ask your AI assistant to:
- "Show me the latest errors from my project"
- "Fix the error regarding the PHP syntax error in myfile.php"
- "Mark the error as resolved in Flare"
- "Fix error ERROR-ID-HERE and mark the error as resolved"
- "Show me all slow routes in my app"
- "Create a note in Flare with the results of your investigation about this error"
Personally, I use Claude Code as my little AI programmer helper. Using our MCP server, Claude Code can connect to Flare and fetch all the context around an error.
Here I asked Claude Code fetch the information about the latest exception in Flare for the project, and then I asked the AI to fix it.
After half a minute, the Claude Code made the correct fix.
Recently, we also added performance monitoring to Flare. Flare knows all the runtimes of your requests, jobs, commands, jobs, ... all that good stuff.
The AI can use of all that info to analyse the performance.
Mailcoach is another SaaS we've built, which is also monitored via Flare. Here we asked Claude Code to analyse the performance of the Mailcoach API.
Pretty sweet, right!
Our MCP server can also mark errors as resolved (the AI will probably automatically do this after you’ve instructed it to fix an error 😀). We show this in our AI as well.
Using our MCP server
We’ve added a dedicated page in our docs with instructions how to use our MCP server with Claude Code and Junie.
If you use an other AI agent, the installation process will likely be very similar.
How does it work under the hood
Flare is powered by PHP and Laravel. There seems to be many great MCP libraries in development. For now, we settled on using php-mcp/laravel.
Using that package it’s possible to create a tool. Very simply set, a tool is a piece of code that the AI can use to fetch live data. In our case, we’ve created a tool to fetch error data.
Here is the entire search_errors
tool that the AI can use.
namespace App\Http\Mcp;
use App\Domain\Project\Models\Project;
use App\Http\Api\Resources\Data\ErrorApiData;
use App\Http\Mcp\Concerns\LogsMcpUsage;
use App\Support\Search\ErrorSearch;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
use Spatie\LaravelData\PaginatedDataCollection;
class SearchErrorsTool
{
use AuthorizesRequests;
use LogsMcpUsage;
/**
* Search for errors in a specific project. By default, the search query will be is:unresolved, showing you the errors that are not resolved in this project. You can pass a plain string to the query parameter and we'll use it as best we can in the error message, class... In combination with the string, you can also add these to the query parameter string to scope the search
* - class:QueryException -> filters all QueryException errors or occurrences
* - job:App\Jobs\DownloadVideo -> filters all errors or occurrences triggered by the DownloadVideo job
* - priority:medium -> filters all errors with a medium priority
* - first_seen_at:2020-05-16 -> filters all errors which were first seen on May 16th, 2020
* - is:unresolved -> only unresolved errors will be shown
* - is:resolved -> only resolved errors will be shown
* - is:unsnoozed -> only unsnoozed errors will be shown
* - is:snoozed -> only snoozed errors will be shown
* - is:recent -> only errors which were seen in the last 24 hours will be shown
* - is:handled -> only errors which were marked as handled will be shown
* - is:unhandled -> only errors which were not marked as handled will be shown
* - type:web -> Filter errors or occurrences by the type of entry point which triggered them. Can be web, job, command
* - url:https://flareapp.io -> filters all errors or occurrences triggered on the Flare website
* - user_email:[email protected] -> filters all errors or occurrences triggered by the user with email [email protected]
*
* @param string|int $projectId The id of the project to search errors for
* @param string $searchQuery The search query, do NOT put the project id here, but pass it to the projectId parameter of the tool
* @param int $perPage The number of errors to return per page
* @return array|mixed[]
*/
public function execute(string|int $projectId, string $searchQuery = 'is:unresolved', int $perPage = 25, int $page = 1)
{
$project = Project::query()->findOrFail($projectId);
$this->authorize('see', $project);
$this->logMcpUsage($project);
$errorSearch = new ErrorSearch;
$builder = $errorSearch->getBuilder($project, $searchQuery);
$errors = $builder->jsonPaginate($perPage);
return ErrorApiData::collect(
items: $errors,
into: PaginatedDataCollection::class
)->wrap('data')->toArray();
}
}
Let’s go over this. The class starts with a big block of comment explaining what the tool does and how the parameters can be used. This information will be seen by AI when connecting to the MCP server. So this docblock is basically the manual for AI on how to use the tool.
You might wonder how security is handled. The AI can’t read our DB directly because the AI itself does not run on our server, it runs on your computer (or on the servers of your favorite AI service). The AI simply performance requests to our MCP endpoint, and all request must be authenticated by a valid API token.
Because we leverage token based authenticated, we can simply keep on using Laravel’s authorization capabilities and make a policy check.
$this->authorize('see', $project);
Because we want to know how people are using our MCP server, we also log all usage
$this->logMcpUsage($project);
In Flare’s web UI, there’s a search field where people can search for errors. On the backend the search is implemented in the ErrorSearch
class. Our MCP server can use the same class for searching.
$errorSearch = new ErrorSearch();
$builder = $errorSearch->getBuilder($project, $searchQuery);
$errors = $builder->jsonPaginate($perPage);
And finally, we return the found errors as JSON to the AI
return ErrorApiData::collect(
items: $errors,
into: PaginatedDataCollection::class
)->wrap('data')->toArray();
In closing
Our MCP server is now in public beta, and we’re looking for people that are willing to help us test it. If you don’t have a Flare account yet, you can create one for free (we have a 10 day trial).
We consider this feature still beta and might change it in the future. Like said above, there are several MCP packages for PHP projects in development, we might swap out our current one if a better one comes along. Also, with MCP servers getting popular there are also several opinons on how it should be built up and which responses it should return. Here's an interesting blog post on that subject.
Several of our close friends have already been using our MCP servers for some time, and reported good results. I hope you'll like using Flare's MCP capabilities as well.
Continue reading
Lessons from the deep end
20 months ago, we started building Performance Monitoring as Flare’s next big feature, never expecting Laravel’s rapid commercial growth to put us in direct competition with their own tools. This is our honest take on those 20 months went, how we’re adapting to this new reality, and where we’re heading next while staying true to who we are. A dive into the deep end, without knowing how far down it goes.
Alex
Using ClickHouse at Flare to aggregate data
We're building the next chapter of Flare with performance monitoring, in this first chapter we take a look at aggregating data with a new database called ClickHouse
Ruben
Subscribe to Backtrace, our quarterly Flare newsletter
No spam, just news & product updates