Skip to content

james2037/mcp-php-application

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MCP PHP Application

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.

Prerequisites

Before using this application, ensure that you have the following installed:

  1. PHP: Running php --version should report 8.1 or greater.
  2. Composer: The dependency manager for PHP. You can find it here.

Installation

To set up the application, follow these steps:

  1. Clone this repository:

    git clone https://github.com/james2037/mcp-php-application.git
  2. Navigate to the project directory:

    cd mcp-php-application
  3. Install the dependencies using Composer:

    composer install

Creating a Tool

To create a tool for the application, follow these steps:

  1. 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);
        }
    }
  2. The #[ToolAttribute] annotation defines the name and description of the tool.

  3. Parameters for the tool are defined using the #[ParameterAttribute] annotation.

  4. Implement the doExecute method to define the tool's functionality.

Running the Server

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.

Features

Currently, you can write tools. The server supports the STDIO transport only. New capabilities and transports coming soon.

Contributing

Contributions to the MCP PHP Application are welcome! Feel free to submit issues or pull requests to improve functionality, documentation, or examples.

License

This project is licensed under the MIT License.

About

An application that uses MCP PHP Server

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages