Symfony application demoing Symfony AI components.
What you need to run this demo:
- Internet Connection
- Terminal & Browser
- Git & GitHub Account
- Docker with Docker Compose Plugin
- Your Favorite IDE or Editor
- An OpenAI API Key
This small demo sits on top of following technologies:
- PHP >= 8.4
- Symfony 8.0 incl. Twig, Asset Mapper & UX
- Bootstrap 5
- OpenAI's GPT & Embeddings
- PostgreSQL with pgvector
- FrankenPHP
The setup is split into three parts, the Symfony application, the OpenAI configuration, and initializing PostgreSQL.
Checkout the repository, start the docker environment and install dependencies:
git clone git@github.com:symfony/ai-demo.git
cd ai-demo
composer install
docker compose up -d
symfony serve -dNow you should be able to open https://localhost:8000/ in your browser, and the chatbot UI should be available for you to start chatting.
Note
You might have to bypass the security warning of your browser with regard to self-signed certificates.
For using GPT and embedding models from OpenAI, you need to configure an OpenAI API key as environment variable.
This requires you to have an OpenAI account, create a valid API key and set it as OPENAI_API_KEY in .env.local file.
echo "OPENAI_API_KEY='sk-...'" > .env.localVerify the success of this step by running the following command:
symfony console debug:dotenvYou should be able to see the OPENAI_API_KEY in the list of environment variables.
PostgreSQL with pgvector is used to store embeddings of the chatbot's context.
To initialize the vector store, you need to run the following command:
symfony console ai:store:setup ai.store.postgres.symfony_blog
symfony console ai:store:index blog -vvNow you should be able to retrieve documents from the store:
symfony console ai:store:retrieve blog "Week of Symfony"Don't forget to set up the project in your favorite IDE or editor.
vendor/bin/phpunit # unit and integration tests
vendor/bin/phpunit --testsuite e2e # end-to-end tests in a real browserThe e2e suite uses Symfony Panther to click through all ten
use cases and assert the Symfony AI panel of the profiler for the very request the click triggered.
Every test calls an AI platform for real, which costs money and takes time - the suite is therefore
excluded from the default one, and meant to be run locally.
Next to the setup above, it needs:
- Chrome or Chromium with a matching
chromedriver, whichvendor/bin/bdi detect driversdownloads intodrivers/. If only a Snap or Flatpak Chromium is installed, point Panther at it withPANTHER_CHROME_BINARYin.env.test.local. - API keys in
.env.local, or exported in your environment - a test is skipped when the key of its use case is missing:OPENAI_API_KEYfor eight of them,HUGGINGFACE_API_KEYfor the image cropping,MISTRAL_API_KEYfor the document OCR. - ffmpeg (optional) to convert the audio fixture for the fake microphone of the speech use case.
The blog store does not need to be indexed beforehand: StoreTest drives the indexing pipeline
through the console commands, and BlogTest sets the store up and indexes it when it is empty. Both
skip themselves when the database is not running.
Panther boots the application in the dev environment, because the profiler - and with it the
Symfony AI panel - only collects data with kernel.debug enabled. The web server therefore reads
the real API keys from .env.local itself. Chrome fakes camera and microphone, so the video and
speech use cases run without a human in front of the screen.
vendor/bin/phpunit --testsuite e2e --filter BlogTest # a single use case
PANTHER_NO_HEADLESS=1 vendor/bin/phpunit --testsuite e2e # watch the browserScreenshots of failing tests are written to var/error-screenshots/.
- The chatbot application is a simple and small Symfony 8.0 application.
- The UI is coupled to a Twig LiveComponent, that integrates different
Chatimplementations on top of the user's session. - You can reset the chat context by hitting the
Resetbutton in the top right corner. - You find three different usage scenarios in the upper navbar.
Demo MCP server exposing a current-time tool and a Movies MCP App — an interactive HTML UI (#[AsMcpApp])
that renders the movie collection as a searchable grid in hosts supporting MCP Apps.
To add the server, add the following configuration to your MCP Client's settings, e.g. your IDE:
{
"servers": {
"symfony": {
"command": "php",
"args": [
"/your/full/path/to/bin/console",
"mcp:server"
]
}
}
}You can test the MCP server by running the following command to start the MCP client:
symfony console mcp:serverWith plain JSON RPC requests
Then, you can initialize the MCP session with the following JSON RPC request:
{ "jsonrpc": "2.0", "id": 1, "method": "initialize", "params": { "protocolVersion": "2024-11-05", "capabilities": {}, "clientInfo": { "name": "demo-client", "version": "dev" } } }And, to request the list of available tools:
{ "jsonrpc": "2.0", "id": 2, "method": "tools/list" }With MCP Inspector
For testing, you can also use the MCP Inspector:
npx @modelcontextprotocol/inspector php bin/console mcp:serverWhich opens a web UI to interactively test the MCP server.
Symfony AI Mate is an MCP (Model Context Protocol) server that provides AI assistants with Symfony-specific development capabilities.
This demo is already configured! For new projects you can set up AI Mate as follows:
# Install AI Mate
composer require --dev symfony/ai-mate
# Initialize configuration
vendor/bin/mate init
# Discover available tools
vendor/bin/mate discoverThe mcp.json file in the project root enables automatic MCP client detection:
{
"mcpServers": {
"symfony-ai-mate": {
"command": "./vendor/bin/mate",
"args": ["serve", "--force-keep-alive"]
}
}
}For other projects, add AI Mate to your MCP client settings (e.g., ~/.claude/mcp.json, IDE settings, etc.).
This demo includes a symfony-ai-features tool (see mate/src/SymfonyAiFeaturesTool.php) that analyzes the project's
AI configuration and reports all available platforms, agents, tools, stores, and packages.
Try it in your MCP-enabled chat:
"Which Symfony AI features are available in this demo?"
"What AI agents are configured in this project?"
"Show me all the Symfony AI tools and their configuration"
"What is the current PHP version used in this project?"
"Is the php extension intl installed?"
The AI assistant will use the symfony-ai-features and other MCP tool to provide detailed information about project
internals.
Create tools in mate/src/ and register them in mate/config.php. See the
AI Mate documentation for detailed guides.
# Test with MCP Inspector
npx @modelcontextprotocol/inspector ./vendor/bin/mate serve