Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,30 @@ jobs:
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- run: npx --yes @anthropic-ai/claude-code plugin validate --profile directory .

registry:
# The MCP bundle and the image that registry.yml publishes, with the phar of Psalm's master branch
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6
- uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
with:
php-version: '8.5'
coverage: none
- name: Build and check the MCP bundle
run: |
mkdir -p build/mcpb/scripts
curl --fail --location --silent --show-error --output build/mcpb/psalm.phar \
https://github.com/psalm/phar/raw/master/psalm.phar
cp scripts/server.php build/mcpb/scripts/
cp LICENSE README.md build/mcpb/
cp .claude-plugin/icon.png build/mcpb/icon.png
jq '.version = "0.0.1"' registry/manifest.json > build/mcpb/manifest.json
php registry/smoke.php php "$PWD/build/mcpb/scripts/server.php" mcp '{project}'
npx --yes @anthropic-ai/mcpb@2.1.2 validate build/mcpb/manifest.json
npx --yes @anthropic-ai/mcpb@2.1.2 pack build/mcpb build/psalm.mcpb
- name: Build and check the image
run: |
docker build --tag psalm-mcp:smoke --file registry/Dockerfile build/mcpb
php registry/smoke.php docker run -i --rm --mount 'type=bind,src={project},dst={project}' \
--workdir '{project}' psalm-mcp:smoke
30 changes: 30 additions & 0 deletions .github/workflows/npm.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: npm

# Publishes the OpenCode plugin (package.json) for each release tag, through npm trusted publishing

on:
push:
tags:
- 'v*'

permissions:
contents: read

jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6

- uses: actions/setup-node@8fccf151e3ba8038c300f83b40c8fd1e94f9c5ce # v7
with:
node-version: '24'
registry-url: https://registry.npmjs.org

- name: Check the version
run: test "v$(jq -r .version package.json)" = "$GITHUB_REF_NAME"

- run: npm publish --provenance --access public
159 changes: 159 additions & 0 deletions .github/workflows/registry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
name: MCP registry

# Publishes the MCP server of each Psalm release to the MCP registry, as an MCPB bundle (a release asset of this
# repository) and as a container image, both with the launcher and the release's psalm.phar.

on:
schedule:
- cron: '17 */6 * * *'
workflow_dispatch:
inputs:
psalm:
description: The Psalm release to publish (default the latest)
required: false

permissions:
contents: read

concurrency:
group: registry

env:
SERVER_NAME: io.github.psalm/psalm
IMAGE: ghcr.io/psalm/psalm-mcp

jobs:
check:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.release.outputs.version }}
publish: ${{ steps.release.outputs.publish }}
steps:
- id: release
env:
GH_TOKEN: ${{ github.token }}
INPUT_VERSION: ${{ inputs.psalm }}
run: |
version="${INPUT_VERSION:-$(gh release view -R vimeo/psalm --json tagName --jq .tagName)}"
[[ "$version" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]
echo "version=$version" >> "$GITHUB_OUTPUT"
if ! gh api "repos/vimeo/psalm/contents/src/Psalm/Internal/Cli/Mcp.php?ref=$version" --silent 2>/dev/null; then
echo "::notice::Psalm $version has no MCP server"
echo "publish=false" >> "$GITHUB_OUTPUT"
elif curl --silent --fail --output /dev/null \
"https://registry.modelcontextprotocol.io/v0/servers/${SERVER_NAME/\//%2F}/versions/$version"; then
echo "publish=false" >> "$GITHUB_OUTPUT"
else
echo "publish=true" >> "$GITHUB_OUTPUT"
fi

publish:
needs: check
if: needs.check.outputs.publish == 'true'
runs-on: ubuntu-latest
permissions:
contents: write
packages: write
id-token: write
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.check.outputs.version }}
MCPB_VERSION: 2.1.2
MCP_PUBLISHER_VERSION: v1.8.21
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v6

- uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # v2
with:
php-version: '8.5'
coverage: none

