Skip to content

Repository files navigation

Psalm plugins for AI coding agents

Psalm is a static analyzer that finds security vulnerabilities and bugs in PHP code. Its taint analysis follows user input to the calls where it is dangerous, to find SQL injection, XSS, command injection, path traversal, SSRF and more. This plugin gives an agent:

  • MCP tools to check files or the whole project (psalm_check), to trace each security issue from its source to its sink (psalm_trace), to see the types Psalm infers (psalm_inspect), to find where a symbol is used (psalm_references), and to read the documentation of an issue (psalm_explain);
  • a skill to run Psalm, fix its issues and annotate code, which is the one the Psalm of your project ships;
  • in Claude Code, the language server, which shows Psalm's errors after each edit.

Setup

Install Psalm in the project with composer require --dev vimeo/psalm, and create its config with vendor/bin/psalm --init, or let the agent do it with psalm_install (see below). Then install the plugin, in Claude Code:

/plugin marketplace add psalm/agent-plugins
/plugin install psalm@psalm

Gemini CLI: gemini extensions install https://github.com/psalm/agent-plugins

OpenCode: opencode plugin add github:psalm/agent-plugins

Cursor: agent plugin install https://github.com/psalm/agent-plugins

GitHub Copilot CLI: copilot plugin marketplace add psalm/agent-plugins, then copilot plugin install psalm@psalm

Two environment variables change what the plugin runs:

  • PSALM_PHP: the PHP binary that runs Psalm;
  • PSALM_PROJECT_DIR: the project, if several directories have a psalm.xml.

Other agents: Using Psalm with AI agents.

MCP registry

The MCP registry lists the MCP server as io.github.psalm/psalm, in two packages that bring a psalm.phar for projects without Psalm:

  • an MCP bundle (psalm-VERSION.mcpb, in this repository's releases) for Claude Desktop and other clients that install bundles. It needs php;

  • the image ghcr.io/psalm/psalm-mcp, which needs Docker. It runs with the project mounted at its own path:

    docker run -i --rm --mount type=bind,src="$PWD",dst="$PWD" --workdir "$PWD" ghcr.io/psalm/psalm-mcp

What the plugin runs and sends

  • php scripts/server.php starts when the agent does. It looks for the Psalm of the project (in vendor/, vendor-bin/*/vendor/, tools/, the global Composer packages, then the PATH) and runs its MCP server (psalm-mcp) or, in Claude Code, its language server (psalm-language-server), in the project directory.
  • In a Composer project without Psalm, the MCP server says how to install it, and offers psalm_install, which the agent should call only after you agree. It runs composer require --dev vimeo/psalm (which changes composer.json and composer.lock, downloads from Packagist and GitHub, and runs the project's Composer scripts), then psalm --init if there is no psalm.xml, and hands the session over to the Psalm MCP server, without a restart. psalm --init picks the errorLevel at which the project has few issues now; the agent is told that the issues of the stricter levels are bugs to fix too, up to errorLevel="1".
  • Psalm loads the project's Composer autoloader and the Psalm plugins in its psalm.xml, so use the plugin in projects you trust. psalm_check without paths runs the project's psalm command.
  • The skill runs the scripts of the skill that the project's Psalm ships, in vendor/vimeo/psalm/skills/psalm.
  • The MCP bundle and the image also run the psalm.phar they ship when the project has no Psalm.
  • Nothing is sent anywhere by default. The skill can send a self-contained snippet to https://psalm.dev/check, to check a bug report against the latest Psalm, only after you agree, and it reads the documentation on psalm.dev. Psalm sends its results to https://shepherd.dev only when it runs with --shepherd. The plugin downloads nothing but Psalm, when psalm_install runs, and collects no data.

Releasing

The plugins are released with each Psalm release, under its version. Within an hour of the release, release.yml sets the version in .claude-plugin/plugin.json, .cursor-plugin/plugin.json, gemini-extension.json and package.json on main, tags it vVERSION, creates the GitHub release that Gemini CLI installs, and publishes the OpenCode package to npm. It also publishes the MCP bundle (in the mcp-VERSION release), the image and the registry entry, with the release's psalm.phar. Changes merged into main ship with the next Psalm release.

Run the workflow by hand, with a Psalm version or without one (the latest), to finish a release that failed: it skips what is already published.

Releases

Packages

Used by

Contributors

Languages