Skip to main content
Glama
Phpactor MCP Server

Phpactor MCP Server

by p4it-kft

Phpactor MCP Server

MCP server that wraps Phpactor to provide project-wide semantic PHP refactoring tools for AI assistants (Claude Code, etc.).

What it does

Exposes 6 tools that require Phpactor's type-aware engine — things a text-based AI cannot reliably do with grep:

Tool

Description

phpactor_index_build

Build/rebuild project index (prerequisite for other tools)

phpactor_find_references

Find all semantic references to a class or member

phpactor_rename_class

Rename class + update ALL references project-wide

phpactor_rename_member

Rename method/property/constant project-wide

phpactor_move_class

Move class to new file/namespace + update references

phpactor_class_info

Query class info (implements, implementations)

See docs/spec.md for full specification.

Related MCP server: phpustik MCP Server

Prerequisites

  • Node.js >= 18

  • Phpactor installed and available in PATH (or set PHPACTOR_BIN env var)

    # Install Phpactor (PHAR)
    curl -Lo phpactor https://github.com/phpactor/phpactor/releases/latest/download/phpactor.phar
    chmod +x phpactor
    mv phpactor ~/.local/bin/
  • PHP >= 8.1

  • A PHP project with Composer and PSR-4 autoload configured

Yii2 / non-PSR-4 projects

Phpactor requires PSR-4 autoload mappings. For Yii2 projects, add this to composer.json:

{
  "autoload": {
    "psr-4": {
      "common\\": "common/",
      "backend\\": "backend/",
      "frontend\\": "frontend/",
      "console\\": "console/",
      "modules\\": "modules/"
    }
  }
}

Then run composer dump-autoload.

Install

npm install -g @p4it-kft/phpactor-mcp

No build step needed — the package is published prebuilt to npm.

From source (development)

git clone https://github.com/p4it-kft/@p4it-kft/phpactor-mcp
cd @p4it-kft/phpactor-mcp
npm install
npm run build

Configure in Claude Code

Add to ~/.claude/settings.json (or project-level .claude/settings.json):

{
  "mcpServers": {
    "phpactor": {
      "command": "npx",
      "args": ["-y", "@p4it-kft/phpactor-mcp"]
    }
  }
}

Optionally set PHPACTOR_BIN if Phpactor is not in PATH:

{
  "mcpServers": {
    "phpactor": {
      "command": "npx",
      "args": ["-y", "@p4it-kft/phpactor-mcp"],
      "env": {
        "PHPACTOR_BIN": "/path/to/phpactor"
      }
    }
  }
}

Usage

Once configured, the tools are available to Claude. Typical workflow:

  1. Build the index first — Claude calls phpactor_index_build with your project path

  2. Use tools — find references, rename, move classes as needed

  3. Rebuild index after significant file changes

Testing

# Run all integration tests (requires tmp/p4it-website test project)
bash test-phpactor.sh

Development

npm run dev    # Watch mode — recompiles on changes
npm run build  # One-time build

Available Tools

6 tools
phpactor_class_infoA

Query indexed information about a PHP class: FQCN, file path, type, what it implements, and what implements it.

Inputs: fqcn (required), projectPath (required).

phpactor_find_referencesA

Find all semantic references to a PHP class or class member across the project. Returns type-aware results (not grep-based text matching).

Inputs: filePath (required), projectPath (required), memberName, memberType.

phpactor_index_buildA

Build or rebuild the Phpactor project index. Must run before other phpactor tools. Checks PSR-4 autoload config and warns if missing (Yii2 projects need manual setup).

Inputs: projectPath (required), reset.

phpactor_move_classA

Move/rename a PHP class: moves the file, updates the namespace declaration, AND updates all references project-wide. This is the tool for full class renames. WARNING: Writes directly to disk — commit your work first!

Inputs: destPath (required), sourcePath (required), projectPath (required).

phpactor_rename_classA

Update all REFERENCES to a PHP class project-wide (use statements, type hints, docblocks, instantiations). Does NOT rename the file or modify the class declaration — use phpactor_move_class for a full rename including file move and namespace update.

Inputs: newFqcn (required), filePath (required), projectPath (required), dryRun.

phpactor_rename_memberA

Rename a PHP method, property, or constant and update all references project-wide. Uses type inference to only rename the correct member (not same-named members on other classes).

Inputs: newName (required), filePath (required), memberName (required), memberType (required), +2 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 6 tools

    Disambiguation5/5

    Each tool has a clearly distinct purpose: class info, find references, build index, move class, rename class (only references), rename member. The descriptions explicitly contrast move_class vs rename_class, so an agent can easily differentiate.

    Naming Consistency4/5

    All tools start with 'phpactor_' and use snake_case, but the verb_noun pattern is not fully consistent: 'class_info' and 'index_build' deviate slightly. However, the overall pattern is predictable and readable.

    Tool Count5/5

    6 tools is well-scoped for a PHP code intelligence server, covering indexing, querying, and refactoring. No tool is redundant, and the count is appropriate for the domain.

    Completeness4/5

    The tool set covers core operations (index, inspect, move/rename class, rename member) but lacks capabilities like listing classes or getting method details. Minor gaps exist, but the surface is usable for common tasks.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Connects AI assistants like Claude to PHP's XDebug debugger for runtime inspection, breakpoint control, and variable tracking, enabling natural language debugging of PHP applications.
      6
      1
      Apache 2.0
    • A
      license
      B
      quality
      D
      maintenance
      Enables AI assistants to deeply interact with the PHP ecosystem, including runtime, static analysis, security scanning, testing, Composer, and frameworks like Laravel and Symfony. It exposes over 30 tools, 8 resources, and 7 prompts via MCP, allowing natural language commands to run PHP linting, static analysis, audits, tests, and project initialization.
      41
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Bridges AI assistants to clangd for C/C++ code intelligence, providing tools for symbol search, definitions, references, type info, and more.
      2
      MIT
    • A
      license
      Not graded
      quality
      C
      maintenance
      Enables AI agents to navigate and refactor a codebase through an AST index, offering project overviews, symbol and usage search, module dependency exploration, and LSP-backed operations such as rename, go-to-definition, diagnostics, and extract-method. Supports TypeScript/JavaScript and C# with automatic reindexing and watch mode.
      MIT