Skip to content

Commit 3d882df

Browse files
authored
Merge branch 'klapaudius:master' into master
2 parents 9e1a313 + 9b70218 commit 3d882df

File tree

173 files changed

+20855
-758
lines changed

Some content is hidden

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

173 files changed

+20855
-758
lines changed

.cursorrules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ This is a packge for Symfony which makes easier to build a Model Context Protoco
22

33
## Technical Specification
44

5-
- Support Symfony 7
5+
- Support Symfony 6.4 and 7
66
- Support PHP 8.2+
77

88
## Symfony Package Development Guideline

.github/FUNDING.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# These are supported funding model platforms
2+
3+
github: [klapaudius]

.github/workflows/fix-php-code-style-issues.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ jobs:
2222
ref: ${{ github.head_ref }}
2323

2424
- name: Fix PHP code style issues
25-
uses: aglipanci/laravel-pint-action@2.5
25+
uses: aglipanci/laravel-pint-action@2.6
2626

2727
- name: Commit changes
28-
uses: stefanzweifel/git-auto-commit-action@v5
28+
uses: stefanzweifel/git-auto-commit-action@v6
2929
with:
3030
commit_message: Fix styling

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,4 @@ testbench.yaml
3131
/coverage
3232
/phpunit.coverage.xml
3333
/docker/.env
34+
/docs/private/

.windsurfrules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ This is a packge for Symfony which makes easier to build a Model Context Protoco
22

33
## Technical Specification
44

5-
- Support Symfony 7
5+
- Support Symfony 6.4 and 7
66
- Support PHP 8.2+
77

88
## Symfony Package Development Guideline

