The MCP PHP Application is a stub application designed to work with the MCP PHP Server framework. It serves as a starting point for users implementing the Model Context Protocol (MCP) in their projects.
Before using this application, ensure that you have the following installed:
- PHP: Running
php --version
should report 8.1 or greater. - Composer: The dependency manager for PHP. You can find it here.
To set up the application, follow these steps:
-
Clone this repository:
git clone https://github.com/james2037/mcp-php-application.git
-
Navigate to the project directory:
cd mcp-php-application
-
Install the dependencies using Composer:
composer install
To create a tool for the application, follow these steps:
-
Create a new class in the
tools/
directory. For example:<?php namespace App\Tools; use MCP\Server\Tool\Tool; use MCP\Server\Tool\Attribute\Tool as ToolAttribute; use MCP\Server\Tool\Attribute\Parameter as ParameterAttribute; #[ToolAttribute('calculator', 'A calculator tool')] class CalculatorTool extends Tool { protected function doExecute( #[ParameterAttribute('operation', type: 'string', description: 'Operation to perform (add/subtract)')] #[ParameterAttribute('a', type: 'number', description: 'First number')] #[ParameterAttribute('b', type: 'number', description: 'Second number')] array $arguments ): array { $result = match ($arguments['operation']) { 'add' => $arguments['a'] + $arguments['b'], 'subtract' => $arguments['a'] - $arguments['b'], default => throw new \InvalidArgumentException('Invalid operation') }; return $this->text((string)$result); } }
-
The
#[ToolAttribute]
annotation defines the name and description of the tool. -
Parameters for the tool are defined using the
#[ParameterAttribute]
annotation. -
Implement the
doExecute
method to define the tool's functionality.
To start the MCP PHP server, run the following command:
php path/to/mcp_server.php
the mcp_server.php
file is located in the root of this repository.
The server will start and listen for requests based on the Model Context Protocol.
Currently, you can write tools. The server supports the STDIO transport only. New capabilities and transports coming soon.
Contributions to the MCP PHP Application are welcome! Feel free to submit issues or pull requests to improve functionality, documentation, or examples.
This project is licensed under the MIT License.