- name: Download the phar
run: |
mkdir -p build/mcpb/scripts
gh release download "$VERSION" -R vimeo/psalm -p psalm.phar -D build/mcpb
expected=$(gh release view "$VERSION" -R vimeo/psalm --json assets \
--jq '.assets[] | select(.name == "psalm.phar") | .digest')
test "sha256:$(sha256sum build/mcpb/psalm.phar | cut -d' ' -f1)" = "$expected"

- name: Build the MCP bundle
run: |
cp scripts/server.php build/mcpb/scripts/
cp LICENSE README.md build/mcpb/
cp .claude-plugin/icon.png build/mcpb/icon.png
jq --arg v "$VERSION" '.version = $v' registry/manifest.json > build/mcpb/manifest.json
php registry/smoke.php php "$PWD/build/mcpb/scripts/server.php" mcp '{project}'
npx --yes "@anthropic-ai/mcpb@$MCPB_VERSION" validate build/mcpb/manifest.json
npx --yes "@anthropic-ai/mcpb@$MCPB_VERSION" pack build/mcpb "build/psalm-$VERSION.mcpb"

- uses: docker/setup-qemu-action@99012661954931238ded8c8b007157a8430204e1 # v4
- uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4

- name: Build the image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
context: build/mcpb
file: registry/Dockerfile
load: true
tags: psalm-mcp:smoke

- name: Check the image
run: |
php registry/smoke.php docker run -i --rm --mount 'type=bind,src={project},dst={project}' \
--workdir '{project}' psalm-mcp:smoke

- uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550 # v4
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}

- name: Push the image
uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7
with:
context: build/mcpb
file: registry/Dockerfile
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ env.IMAGE }}:${{ env.VERSION }},${{ env.IMAGE }}:latest

- name: Attach the bundle to a release
run: |
if gh release view "mcp-$VERSION" > /dev/null 2>&1; then
gh release upload "mcp-$VERSION" "build/psalm-$VERSION.mcpb" --clobber
else
gh release create "mcp-$VERSION" "build/psalm-$VERSION.mcpb" --target "$GITHUB_SHA" --latest=false \
--title "Psalm $VERSION MCP server" \
--notes "The MCP server of [Psalm $VERSION](https://github.com/vimeo/psalm/releases/tag/$VERSION) as an MCP bundle, and as the image \`$IMAGE:$VERSION\`."
fi

- name: Write server.json
run: |
jq --arg v "$VERSION" \
--arg bundle "https://github.com/${{ github.repository }}/releases/download/mcp-$VERSION/psalm-$VERSION.mcpb" \
--arg sha "$(sha256sum "build/psalm-$VERSION.mcpb" | cut -d' ' -f1)" \
--arg image "$IMAGE:$VERSION" \
'.version = $v
| .packages[0].identifier = $bundle | .packages[0].fileSha256 = $sha
| .packages[1].identifier = $image' \
registry/server.json > server.json
cat server.json

- uses: sigstore/cosign-installer@881c63bd87e38389154debd8331404ce7ca8a3ab # v4

- name: Download mcp-publisher
run: |
archive=mcp-publisher_linux_amd64.tar.gz
base_url="https://github.com/modelcontextprotocol/registry/releases/download/$MCP_PUBLISHER_VERSION"
curl --fail --location --silent --show-error --output "$archive" "$base_url/$archive"
curl --fail --location --silent --show-error --output "$archive.sigstore.json" "$base_url/$archive.sigstore.json"
cosign verify-blob --bundle "$archive.sigstore.json" \
--certificate-identity "https://github.com/modelcontextprotocol/registry/.github/workflows/release.yml@refs/tags/$MCP_PUBLISHER_VERSION" \
--certificate-oidc-issuer https://token.actions.githubusercontent.com \
"$archive"
tar xzf "$archive" mcp-publisher

- name: Publish to the MCP registry
run: |
./mcp-publisher login github-oidc
./mcp-publisher publish
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/vendor/
composer.lock
.phpunit.cache/
/psalm.phar
/build/
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@ Two environment variables change what the plugin runs:

