Skip to main content
Glama
p4it-kft

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: smart-xdebug-mcp

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.

ParametersJSON Schema
NameRequiredDescriptionDefault
fqcnYesFully qualified class name (e.g. App\Entity\User)
projectPathYesAbsolute path to the PHP project root

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden. It correctly indicates a read-only query operation but does not disclose dependencies (e.g., need for a built index), failure modes, or performance characteristics. Adequate but minimal.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single sentence, front-loaded with the verb 'Query' and key resource. No wasted words; every part adds value.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple query tool with two parameters and no output schema, the description lists the returned fields (FQCN, file path, type, implements, implemented by) which is helpful. However, it omits mention that an index must be built (given sibling phpactor_index_build), which could be relevant for the agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with clear parameter descriptions (FQCN example, absolute path for projectPath). The tool description adds no additional meaning beyond the schema, so baseline score 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states 'Query indexed information about a PHP class' and lists specific returned data (FQCN, file path, type, etc.), effectively describing the tool's function and distinguishing it from siblings like phpactor_find_references or phpactor_rename_class.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies when to use (to get class info) but does not explicitly state when not to use or mention alternatives. Sibling tools are listed but no guidance on choosing this over them is provided, leaving the agent to infer.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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).

ParametersJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the PHP file, relative to projectPath
memberNameNoMethod/property/constant name. Omit to find class references.
memberTypeNoRequired when memberName is set
projectPathYesAbsolute path to the PHP project root

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations; description adds 'type-aware' behavior but omits read-only nature, authentication, or performance implications.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two efficient sentences with front-loaded purpose, no redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema; lacks description of return format (e.g., file locations, line numbers). Incomplete for an agent to consume results.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%; description adds no extra context about parameters, so baseline 3 applies.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states it finds semantic references to PHP class or class member. Distinguishes from grep-based matching and sibling tools like rename/move.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Implies use when semantic (not text) references needed, with 'not grep-based'. But no explicit when-not or alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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).

ParametersJSON Schema
NameRequiredDescriptionDefault
resetNoPurge the index and rebuild from scratch
projectPathYesAbsolute path to the PHP project root

TDQS

A4/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided, so description carries full burden. It states it builds/rebuilds the index and checks PSR-4 autoload, but does not disclose side effects (e.g., destructive nature of rebuild) or other behavioral traits like auth needs or rate limits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences with no waste. The first sentence states the core purpose, and the second adds important context. Front-loaded and efficient.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema, but description covers key aspects: purpose, prerequisite behavior, and project setup warnings. Could mention return values or behavior when index exists, but still reasonably complete.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100%, so both parameters are already documented in the schema. The description adds no additional meaning beyond stating the function, meeting the baseline of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool builds or rebuilds the Phpactor project index, with specific verb and resource. It distinguishes from siblings by noting it must run before other phpactor tools.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly says 'Must run before other phpactor tools,' providing clear when-to-use guidance. It also warns about Yii2 projects needing manual setup, but does not explicitly mention when not to use or offer alternatives.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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!

ParametersJSON Schema
NameRequiredDescriptionDefault
destPathYesAbsolute path to the destination PHP file
sourcePathYesAbsolute path to the source PHP file
projectPathYesAbsolute path to the PHP project root

TDQS

A4.2/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It explicitly states that the tool writes directly to disk and updates references project-wide, which is crucial behavioral information. It does not cover all aspects (e.g., rollback, permissions), but the warning about committing work provides adequate transparency for safe use.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is three sentences with no wasted words. The first sentence front-loads the main action and its effects, the second summarizes the purpose, and the third provides a critical warning. Excellent structure and conciseness.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (project-wide modifications) and lack of output schema, the description covers key aspects: what it does, the full impact, and a safety warning. It could mention error handling or performance, but overall it is sufficiently complete for an AI agent to use correctly.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with clear descriptions for all three parameters. The description briefly adds context about moving and renaming, but does not significantly enhance meaning beyond the schema (e.g., format constraints, validation rules). Baseline 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb (Move/rename), resource (PHP class), and specific actions (moves file, updates namespace, updates all references project-wide). It also explicitly says 'This is the tool for full class renames,' distinguishing it from siblings like phpactor_rename_class.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description includes a warning to commit work first and states it's for full class renames, giving usage context. However, it does not explicitly mention when not to use this tool or provide alternatives like phpactor_rename_class for cases where only renaming without moving is needed.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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.

ParametersJSON Schema
NameRequiredDescriptionDefault
dryRunNoPreview changes without writing to files
newFqcnYesNew fully qualified class name (e.g. App\Service\NewName)
filePathYesPath to the PHP file containing the class, relative to projectPath
projectPathYesAbsolute path to the PHP project root

TDQS

A4.4/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full burden. It clearly states the scope (project-wide references) and boundaries (no file rename or class declaration change). However, it does not disclose potential side effects, reversibility, or permission requirements, which would improve transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with two sentences. The first sentence front-loads the main action and scope; the second clarifies limitations and points to an alternative. No wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the 4 parameters and no output schema, the description covers the core functionality and boundary conditions well. It lacks information about return values or success indicators, but is still fairly complete for the agent's decision-making.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 100% coverage with descriptions for all 4 parameters. The tool description does not add additional parameter-level meaning beyond what the schema provides, so a baseline score of 3 is appropriate.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states it updates all references to a PHP class project-wide, listing specific reference types. It distinguishes from sibling phpactor_move_class by explicitly stating what it does NOT do (rename file or modify class declaration).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance on when to use this tool (update references only) and when to use the alternative phpactor_move_class for a full rename. This effectively helps the agent choose between siblings.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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).

ParametersJSON Schema
NameRequiredDescriptionDefault
dryRunNoPreview changes without writing to files
newNameYesNew member name
filePathYesPath to the PHP file containing the class, relative to projectPath
memberNameYesCurrent member name
memberTypeYesType of the member
projectPathYesAbsolute path to the PHP project root

TDQS

A3.7/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses the use of type inference and project-wide updates, which is good. However, it does not mention potential side effects, reversibility, or required permissions. The mutation aspect is implied but not explicitly warned.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise with only two sentences, front-loading the core action. Every sentence provides value, and there is no redundant information.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of the tool (renaming across a project) and the lack of an output schema, the description is somewhat incomplete. It does not mention the dryRun parameter, return value, or error handling, which would be helpful for an agent to understand the full behavior.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters. The tool description adds no additional meaning or context for the parameters beyond what is in the schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action (rename) and the resource (PHP method, property, or constant). It specifies that it updates all references project-wide, which distinguishes it from similar tools. The mention of type inference to avoid incorrect renames adds clarity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies when to use (renaming a member) but does not explicitly state when not to use or provide alternatives among sibling tools. It lacks guidance on choosing between this and tools like phpactor_rename_class or phpactor_move_class.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

TDQS

A4.1/5.0
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
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

  • A
    license
    A
    quality
    C
    maintenance
    Enables LLMs to apply Martin Fowler's 71+ refactoring patterns to codebases through a pluggable, language-agnostic architecture. Supports previewing and applying refactorings, analyzing code smells, and inspecting code structure with safe-by-default operations.
    5
    5
    MIT
  • 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
    A
    quality
    D
    maintenance
    Enables coding agents to perform safe, project-wide Python refactoring (rename, move, extract, inline, change signature, organize imports, etc.) with a dry-run safety contract and LSP-coordinate addressing.
    15
    MIT
  • 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

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/p4it-kft/p4it-phpactor-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server