MCP ExplorerExplorer

Mcp Php Application

@james2037on a year ago
2 MIT
FreeCommunity
AI Systems
# An Application Using MCP PHP Server

Overview

What is Mcp Php Application

The MCP PHP Application is a stub application designed to work with the MCP PHP Server framework, serving as a starting point for implementing the Model Context Protocol (MCP) in projects.

Use cases

Use cases include building web applications that require dynamic data manipulation, creating custom tools for specific operations, and integrating with other systems that support the Model Context Protocol.

How to use

To use the MCP PHP Application, clone the repository, navigate to the project directory, and install the dependencies using Composer. You can then create tools by adding new classes in the tools/ directory.

Key features

Key features include compatibility with the MCP PHP Server framework, the ability to create custom tools with defined parameters, and a structured approach to implementing the Model Context Protocol.

Where to use

The MCP PHP Application can be used in web development projects that require a structured approach to managing model contexts, particularly in applications that utilize the Model Context Protocol.

Content

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.

Tools

No tools

Comments

Recommend MCP Servers

View All MCP Servers