Skip to content

Commit e01a954

Browse files
author
klapaudius
committed
Merge branch '1.x'
# Conflicts: # src/Transports/SseTransport.php
2 parents 8169369 + 9932bac commit e01a954

File tree

79 files changed

+5855
-504
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+5855
-504
lines changed

CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,15 @@
1+
### Version 1.2.0
2+
3+
- **Core Features:**
4+
- Add real-time communication support through Streamable Http
5+
- Add Streaming Tool Support
6+
- Add TextToolResult, AudioToolResult, ImageToolResult and ResourceToolResult to properly manage tool returns
7+
- Both SSE and StreamableHttp can be active that makes clients able to use the old protocol version
8+
- **Deprecations:**
9+
- Configuration key `klp_mcp_server.server_provider` is replaced by `klp_mcp_server.server_providers` to maintain backward compatibility
10+
for clients that does not support the `2025-03-26` protocol version yet.
11+
- The ToolInterface is deprecated. Use StreamableToolInterface instead.
12+
113
### Version 1.1.0
214

315
- **Core Features:**

CLAUDE.md

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Project Overview
6+
7+
This is a Symfony bundle that enables developers to seamlessly add a Model Context Protocol (MCP) server to their Symfony applications. The main goal is to provide a production-ready implementation following the official MCP specifications at https://modelcontextprotocol.io/specification/2025-03-26.
8+
9+
The bundle allows Symfony applications to expose tools and resources that can be consumed by Large Language Models (LLMs) through secure transport protocols (SSE and StreamableHTTP), avoiding the security risks of STDIO transport in enterprise environments.
10+
11+
## Commands
12+
13+
### Testing
14+
```bash
15+
# Run all tests
16+
vendor/bin/phpunit
17+
18+
# Run a specific test file
19+
vendor/bin/phpunit tests/path/to/TestFile.php
20+
21+
# Generate code coverage
22+
vendor/bin/phpunit --coverage-html build/coverage
23+
24+
# Run PHPStan static analysis
25+
vendor/bin/phpstan analyse
26+
```
27+
28+
### Development Tools
29+
```bash
30+
# Create a new MCP tool
31+
php bin/console make:mcp-tool MyCustomTool
32+
33+
# Test a specific MCP tool
34+
php bin/console mcp:test-tool MyCustomTool
35+
36+
# Test tool with specific input
37+
php bin/console mcp:test-tool MyCustomTool --input='{"param":"value"}'
38+
39+
# List all available tools
40+
php bin/console mcp:test-tool --list
41+
```
42+
43+
### MCP Inspector
44+
```bash
45+
# Run the MCP Inspector for visual testing
46+
npx @modelcontextprotocol/inspector node build/index.js
47+
```
48+
49+
## Architecture Overview
50+
51+
### Package Structure
52+
This is a Symfony bundle that implements the Model Context Protocol (MCP) server. It provides:
53+
54+
- **Dual Transport Support**: Both SSE (Server-Sent Events) and StreamableHTTP protocols
55+
- **Tool System**: Extensible framework for creating MCP tools that LLMs can invoke
56+
- **Resource System**: Management of resources that can be exposed to LLM clients
57+
- **Progress Notifications**: Real-time progress updates for long-running operations
58+
59+
### Key Components
60+
61+
#### Transport Layer
62+
- **SSE Transport**: Uses Server-Sent Events with a pub/sub pattern via adapters (Cache or Redis)
63+
- **StreamableHTTP Transport**: Direct HTTP-based communication supporting both streaming and non-streaming responses
64+
- **Adapter System**: Abstraction layer allowing different message brokers (Cache, Redis)
65+
66+
#### Tool System
67+
- **BaseToolInterface**: Core interface for all tools (deprecated in favor of StreamableToolInterface)
68+
- **StreamableToolInterface**: Modern interface supporting progress notifications
69+
- **ToolResultInterface**: Abstraction for different result types (Text, Image, Audio, Resource)
70+
- **ProgressNotifier**: System for sending real-time progress updates during tool execution
71+
72+
#### Request Handlers
73+
- Located in `src/Server/Request/`: Handle different MCP protocol methods
74+
- Each handler implements specific MCP operations (initialize, tools/list, tools/call, etc.)
75+
76+
#### Protocol Implementation
77+
- **MCPProtocol**: Core protocol implementation handling request/response flow
78+
- **RequestHandler/NotificationHandler**: Process different message types
79+
- **MCPServer**: Main server orchestrating all components
80+
81+
### Configuration
82+
- Main config: `config/packages/klp_mcp_server.yaml`
83+
- Tools and resources are registered in configuration
84+
- Supports multiple adapters for SSE transport
85+
86+
## Important Notes
87+
88+
- **Cannot use** `symfony server:start` - requires proper web server (Nginx/Apache + PHP-FPM) for concurrent connections
89+
- Tools should implement `StreamableToolInterface` for modern features
90+
- Progress notifications only work with streaming tools (`isStreaming()` returns true)
91+
- All types should use `string|null` syntax instead of `?string` (null at the end)
92+
- Follow PSR-12 coding standards and include PHPDoc for all public methods

