PHP SDK #118
Replies: 1 comment
-
I've released the second alpha build of the MCP SDK for PHP, focusing mainly on client-side improvements. The biggest update is the introduction of a MCP Web Client capable of running in a standard web hosting environment. It features a web interface capable of connecting to a MCP Server, and running Prompts, Tools, and Resources with full message logging for debugging. Being able to run both a MCP Web Client and MCP Server via stdio in a standard cPanel account opens a wide range of potential applications. A major challenge is that many web hosting environments block long-running processes, so the connection between a MCP client and server wouldn't remain open between operations. To overcome this, I developed a separate wrapper class between the Web Client and the main Client class that initializes and closes the connection for each request. Important information can then be stored in a PHP session, which should meet the needs for the majority of use cases. I've also successfully connected a MCP Client running through PHP-CLI with the "Everything MCP Server" from the official servers repository, and plan to continue testing different types of MCP Servers with PHP-based clients. Other future steps include testing remote servers via SSE, and improving security, error handling, and resource management to prepare the SDK for production environments. |
Beta Was this translation helpful? Give feedback.
-
Pre-submission Checklist
What would you like to share?
I've released an alpha build of a MCP SDK for PHP. I have working examples of both a client and server, tested in PHP 8.3 on both Windows and Linux.
The SDK has been built into a Composer package, making it easy to install. At this stage, my main focus has been laying a solid foundation of classes that fully implement the TypeScript schema of MCP. There should be a class for each feature as defined in the spec, but only the prompts/list demonstrated in my example has been tested. The other features may need minor tweaks and refactoring to get them working on a live server/client.
Currently only the stdio transport is fully implemented, but I have most of the groundwork in place for a SSE transport. It also only uses synchronous calls due to the complexity of implementing async in a way that will work cross-platform, but I hope to look into adding async in the future. Some of the groundwork for that is already in the code, and could probably be easily completed by a developer who is more familiar with PHP transports across different platforms (such as how blocking vs non-blocking is handled).
The PHP SDK was built following the general structure of the official Python SDK. I used Claude 3.5 Sonnet to write a draft version of the PHP code that implements the general functionality of the Python code, while also providing it with the TypeScript schema to ensure that the classes conform to the spec. I then did additional refactoring and debugging with ChatGPT o1 pro mode, along with carefully mapping out the code myself, to ensure all the classes fit together, and run properly in a PHP environment. There is still more work to be done before using the SDK in a production environment, but this should give a good starting point for anyone looking to use MCP in PHP.
Overall, I'm very impressed by what I've seen with the MCP protocol, and some of the use cases demonstrated by the community. PHP powers much of the web, and I believe this SDK can provide an easy and secure way to integrate LLMs with everything from personal blogs to large e-commerce platforms. I'm looking forward to any feedback or improvements the community may be able to add to the SDK, as well as seeing the creative ways it could be integrated with other PHP projects.
Relevant Links
GitHub repository: https://github.com/logiscape/mcp-sdk-php
Beta Was this translation helpful? Give feedback.
All reactions