Setting Up MCP with Symfony and Connecting It to Gemini Spark
What if you could ask Gemini questions about your application's real business data without building a dedicated AI agent or exposing your database directly?
For example:
"How many downloads did we get this month?"
Or:
"How many prospects contacted us this week?"
Or even:
"Compare this month's downloads with last month's and remind me every Monday to check the numbers."
This is exactly the kind of workflow I recently experimented with by combining Symfony MCP and Gemini Spark.
The idea is simple:
The interesting part is that I didn't need to build a complete AI agent with an API key myself. Symfony exposes the application's capabilities through MCP, and Gemini Spark becomes the interface through which I interact with them.
Why MCP?
The Model Context Protocol (MCP) is an open standard that allows AI applications to connect to external tools and data sources through a standardized protocol.
Instead of creating a custom integration for every AI product, your application exposes an MCP server.
An MCP client can then discover the capabilities exposed by your application and use them when needed.
Those capabilities can include:
- Tools — actions the AI can call.
- Resources — information the AI can retrieve.
- Prompts — predefined instructions or workflows.
Symfony provides an official integration through the Symfony AI MCP Bundle, which supports MCP servers over HTTP and STDIO.
For this project, I was mainly interested in tools.
The use case: StockPro Business Data
I already have a website around StockPro, my inventory management software.
The website collects and stores different types of business data, such as:
- software downloads;
- prospects;
- feedback;
- license information;
- website activity;
- marketing-related information.
I wanted to make this information accessible to an AI assistant.
But I didn't want to build a complete chatbot, authentication system, AI orchestration layer, conversation memory and scheduling system just for that.
Instead, I decided to expose selected business capabilities through an MCP server.
The result is much simpler:
Gemini can then decide which tool is relevant to a question and use the returned information to formulate an answer.
1. Installing the Symfony MCP Bundle
The first step is to install the official Symfony MCP Bundle:
The Symfony MCP Bundle integrates the official MCP SDK into Symfony.
The nyholm/psr7 package provides the PSR-7/PSR-17 implementation required by the MCP HTTP layer in this setup.
The official Symfony documentation currently recommends installing the MCP Bundle with:
and configuring the MCP route afterward.
2. Exposing an MCP Endpoint
The MCP route can be registered in config/routes.yaml:
Then we configure the MCP server in:
A simplified configuration looks like this:
This gives us an HTTP endpoint such as:
The MCP Bundle supports both HTTP and STDIO transports, so the same Symfony application can be used by local clients or remote clients.
3. Be Careful with Symfony Security
There is an important detail when exposing an MCP server from an existing Symfony application.
If your application already has a traditional authentication firewall, the MCP request can accidentally be redirected to your login page.
Instead of returning MCP's JSON response, Symfony could return:
From the perspective of an MCP client, this obviously breaks the connection.
The MCP endpoint therefore needs to be handled appropriately by Symfony Security.
For example:
For a production system, I would not simply leave a sensitive MCP endpoint unprotected.
The important idea is that MCP authentication should be handled deliberately, using an appropriate authentication mechanism for your environment.
The current Symfony MCP documentation also supports using Symfony Security rules to control access to MCP endpoints.
4. Creating the First MCP Tool
This is where things become interesting.
Symfony lets us expose regular PHP services as MCP capabilities using PHP attributes.
For example:
The important part is this:
The method becomes an MCP tool that an MCP client can discover and call.
The Symfony MCP Bundle automatically discovers MCP capabilities registered through attributes on Symfony services.
5. Connecting the Tool to Real Data
The real value comes from connecting these tools to the application's existing business logic.
For example, instead of returning a hard-coded value, the tool can inject a Doctrine repository:
Now the flow is:
This is one of the things I like most about MCP.
The AI doesn't need direct access to the database.
It receives only the information returned by the tool.
6. Creating More Useful Tools
For my StockPro use case, I can expose several business-oriented tools.
For example:
A tool doesn't necessarily have to represent a database table.
It should represent a useful business capability.
For example, this is often more useful:
than exposing raw database operations.
The goal is to give the AI meaningful operations it can use to answer business questions.
7. Tools, Resources and Prompts
MCP isn't limited to tools.
Symfony's MCP integration supports several MCP capabilities, including:
- Tools
- Resources
- Prompts
- Resource templates
For example, a resource could expose pricing information:
A prompt could provide a predefined analysis workflow:
This gives you a clean separation:
8. Testing the MCP Server
Before connecting an external AI client, it is useful to verify that the server actually works.
Symfony provides a debugging command:
This lets you inspect the MCP capabilities exposed by your configured servers.
You can also test the HTTP endpoint directly with a JSON-RPC request.
For example:
The important thing is to verify that the endpoint responds correctly and that your tools are actually discoverable.
9. Connecting the MCP Server to Gemini Spark
This is where the experiment gets really interesting.
Gemini Spark supports custom applications through MCP server URLs.
Google officially added support for connecting personal or third-party applications to Gemini Spark using their MCP server URLs.
From the Gemini web application, you can add a custom app using its MCP server URL.
In my case, I provided the URL of my Symfony MCP server.
Once connected, Gemini can discover the capabilities exposed by the server.
The important distinction is:
MCP is the bridge between the two.
10. Asking Questions About My Application
Once the connection is established, I can interact with my StockPro data using natural language.
For example:
"How many people downloaded StockPro this month?"
Gemini can use the corresponding MCP tool to retrieve the real number.
I can then ask:
"Compare that with last month."
Or:
"How many of those users became prospects?"
Or:
"What was our best month for downloads this year?"
The important thing is that these answers are based on the data exposed by my application, rather than information that Gemini already knows.
11. The Interesting Part: Scheduled Tasks
This is where Gemini Spark becomes particularly interesting for developers who don't want to build their own AI agent infrastructure.
Gemini Spark supports scheduled tasks and workflows.
Google describes schedules as automated triggers that tell Spark when to execute a task. They can be based on time intervals or certain conditions.
So instead of manually checking my StockPro dashboard every Monday, I can ask Gemini to do something like:
"Every Monday morning, check StockPro's downloads and prospects from the previous week and give me a short business summary."
The workflow becomes:
This is significantly more interesting than simply asking an AI chatbot a question.
You have effectively connected:
your application → your business data → MCP → an external AI agent → scheduled workflows.
12. Why This Is Interesting for Developers
Many developers want to experiment with AI agents but immediately think about building:
- an AI API integration;
- a chat interface;
- conversation history;
- tool calling;
- background jobs;
- scheduling;
- notifications;
- authentication;
- agent orchestration.
That can become a significant project.
MCP changes part of the equation.
Instead of asking:
"How do I build an AI agent that understands my application?"
you can start with:
"What capabilities can my application expose to an AI?"
For a Symfony application, this is especially interesting because your existing services, repositories and business logic can be reused.
You can create an MCP tool around an existing service instead of rebuilding the entire application for AI.
13. MCP Is Not an AI Agent
This distinction is important.
MCP does not replace an AI model.
It provides a standardized way for an AI client to interact with external tools and data.
Think of it like this:
The MCP server is your application's interface to the AI.
Gemini Spark provides the agentic experience on top of that connection.
14. Security Matters
This architecture is powerful, but it also means you are exposing application capabilities to an external AI client.
That should be treated as a security boundary.
Don't expose:
or arbitrary SQL execution.
Prefer narrowly defined business tools:
Also consider:
- authentication;
- authorization;
- input validation;
- rate limiting;
- logging;
- sensitive data filtering;
- least-privilege access;
- read-only tools where possible.
Google explicitly warns that custom MCP servers are third-party systems outside Google's control and recommends connecting only servers you trust. Google also notes that Gemini requires confirmation for write actions from custom connected apps.
This is particularly important when moving from read-only analytics to tools capable of modifying data.
15. What About Developers Without an AI Agent?
This is probably the most interesting lesson from this experiment.
You don't necessarily need to build an AI agent yourself to benefit from an MCP-enabled application.
You can make your application agent-ready.
For example, a Symfony application could expose:
The same application capabilities can potentially be consumed by different MCP-compatible clients.
Symfony's MCP Bundle is designed specifically around this model: a Symfony application can act as an MCP server exposing tools, prompts and resources to clients.
That means your investment is not necessarily tied to one AI provider.
16. My Takeaway
The most interesting part of this experiment wasn't simply connecting Gemini to Symfony.
It was realizing that MCP lets me expose my application's capabilities once and let compatible AI clients consume them.
For StockPro, I didn't have to build a complete AI analytics platform just to ask questions about downloads and prospects.
I exposed the relevant business capabilities through Symfony.
Gemini Spark handles the conversational and agentic side.
The result is a very simple architecture:
And this is where I think MCP becomes particularly valuable for web developers.
Instead of building a separate AI application around every existing project, you can start by making your application understandable and usable by AI clients.
Your existing business logic becomes a set of capabilities that AI agents can discover and use.
Final Thoughts
If you already have a Symfony application with useful business data, I would strongly recommend experimenting with MCP.
Start small.
Don't expose your entire application.
Pick a few meaningful read-only capabilities, such as:
Then connect your MCP server to an MCP-compatible client.
The interesting question is no longer:
"How can I build a chatbot for my application?"
It becomes:
"What could an AI do if it had access to the right capabilities of my application?"
That is a much more interesting question.
And with Symfony MCP, getting started can be surprisingly lightweight.