Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .phpstan/ForbidNativeExceptionRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ final class ForbidNativeExceptionRule implements Rule
'Symfony\\AI\\Agent' => 'Symfony\\AI\\Agent\\Exception\\',
'Symfony\\AI\\Platform' => 'Symfony\\AI\\Platform\\Exception\\',
'Symfony\\AI\\Store' => 'Symfony\\AI\\Store\\Exception\\',
'Symfony\\AI\\McpSdk' => 'Symfony\\AI\\McpSdk\\Exception\\',
'Symfony\\AI\\AiBundle' => 'Symfony\\AI\\AiBundle\\Exception\\',
'Symfony\\AI\\McpBundle' => 'Symfony\\AI\\McpBundle\\Exception\\',
];
Expand Down
3 changes: 1 addition & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ Symfony AI monorepo with independent packages for AI integration in PHP applicat
- **Platform** (`src/platform/`): Unified AI platform interface (OpenAI, Anthropic, Azure, Gemini, VertexAI)
- **Agent** (`src/agent/`): AI agent framework for user interaction and task execution
- **Store** (`src/store/`): Data storage abstraction with vector database support
- **MCP SDK** (`src/mcp-sdk/`): Model Context Protocol SDK for agent-tool communication

### Integration Bundles
- **AI Bundle** (`src/ai-bundle/`): Symfony integration for Platform, Store, and Agent
- **MCP Bundle** (`src/mcp-bundle/`): Symfony integration for MCP SDK
- **MCP Bundle** (`src/mcp-bundle/`): Symfony integration for official MCP SDK

### Supporting Directories
- **Examples** (`examples/`): Standalone usage examples
Expand Down
5 changes: 2 additions & 3 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ This is the Symfony AI monorepo containing multiple components and bundles that
- **Platform** (`src/platform/`): Unified interface to AI platforms (OpenAI, Anthropic, Azure, Gemini, VertexAI, etc.)
- **Agent** (`src/agent/`): Framework for building AI agents that interact with users and perform tasks
- **Store** (`src/store/`): Data storage abstraction with indexing and retrieval for vector databases
- **MCP SDK** (`src/mcp-sdk/`): SDK for Model Context Protocol enabling agent-tool communication

### Integration Bundles
- **AI Bundle** (`src/ai-bundle/`): Symfony integration for Platform, Store, and Agent components
- **MCP Bundle** (`src/mcp-bundle/`): Symfony integration for MCP SDK
- **MCP Bundle** (`src/mcp-bundle/`): Symfony integration for official MCP SDK

### Supporting Directories
- **Examples** (`examples/`): Standalone examples demonstrating component usage across different AI platforms
Expand Down Expand Up @@ -92,7 +91,7 @@ symfony server:start
Components are designed to work independently but have these relationships:
- Agent depends on Platform for AI communication
- AI Bundle integrates Platform, Agent, and Store
- MCP Bundle provides MCP SDK integration
- MCP Bundle provides official MCP SDK integration
- Store is standalone but often used with Agent for RAG applications

