-
Notifications
You must be signed in to change notification settings - Fork 51
Feat!: MCP Protocol 2025-03-26 Support #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
… state - Updated Protocol, Registry, Server, ServerBuilder, and RequestProcessor to use SessionManager for session handling. - Adjusted methods to reflect the new session management approach, including cleanup and message queuing. - Enhanced error handling in AudioContent for better file reading feedback.
- Introduced batch processing and better error handling. - Refactored Protocol class to use sessionId instead of clientId for message handling. - Updated ServerBuilder to initialize Protocol with RequestProcessor, streamlining session management. - Cleaned up unused code and improved error logging for better maintainability.
…3-26 schema Refactors core MCP element definitions (Tool, Resource, ResourceTemplate, Prompt) and content types (Text, Audio, EmbeddedResource, ResourceContent) to enhance type safety and schema compliance with the MCP 2025-03-26 specification. Key changes include: - Introduced `Model\Annotations` and `Model\ToolAnnotations` classes for structured annotation handling, replacing generic arrays. - Updated `McpTool`, `McpResource`, and `McpResourceTemplate` attributes and their corresponding Definition classes to use these new Annotation types. - Restructured `JsonRpc\Contents\EmbeddedResource` to be a wrapper for `ResourceContent`, correctly reflecting the protocol's embedded resource structure. `ResourceContent` now directly holds URI, MIME, and data. - Added optional `annotations` property to `TextContent` and `AudioContent`. - Removed individual getter methods from Definition classes, promoting reliance on public readonly properties or `toArray()` for MCP output. - Updated `toArray()`, `fromArray()`, and `fromReflection()` methods across all affected Definition and Content classes to support these changes.
- New StreamableHttpTransport to handle post, get and delete requests and resumability - updated JSON RPC objects to comply more closely with the specification - added Eventstore interface and implementation for storing stream events to allow resumability - new SessionIdGenerator Interface and implementation
- Updated Protocol class to utilize SessionInterface for session handling, improving type safety and consistency. - Refactored message processing methods to accept SessionInterface instead of sessionId directly. - Improved error handling in StdioServerTransport and StreamableHttpServerTransport for better logging and response management. - Introduced new methods in SessionInterface for better session data management.
- Updated Protocol class to ensure session creation and deletion are logged correctly during client connection and disconnection. - Enhanced StreamableHttpServerTransport by consolidating session context management and improving SSE stream handling. - Removed unnecessary session context variables to streamline the code and improve clarity.
Replaces internal MCP data structures (Requests, Responses, Results, Content types, Enums, and model definitions like Tool, Resource) with their counterparts from the new `php-mcp/schema` package, enhancing type safety and compliance with the MCP specification.
…ments - New `CompletionProviderInterface` and `CompletionProvider` attribute. - Updated the Dispatcher to handle completion requests, integrating completion logic for prompts and resource templates. - Enhanced the Registry to manage completion providers, allowing for better organization and retrieval of completion logic. - Introduced methods in ServerBuilder and Discoverer to facilitate automatic registration of completion providers during element discovery and server setup.
- Replaced custom `parseRequest` methods in `HttpServerTransport`, `StdioServerTransport`, and `StreamableHttpServerTransport` with a unified `Parser::parse` method from the `php-mcp/schema` package. - Removed redundant code for request parsing, enhancing maintainability and consistency across transport implementations. - Updated error handling to utilize the new message parsing approach, improving logging and response management.
- Updated the Protocol class to set a 404 status code for invalid or expired sessions and improved logging for response sending and error handling. - Adjusted response status code handling to utilize the context's status code, ensuring more accurate HTTP responses.
…lement logic This commit introduces a new set of classes under the `PhpMcp\Server\Elements` namespace (`RegisteredElement`, `RegisteredTool`, `RegisteredResource`, `RegisteredPrompt`, `RegisteredResourceTemplate`). These classes now encapsulate: - The MCP schema DTO (e.g., `PhpMcp\Schema\Tool`). - The handler invocation logic (previously in `Support\Handler` and `Support\ArgumentPreparer`), including argument preparation and type casting, now part of the `RegisteredElement` base class. - Specific execution methods (e.g., `call()` on `RegisteredTool`, `read()` on `RegisteredResource`). - Result formatting logic (previously in `Traits\ResponseFormatter`) moved into the respective `Registered*` classes. - URI template matching logic is now self-contained within `RegisteredResourceTemplate`. - Completion provider storage is now part of `RegisteredTool`, `RegisteredPrompt`, and `RegisteredResourceTemplate`.
- Introduced a new `SystemClock` class implementing `ClockInterface` for time management. - Updated `ArraySessionHandler` and `CacheSessionHandler` to utilize the `SystemClock` for timestamping, enhancing testability and flexibility. - Added a `FixedClock` mock for testing purposes, allowing controlled time manipulation in tests.
- Complete refactor of unit tests for all `src/` components. - New robust integration tests for the transports - Addressed bugs discovered when adding integration tests
…tting in CI workflow
Update documentation to reflect current architecture with proper schema generation, deployment strategies, and corrected configuration examples.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR brings support for the
2025-03-26revision of the MCP Protocol with significant architectural improvements, enhanced schema generation, and new transport capabilities.✨ New Features
#[Schema]attribute with full JSON Schema validation support#[CompletionProvider]attribute for auto-completion in resource templates and promptsSystemClockandFixedClockfor testingInMemoryEventStoreimplementation🔧 Enhanced Features
🏗️ Architecture Improvements
Parser::parsemethod across all transports🔥 Breaking Changes
php-mcp/schemapackage for all MCP related DTOs, requests, responses, and content typesClientStateManagerwithSessionManagerandSessionclassesSupport\*classes toUtils\*namespaceRequestHandlerwithDispatcherfor better semantic clarity📚 Documentation
🧪 Testing
📦 Dependencies
php-mcp/schema^1.0