Other agents: [Using Psalm with AI agents](https://psalm.dev/docs/running_psalm/ai_agents/).

### MCP registry

The [MCP registry](https://registry.modelcontextprotocol.io) 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:

```sh
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/`,
Expand All @@ -42,6 +55,7 @@ Other agents: [Using Psalm with AI agents](https://psalm.dev/docs/running_psalm/
- 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
Expand All @@ -50,4 +64,6 @@ Other agents: [Using Psalm with AI agents](https://psalm.dev/docs/running_psalm/
## Releasing

Set the same version in `.claude-plugin/plugin.json`, `.cursor-plugin/plugin.json`, `gemini-extension.json` and
`package.json`, and tag it.
`package.json`, and tag it. The `v*` tag publishes the OpenCode package to npm (`npm.yml`).

`registry.yml` publishes the MCP bundle, the image and the registry entry of each Psalm release, with its version.
18 changes: 18 additions & 0 deletions registry/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# The MCP server of the Psalm of a project, or of the psalm.phar beside the launcher when the project has none. Run it
# with the project mounted at its own path, so that the paths the agent passes exist in the container:
# docker run -i --rm --mount type=bind,src=$PWD,dst=$PWD --workdir $PWD ghcr.io/psalm/psalm-mcp
FROM php:8.5-cli-alpine

RUN apk add --no-cache --virtual .build-deps $PHPIZE_DEPS linux-headers \
&& docker-php-ext-install pcntl \
&& apk del .build-deps

COPY scripts/server.php /opt/psalm/scripts/server.php
COPY psalm.phar /opt/psalm/psalm.phar

LABEL io.modelcontextprotocol.server.name="io.github.psalm/psalm"
LABEL org.opencontainers.image.source="https://github.com/psalm/agent-plugins"
LABEL org.opencontainers.image.description="Psalm static analysis for PHP as an MCP server"
LABEL org.opencontainers.image.licenses="MIT"

ENTRYPOINT ["php", "/opt/psalm/scripts/server.php", "mcp"]
45 changes: 45 additions & 0 deletions registry/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"manifest_version": "0.3",
"name": "psalm",
"display_name": "Psalm",
"version": "0.0.0",
"description": "Psalm static analysis for PHP: check code, inspect inferred types, find references and explain issues.",
"author": {
"name": "Psalm",
"url": "https://psalm.dev"
},
"homepage": "https://psalm.dev/docs/running_psalm/ai_agents/",
"repository": {
"type": "git",
"url": "https://github.com/psalm/agent-plugins"
},
"license": "MIT",
"icon": "icon.png",
"server": {
"type": "binary",
"entry_point": "scripts/server.php",
"mcp_config": {
"command": "php",
"args": [
"${__dirname}/scripts/server.php",
"mcp",
"${user_config.project}"
]
}
},
"user_config": {
"project": {
"type": "directory",
"title": "PHP project",
"description": "The directory of the PHP project that Psalm analyzes",
"required": true
}
},
"compatibility": {
"platforms": [
"darwin",
"linux",
"win32"
]
}
}
59 changes: 59 additions & 0 deletions registry/server.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
{
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
"name": "io.github.psalm/psalm",
"title": "Psalm",
"description": "Psalm static analysis for PHP: check code, inspect types, find references, explain issues",
"version": "0.0.0",
"websiteUrl": "https://psalm.dev/docs/running_psalm/ai_agents/",
"repository": {
"url": "https://github.com/psalm/agent-plugins",
"source": "github"
},
"packages": [
{
"registryType": "mcpb",
"identifier": "",
"fileSha256": "",
"transport": {
"type": "stdio"
}
},
{
"registryType": "oci",
"identifier": "",
"transport": {
"type": "stdio"
},
"runtimeArguments": [
{
"type": "named",
"name": "--mount",
"description": "The PHP project, mounted at its own path",
"value": "type=bind,src={project},dst={project}",
"isRequired": true,
"variables": {
"project": {
"description": "The directory of the PHP project that Psalm analyzes",
"format": "filepath",
"isRequired": true
}
}
},
{
"type": "named",
"name": "--workdir",
"description": "The PHP project",
"value": "{project}",
"isRequired": true,
"variables": {
"project": {
"description": "The directory of the PHP project that Psalm analyzes",
"format": "filepath",
"isRequired": true
}
}
}
]
}
]
}
Loading
Loading