bdlabs/MCP-Server
If you are the rightful owner of MCP-Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
MCP Server is a modular communication protocol server designed for easy integration and management of various tools and communication methods.
MCP Server - Modular Communication Protocol Server
Overview
MCP Server is a powerful and flexible server solution that enables easy integration and management of various tools and communication methods. Designed according to SOLID principles, it offers a modular architecture allowing rapid extension of functionality without modifying existing code.
Project Structure
mcp-server/
āāā Server/
ā āāā Registry/
ā ā āāā MethodRegistry.php # Registry of available API methods
ā ā āāā ToolRegistry.php # Registry of available tools
ā ā
ā āāā ResponseFormatter/
ā ā āāā ResponseFormatterInterface.php # Response formatter interface
ā ā āāā JsonResponseFormatter.php # JSON response formatter
ā ā āāā EventStreamResponseFormatter.php # Event stream formatter
ā ā
ā āāā Tool/
ā ā āāā Response/
ā ā ā āāā ToolResponsable.php # Tool response interface
ā ā ā āāā TextContentResponse.php # Text response
ā ā ā āāā ImageContentResponse.php # Image response
ā ā ā āāā AudioContentResponse.php # Audio response
ā ā ā āāā ResourceContentResponse.php # Resource response
ā ā ā
ā ā āāā ToolInterface.php # Interface for tools
ā āāā MCPServer.php # Main server class
ā āāā MCPServerBuilder.php # Builder for server instance creation
ā āāā MCPServerMethodParams.php # Server method parameters
ā
āāā Tool/
ā āāā AbstractTool.php # Abstract class for tools
ā
āāā LICENSE # Project license (GPL-3.0)
āāā README.md # Project documentation
āāā config.php # Application configuration
āāā index.php # Application entry point
āāā .gitignore # Git ignored files configuration
Core Components
MCPServer
The main server class responsible for processing requests and managing tool and method registration. It uses the facade pattern to simplify complex internal logic.
Registries
- ToolRegistry - manages the collection of available tools
- MethodRegistry - manages available API methods
Response Formatters
Implement the strategy pattern, enabling flexible response formatting:
- JsonResponseFormatter - formats responses as JSON
- EventStreamResponseFormatter - formats responses as event streams
Response Types
A set of classes representing different types of tool responses:
- TextContentResponse - text responses
- ImageContentResponse - responses containing images
- AudioContentResponse - responses containing audio
- ResourceContentResponse - responses containing various resources
Usage Example
<?php
use MCP\MCPServer;
use MCP\MCPServerBuilder;
use MCP\Tool\MyCustomTool\Tool as MyCustomTool;
// Creating a server using the builder
$server = (new MCPServerBuilder())
->build([new MyCustomTool()]);
// Running the server
$server->handleRequest();
Server run.
php -S localhost:9876 index.php
Creating Custom Tools
To create a new tool:
- Create a class implementing the
ToolInterface
- Register the tool using
MCPServerBuilder::addTool()
<?php
namespace MCP\Tool\MyCustomTool;
use MCP\Tool\Response\ToolResponsable;
class Tool extends AbstractTool
{
public function __construct()
{
$this->name = '';
$this->description = '';
$this->inputSchema = [];
}
public function execute(array $params): ToolResponsable
{
// Tool logic implementation
return new TextContentResponse('Tool execution result');
}
}
License
This project is licensed under the GNU General Public License v3.0 (GPL-3.0). See the LICENSE file for details.
Requirements
- PHP 8.1 or newer
Contributing
We welcome contributions to this project! Please review our contribution guidelines in the CONTRIBUTING.md file.
Contact
If you have any questions or issues, please create an issue in our GitHub repository.