## Testing Architecture
Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ Symfony AI consists of several lower and higher level **components** and the res
* **[Platform](src/platform/README.md)**: A unified interface to various AI platforms like OpenAI, Anthropic, Azure, Gemini, VertexAI, and more.
* **[Agent](src/agent/README.md)**: Framework for building AI agents that can interact with users and perform tasks.
* **[Store](src/store/README.md)**: Data storage abstraction with indexing and retrieval for AI applications.
* **[MCP SDK](src/mcp-sdk/README.md)**: SDK for [Model Context Protocol](https://modelcontextprotocol.io) enabling communication between AI agents and tools.
* **Bundles**
* **[AI Bundle](src/ai-bundle/README.md)**: Symfony integration for AI Platform, Store and Agent components.
* **[MCP Bundle](src/mcp-bundle/README.md)**: Symfony integration for MCP SDK, allowing them to act as MCP servers or clients.
* **[MCP Bundle](src/mcp-bundle/README.md)**: Symfony integration for official MCP SDK, allowing them to act as MCP servers or clients.

## Examples & Demo

Expand Down
1 change: 1 addition & 0 deletions demo/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"symfony/flex": "^2.5",
"symfony/framework-bundle": "~7.3.0",
"symfony/http-client": "~7.3.0",
"mcp/sdk": "@dev",
"symfony/mcp-bundle": "@dev",
"symfony/monolog-bundle": "^3.10",
"symfony/runtime": "~7.3.0",
Expand Down
10 changes: 10 additions & 0 deletions demo/config/packages/mcp.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
mcp:
app: demo-app
version: 0.0.1
pagination_limit: 10
instructions: |
This demo MCP server provides time management capabilities for developers.

Use this server when you need to work with timestamps, time zones, or time-based calculations.

client_transports:
stdio: true
http: true
http:
session:
store: file
5 changes: 5 additions & 0 deletions demo/config/routes.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,8 @@ stream:
stream_assistant_reply:
path: '/stream/assistant-reply'
controller: 'App\Stream\TwigComponent::streamContent'

# Load MCP routes conditionally based on configuration
_mcp:
resource: .
type: mcp
28 changes: 28 additions & 0 deletions demo/src/MCP/Prompts/CurrentTimePrompt.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\MCP\Prompts;

use Mcp\Capability\Attribute\McpPrompt;

class CurrentTimePrompt
{
#[McpPrompt(name: 'time-analysis')]
public function getTimeAnalysisPrompt(): array
{
return [
[
'role' => 'user',
'content' => 'You are a time management expert. Analyze what time of day it is and suggest appropriate activities for this time.',
],
];
}
}
33 changes: 33 additions & 0 deletions demo/src/MCP/ResourceTemplates/CurrentTimeResourceTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\MCP\ResourceTemplates;

use Mcp\Capability\Attribute\McpResourceTemplate;

class CurrentTimeResourceTemplate
{
#[McpResourceTemplate(uriTemplate: 'time://{timezone}', name: 'time-by-timezone')]
public function getTimeByTimezone(string $timezone): array
{
try {
$time = (new \DateTime('now', new \DateTimeZone($timezone)))->format('Y-m-d H:i:s T');
} catch (\Exception $e) {
$time = 'Invalid timezone: '.$timezone;
}

return [
'uri' => "time://$timezone",
'mimeType' => 'text/plain',
'text' => $time,
];
}
}
27 changes: 27 additions & 0 deletions demo/src/MCP/Resources/CurrentTimeResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace App\MCP\Resources;

use Mcp\Capability\Attribute\McpResource;

class CurrentTimeResource
{
#[McpResource(uri: 'time://current', name: 'current-time-resource')]
public function getCurrentTimeResource(): array
{
return [
'uri' => 'time://current',
'mimeType' => 'text/plain',
'text' => (new \DateTime('now'))->format('Y-m-d H:i:s T'),
];
}
}
62 changes: 10 additions & 52 deletions demo/src/MCP/Tools/CurrentTimeTool.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,63 +11,21 @@

namespace App\MCP\Tools;

use Symfony\AI\McpSdk\Capability\Tool\MetadataInterface;
use Symfony\AI\McpSdk\Capability\Tool\ToolAnnotationsInterface;
use Symfony\AI\McpSdk\Capability\Tool\ToolCall;
use Symfony\AI\McpSdk\Capability\Tool\ToolCallResult;
use Symfony\AI\McpSdk\Capability\Tool\ToolExecutorInterface;
use Mcp\Capability\Attribute\McpTool;

/**
* @author Tom Hart <tom.hart.221@gmail.com>
*/
class CurrentTimeTool implements MetadataInterface, ToolExecutorInterface
class CurrentTimeTool
{
public function call(ToolCall $input): ToolCallResult
/**
* Returns the current time in UTC.
*
* @param string $format The format of the time, e.g. "Y-m-d H:i:s"
*/
#[McpTool(name: 'current-time')]
public function getCurrentTime(string $format = 'Y-m-d H:i:s'): string
{
$format = $input->arguments['format'] ?? 'Y-m-d H:i:s';

return new ToolCallResult(
(new \DateTime('now', new \DateTimeZone('UTC')))->format($format)
);
}

public function getName(): string
{
return 'current-time';
}

public function getDescription(): string
{
return 'Returns the current time in UTC';
}

public function getInputSchema(): array
{
return [
'type' => 'object',
'properties' => [
'format' => [
'type' => 'string',
'description' => 'The format of the time, e.g. "Y-m-d H:i:s"',
'default' => 'Y-m-d H:i:s',
],
],
'required' => ['format'],
];
}

public function getOutputSchema(): ?array
{
return null;
}

public function getTitle(): ?string
{
return null;
}

public function getAnnotations(): ?ToolAnnotationsInterface
{
return null;
return (new \DateTime('now', new \DateTimeZone('UTC')))->format($format);
}
}
34 changes: 19 additions & 15 deletions src/mcp-bundle/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,23 @@ CHANGELOG
0.1
---

* Add Symfony bundle bridging MCP-SDK with Symfony applications
* Add server mode exposing Symfony tools to MCP clients:
- STDIO transport via `php bin/console mcp` command
- SSE (Server-Sent Events) transport via HTTP endpoints
- Automatic tool discovery and registration
- Integration with AI-Bundle tools
* Add routing configuration for SSE endpoints:
- `/_mcp/sse` for SSE connections
- `/_mcp/messages/{id}` for message retrieval
* Add `McpController` for handling SSE connections
* Add Symfony bundle providing Model Context Protocol integration using official `mcp/sdk`
* Add server mode exposing MCP capabilities to clients:
- STDIO transport via `php bin/console mcp:server` command
- HTTP transport via StreamableHttpTransport using configurable endpoints
- Automatic capability discovery and registration
- EventDispatcher integration for capability change notifications
* Add configurable HTTP transport features:
- Configurable endpoint path (default: `/_mcp`)
- File and memory session store options
- TTL configuration for session management
- CORS headers for cross-origin requests
* Add `McpController` for handling HTTP transport connections
* Add `McpCommand` providing STDIO interface
* Add bundle configuration for enabling/disabling transports
* Add cache-based SSE message storage
* Add service configuration for MCP server setup
* Classes extending `\Symfony\AI\McpSdk\Capability\Tool\IdentifierInterface` automatically
get the `mcp.tool` tag for MCP tool discovery
* Add bundle configuration for transport selection and HTTP options
* Add dedicated MCP logger with configurable Monolog integration
* Add pagination and instructions configuration
* Tools using `#[McpTool]` attribute automatically discovered
* Prompts using `#[McpPrompt]` attribute automatically discovered
* Resources using `#[McpResource]` attribute automatically discovered
* Resource templates using `#[McpResourceTemplate]` attribute automatically discovered
6 changes: 3 additions & 3 deletions src/mcp-bundle/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# MCP Bundle

Symfony integration bundle for [Model Context Protocol](https://modelcontextprotocol.io/) using the Symfony AI
MCP SDK [symfony/mcp-sdk](https://github.com/symfony/mcp-sdk).
Symfony integration bundle for [Model Context Protocol](https://modelcontextprotocol.io/) using the official
MCP SDK [mcp/sdk](https://github.com/modelcontextprotocol/php-sdk).

**Currently only supports tools as server via Server-Sent Events (SSE) and STDIO.**
**Supports MCP capabilities (tools, prompts, resources) as server via HTTP transport and STDIO. Resource templates implementation ready but awaiting MCP SDK support.**

**This Bundle is experimental**.
[Experimental features](https://symfony.com/doc/current/contributing/code/experimental.html)
Expand Down
13 changes: 9 additions & 4 deletions src/mcp-bundle/composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "symfony/mcp-bundle",
"description": "Symfony integration bundle for Model Context Protocol (via symfony/mcp-sdk)",
"description": "Symfony integration bundle for Model Context Protocol (via official mcp/sdk)",
"license": "MIT",
"type": "symfony-bundle",
"authors": [
Expand All @@ -16,8 +16,10 @@
"symfony/framework-bundle": "^7.3|^8.0",
"symfony/http-foundation": "^7.3|^8.0",
"symfony/http-kernel": "^7.3|^8.0",
"symfony/mcp-sdk": "@dev",
"symfony/routing": "^7.3|^8.0"
"mcp/sdk": "@dev",
"symfony/routing": "^7.3|^8.0",
"symfony/psr-http-message-bridge": "^7.3|^8.0",
"php-http/discovery": "^1.20"
},
"require-dev": {
"phpstan/phpstan": "^2.1",
Expand All @@ -37,6 +39,9 @@
}
},
"config": {
"sort-packages": true
"sort-packages": true,
"allow-plugins": {
"php-http/discovery": true
}
}
}
Loading