CHANGELOG.md

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,61 @@
1+
### Version 1.4.0
2+
- **Core Features:**
3+
- Add comprehensive sampling support allowing tools to request LLM assistance during execution
4+
- Introduce SamplingAwareToolInterface for tools that need to make nested LLM calls
5+
- Add SamplingClient service for managing sampling requests
6+
- Create example CodeAnalyzerTool demonstrating sampling usage
7+
- **Enhancements:**
8+
- Automatic injection of SamplingClient into tools that implement SamplingAwareToolInterface
9+
- Support for text and multi-message sampling requests
10+
- Model preferences for controlling LLM selection (cost, speed, intelligence priorities)
11+
- **Bug Fixes:**
12+
- #45 Rename "arguments" option to "inputs" in TestMcpPromptCommand and related files for consistency
13+
- **Documentation:**
14+
- Add comprehensive sampling documentation with examples and best practices
15+
16+
### Version 1.3.3
17+
- **Bug Fixes:**
18+
- Protocol version negotiation incorrect (#41) by @Wolfgang-check24
19+
20+
### Version 1.3.2
21+
- **Bug Fixes:**
22+
- Fix protocol evaluation on client request (#38) by @Wolfgang-check24
23+
- Fix SSE stream blocking issue (#36) by @Wolfgang-check24
24+
- **Enhancements:**
25+
- Add test environment initialization and conditional output handling adjustments
26+
- **Documentation:**
27+
- Move development guidelines to CONTRIBUTING.md
28+
29+
### Version 1.3.1
30+
- **Enhancements:**
31+
- Add Symfony 6.4 compliancy
32+
33+
### Version 1.3.0
34+
35+
- **Core Features:**
36+
- Add comprehensive prompt system with multiple message types (Text, Image, Audio, Resource, Collection)
37+
- Introduce MakeMcpPromptCommand for generating prompts via console
38+
- Add TestMcpPromptCommand for testing prompt functionality
39+
- Store client sampling capabilities for better client-server communication
40+
- Add ProfileGeneratorTool and CollectionToolResult examples
41+
- **Enhancements:**
42+
- Update documentation with prompts usage and testing commands
43+
- **Bug Fixes:**
44+
- Remove unused `setAccessible` calls in tests
45+
- Fix code styling issues
46+
47+
### Version 1.2.0
48+
49+
- **Core Features:**
50+
- Add real-time communication support through Streamable Http
51+
- Add Streaming Tool Support
52+
- Add TextToolResult, AudioToolResult, ImageToolResult and ResourceToolResult to properly manage tool returns
53+
- Both SSE and StreamableHttp can be active that makes clients able to use the old protocol version
54+
- **Deprecations:**
55+
- Configuration key `klp_mcp_server.server_provider` is replaced by `klp_mcp_server.server_providers` to maintain backward compatibility
56+
for clients that does not support the `2025-03-26` protocol version yet.
57+
- The ToolInterface is deprecated. Use StreamableToolInterface instead.
58+
159
### Version 1.1.0
260

361
- **Core Features:**

CLAUDE.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
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, resources, and prompts 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+
- **Prompt System**: Pre-defined conversation starters and templates for LLM interactions
58+
- **Progress Notifications**: Real-time progress updates for long-running operations
59+
60+
### Key Components
61+
62+
#### Transport Layer
63+
- **SSE Transport**: Uses Server-Sent Events with a pub/sub pattern via adapters (Cache or Redis)
64+
- **StreamableHTTP Transport**: Direct HTTP-based communication supporting both streaming and non-streaming responses
65+
- **Adapter System**: Abstraction layer allowing different message brokers (Cache, Redis)
66+
67+
#### Tool System
68+
- **BaseToolInterface**: Core interface for all tools (deprecated in favor of StreamableToolInterface)
69+
- **StreamableToolInterface**: Modern interface supporting progress notifications
70+
- **ToolResultInterface**: Abstraction for different result types (Text, Image, Audio, Resource)
71+
- **ProgressNotifier**: System for sending real-time progress updates during tool execution
72+
73+
#### Prompt System
74+
- **PromptInterface**: Core interface for creating prompts
75+
- **PromptMessageInterface**: Base interface for different message types
76+
- **Message Types**: TextPromptMessage, ImagePromptMessage, AudioPromptMessage, ResourcePromptMessage
77+
- **CollectionPromptMessage**: Container for multiple prompt messages
78+
- **PromptRepository**: Manages and retrieves available prompts
79+
80+
#### Request Handlers
81+
- Located in `src/Server/Request/`: Handle different MCP protocol methods
82+
- Each handler implements specific MCP operations (initialize, tools/list, tools/call, resources/list, resources/read, prompts/list, prompts/get, etc.)
83+
84+
#### Protocol Implementation
85+
- **MCPProtocol**: Core protocol implementation handling request/response flow
86+
- **RequestHandler/NotificationHandler**: Process different message types
87+
- **MCPServer**: Main server orchestrating all components
88+
89+
### Configuration
90+
- Main config: `config/packages/klp_mcp_server.yaml`
91+
- Tools, resources, and prompts are registered in configuration
92+
- Supports multiple adapters for SSE transport
93+
94+
## Important Notes
95+
96+
- **Cannot use** `symfony server:start` - requires proper web server (Nginx/Apache + PHP-FPM) for concurrent connections
97+
- Tools should implement `StreamableToolInterface` for modern features
98+
- Progress notifications only work with streaming tools (`isStreaming()` returns true)
99+
- All types should use `string|null` syntax instead of `?string` (null at the end)
100+
- Follow PSR-12 coding standards and include PHPDoc for all public methods
Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ This document provides essential information for developers working on the Symfo
66

77
### Prerequisites
88
- PHP 8.2 or higher
9-
- Symfony 7.0
9+
- Symfony 6.4 or higher
1010
- Composer
1111

1212
### Installation
@@ -51,15 +51,16 @@ This document provides essential information for developers working on the Symfo
5151
ping:
5252
enabled: true
5353
interval: 30
54-
server_provider: 'sse'
55-
sse_adapter: 'redis'
54+
server_providers: ['streamable_http', 'sse'] # Available options: 'sse', 'streamable_http'
55+
sse_adapter: 'cache'
5656
adapters:
5757
redis:
5858
prefix: 'mcp_sse_'
5959
host: 'localhost' # Change as needed
6060
ttl: 100
6161
tools:
6262
- KLP\KlpMcpServer\Services\ToolService\Examples\HelloWorldTool
63+
- KLP\KlpMcpServer\Services\ToolService\Examples\StreamingDataTool
6364
- KLP\KlpMcpServer\Services\ToolService\Examples\VersionCheckTool
6465
```
6566
@@ -75,6 +76,9 @@ This document provides essential information for developers working on the Symfo
7576
- **Web Server**: This package cannot be used with `symfony server:start` as it requires processing multiple connections concurrently. Use Nginx + PHP-FPM, Apache + PHP-FPM, or a custom Docker setup instead.
7677
- **Redis Configuration**: Ensure your Redis server is properly configured and accessible at the host specified in the configuration.
7778
- **Security**: It's strongly recommended to implement OAuth2 Authentication for production use.
79+
- **Protocol Support**: This bundle supports two protocols:
80+
- **SSE (Server-Sent Events)**: The legacy protocol for real-time communication.
81+
- **StreamableHTTP**: The actual protocol that works over standard HTTP connection or Streaming if needed.
7882

7983
### Docker Setup
8084

@@ -221,11 +225,11 @@ class DataUtilTest extends TestCase
221225
php bin/console make:mcp-tool MyCustomTool
222226
```
223227

224-
2. Implement the `ToolInterface` in your custom tool class:
228+
2. Implement the `StreamableToolInterface` in your custom tool class:
225229
```php
226-
use KLP\KlpMcpServer\Services\ToolService\ToolInterface;
230+
use KLP\KlpMcpServer\Services\ToolService\StreamableToolInterface;
227231
228-
class MyCustomTool implements ToolInterface
232+
class MyCustomTool implements StreamableToolInterface
229233
{
230234
// Implementation
231235
}
@@ -260,4 +264,6 @@ php bin/console mcp:test-tool MyCustomTool --input='{"param":"value"}'
260264

261265
- The package implements a publish/subscribe (pub/sub) messaging pattern through its adapter system.
262266
- The default Redis adapter maintains message queues for each client, identified by unique client IDs.
263-
- Long-lived SSE connections subscribe to messages for their respective clients and deliver them in real-time.
267+
- The bundle supports two transport protocols:
268+
- **SSE (Server-Sent Events)**: Long-lived connections that subscribe to messages for their respective clients and deliver them in real-time.
269+
- **StreamableHTTP**: An HTTP-based protocol that can handle both streaming and non-streaming responses.

LICENSE.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
The MIT License (MIT)
22

3-
Copyright (c) OP.GG
3+
Copyright (c) 2025 Boris AUBE
44

5-
Copyright (c) 2025 klapaudius
5+
Copyright (c) OP.GG
66

77
Permission is hereby granted, free of charge, to any person obtaining a copy
88
of this software and associated documentation files (the "Software"), to deal

0 commit comments

Comments
 (0)