README.md

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,34 @@
1515

1616
## Overview
1717

18-
Symfony MCP Server is a powerful package designed to streamline the implementation of Model Context Protocol (MCP) servers in Symfony applications. This package **utilizes Server-Sent Events (SSE)** transport, providing a secure and controlled integration method.
18+
Symfony MCP Server is a powerful package designed to streamline the implementation of Model Context Protocol (MCP) servers in Symfony applications. This package **utilizes StreamableHTTP and/or Server-Sent Events (SSE)** transport, providing a secure and controlled integration methods.
1919

20-
### Why SSE instead of STDIO?
20+
### Why not STDIO?
2121

2222
While stdio is straightforward and widely used in MCP implementations, it has significant security implications for enterprise environments:
2323

2424
- **Security Risk**: STDIO transport potentially exposes internal system details and API specifications
2525
- **Data Protection**: Organizations need to protect proprietary API endpoints and internal system architecture
26-
- **Control**: SSE offers better control over the communication channel between LLM clients and your application
26+
- **Control**: StreamableHTTP or SSE offers better control over the communication channel between LLM clients and your application
2727

28-
By implementing the MCP server with SSE transport, enterprises can:
28+
By implementing the MCP server with StreamableHTTP or SSE transport, enterprises can:
2929

3030
- Expose only the necessary tools and resources while keeping proprietary API details private
3131
- Maintain control over authentication and authorization processes
3232

3333
Key benefits:
3434

35-
- Seamless and rapid implementation of SSE in existing Symfony projects
35+
- Seamless and rapid implementation of StreamableHTTP and/or SSE in existing Symfony projects
3636
- Support for the latest Symfony and PHP versions
3737
- Efficient server communication and real-time data processing
3838
- Enhanced security for enterprise environments
3939

4040
## Key Features
4141

42-
- Real-time communication support through Server-Sent Events (SSE) integration specified in the MCP 2024-11-05 version (Streamable HTTP from 2025-03-26 version is planned)
42+
- Real-time communication support through StreamableHTTP and/or Server-Sent Events (SSE) integration
4343
- Implementation of tools and resources compliant with Model Context Protocol specifications
44+
- Support of streaming tools with progres notifications
45+
- Support different types of tool results such as Text, Image, Audio, or Resource
4446
- Adapter-based design architecture with Pub/Sub messaging pattern
4547

4648
## Requirements
@@ -62,14 +64,15 @@ Key benefits:
6264
ping:
6365
enabled: true # Read the warning section in the default configuration file before disable it
6466
interval: 30
65-
server_provider: 'sse'
67+
server_providers: ['streamable_http','sse']
6668
sse_adapter: 'cache'
6769
adapters:
6870
cache:
6971
prefix: 'mcp_sse_'
7072
ttl: 100
7173
tools:
7274
- KLP\KlpMcpServer\Services\ToolService\Examples\HelloWorldTool
75+
- KLP\KlpMcpServer\Services\ToolService\Examples\StreamingDataTool
7376
- KLP\KlpMcpServer\Services\ToolService\Examples\VersionCheckTool
7477
resources:
7578
- KLP\KlpMcpServer\Services\ResourceService\Examples\HelloWorldResource
@@ -97,6 +100,7 @@ klp_mcp_server:
97100
98101
- **Streaming Endpoint for MCP Clients**: `GET /{default_path}/sse`
99102
- **Request Submission Endpoint**: `POST /{default_path}/messages`
103+
- **Streamable HTTP Endpoint**: `GET|POST /{default_path}`
100104

