Get the FREE Ultimate OpenClaw Setup Guide →

mcp

Model Context Protocol for Hyperf

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
claude mcp add --transport stdio friendsofhyperf-mcp-server php bin/hyperf.php start \
  --env APP_ENV="production" \
  --env REDIS_URL="redis://localhost" \
  --env MCP_LOG_LEVEL="info"

How to use

This MCP server implements the Model Context Protocol (MCP) using the Hyperf PHP framework. It provides complete MCP protocol support, including tools, resources, and prompts management, and supports both STDIO and HTTP transport methods. The server automatically discovers and registers components via annotations, and uses Redis for distributed session management. To use it, first install and configure the server in your Hyperf application, publish the MCP server configuration, and start the Hyperf server. Clients can connect via HTTP to the configured endpoint (default /mcp) or interact with the STDIO-based command line tool for real-time MCP operations. The included tooling lets you create tools, resources, and prompts, and manage them through MCP-compliant requests and responses.

How to install

Prerequisites:

  • PHP >= 8.1
  • Hyperf ~3.1.0
  • Redis extension for PHP
  • Composer
  1. Install the MCP server package:

    composer require friendsofhyperf/mcp-server

  2. Publish the configuration:

    php bin/hyperf.php vendor:publish friendsofhyperf/mcp-server

  3. Configure MCP servers: Edit the published config to enable and customize servers, capabilities, routing, and discovery as needed. Example settings include enabling tools, resources, prompts, and completions, setting protocol_version, pagination_limit, and discovery paths.

  4. Start the Hyperf server:

    php bin/hyperf.php start

  5. Verify:

    • Access the HTTP MCP endpoint (default path /mcp) if HTTP transport is enabled.
    • Use the STDIO tool via the built-in command signature (mcp:stdio) if you require STDIO transport.

Note: Ensure Redis is running and accessible if you rely on Redis-based session management. You can customize session storage and discovery behavior in the published configuration.

Additional notes

Tips and common considerations:

  • Ensure PHP 8.1+ and the Redis PHP extension are installed and enabled.
  • When running multiple MCP server instances, you can configure multiple entries under mcpServers in the config.
  • The HTTP transport defaults to route /mcp; you can customize the path and middleware in the config under http.
  • The server auto-discovers tools, resources, and prompts via annotations; ensure your PHP classes use the appropriate Mcp\Capability\Attribute attributes.
  • For deployment, consider configuring a proper process manager and ensuring Redis connection health for session storage.
  • If you encounter issues with annotations discovery, verify that your code autoloads correctly and that base_path/scan_dirs are set to include your app source directories.

Related MCP Servers

Sponsor this space

Reach thousands of developers