101105
### Docker Setup (Optional)
102106

@@ -127,9 +131,12 @@ This command:
127131
You can also manually create and register tools in `config/packages/klp_mcp_server.yaml`:
128132

129133
```php
130-
use KLP\KlpMcpServer\Services\ToolService\ToolInterface;
134+
use KLP\KlpMcpServer\Services\ProgressService\ProgressNotifierInterface;
135+
use KLP\KlpMcpServer\Services\ToolService\Annotation\ToolAnnotation;
136+
use KLP\KlpMcpServer\Services\ToolService\Result\ToolResultInterface;
137+
use KLP\KlpMcpServer\Services\ToolService\StreamableToolInterface;
131138
132-
class MyCustomTool implements ToolInterface
139+
class MyCustomTool implements StreamableToolInterface
133140
{
134141
// Tool implementation
135142
}
@@ -155,6 +162,7 @@ This helps you rapidly develop and debug tools by:
155162
- Showing the tool's input schema and validating inputs
156163
- Executing the tool with your provided input
157164
- Displaying formatted results or detailed error information
165+
- Displaying progress notifications for streaming tool
158166
- Supporting complex input types including objects and arrays
159167

160168
**For deep diving into tools creation please take a look at dedicated documentation [Here](https://github.com/klapaudius/symfony-mcp-server/blob/master/docs/building_tools.md)**
@@ -178,15 +186,19 @@ This will typically open a web interface at `localhost:6274`. To test your MCP s
178186
2. In the Inspector interface, enter your Symfony server's MCP SSE URL (e.g., `http://localhost:8000/mcp/sse`)
179187
3. Connect and explore available tools visually
180188

181-
The SSE URL follows the pattern: `http(s)://[your-web-server]/[default_path]/sse` where `default_path` is defined in your `config/packages/klp_mcp_server.yaml` file.
189+
| MCP Specification version | Connection Url pattern |
190+
|:----------------------------:|--------------------------------------------------|
191+
| 2024-11-05 (SSE) | `http(s)://[your-web-server]/[default_path]/sse` |
192+
| 2025-03-26 (Streamable HTTP) | `http(s)://[your-web-server]/[default_path]` |
193+
`default_path` is defined in your `config/packages/klp_mcp_server.yaml` file.
182194

183195
## Advanced Features
184196

185-
### Pub/Sub Architecture with SSE Adapters
197+
### Pub/Sub Architecture with Adapters
186198

187199
The package implements a publish/subscribe (pub/sub) messaging pattern through its adapter system:
188200

189-
1. **Publisher (Server)**: When clients send requests to the `/messages` endpoint, the server processes these requests and publishes responses through the configured adapter.
201+
1. **Publisher (Server)**: When clients send requests (e.g. `/messages` endpoint for SSE connection), the server processes these requests and publishes responses through the configured adapter.
190202

191203
2. **Message Broker (Adapter)**: The adapter maintains message queues for each client, identified by unique client IDs. This provides a reliable asynchronous communication layer.
192204

@@ -282,8 +294,8 @@ We are committed to actively pursuing the following key initiatives to enhance t
282294

283295
- **Core Features:**
284296
- ✅ Resources implementation compliant with MCP specification.
285-
- Support for Streamable HTTP (as specified in MCP 2025-03-26 version).
286-
- Prompts implementation compliant with MCP specification.
297+
- Support for Streamable HTTP (as specified in MCP 2025-03-26 version).
298+
- ⏳️ Prompts implementation compliant with MCP specification.
287299
- **Additional Adaptaters:**
288300
- Support for more Pub/Sub adapters (e.g., RabbitMQ).
289301

0 commit comments

Comments
 (0)