MCP Connector

Expose PHP tools to MCP clients

Expose PHP application tools to MCP clients with phpClaw's ToolRegistry, default argument guards, and framework adapters.


80
Spark score
out of 100
Updated 24 days ago
Source checked Nov 3, 2026
Version latest
Models
universal

Add to Favorites

Why it matters

Make existing PHP application tools available to compatible clients.

Outcomes

What it gets done

01

Expose an existing ToolRegistry

02

Connect clients through stdio or HTTP

Source

Get it from source

Spark does not host a copy of it.

Open source

Reports

Agent outcome reports

No reports yet

Overview

phpClaw combines a PHP runtime for tool-calling workflows with an MCP server that exposes an existing ToolRegistry. It includes pluggable memory, default security guards, provider selection, and adapters for eight frameworks and CMS platforms. Use it to expose PHP application tools to MCP clients or build tool-driven workflows with memory, pipelines, and graphs. Choose another foundation when the workflow requires embeddings or vector stores.

What it does

phpClaw provides a PHP agent runtime and an MCP server that exposes an application's existing ToolRegistry to compatible clients. Claude Desktop, Claude Code, Cursor, and other MCP clients can call registered tools directly without changes to the tools themselves. Default guards scan tool-call arguments, while the prompt-only code-injection, PII, and message-length guards apply to chat messages rather than tool arguments.

The runtime combines tools, memory, security controls, and a ReAct loop that reasons, acts, observes results, and repeats until it answers or reaches an iteration cap. The max_iterations setting defaults to 20. Tools can work with the shell, HTTP APIs, files, databases, and a codebase. Skills load on demand through load_skill within the reasoning cycle.

When to use - and when NOT to

Use the MCP server when an existing PHP application has tools that should be callable from an MCP client. Use the wider runtime when the application needs a tool-calling loop, swappable memory, or several connected reasoning steps. Example tasks include checking disk usage, reading error logs, checking an API response, counting orders with a read-only SELECT, and finding references to a service in a codebase.

For workflows beyond one call, Pipeline chains prompt templates, agents, structured output, and custom callables with retry and fallback. Graph supports branching, loops, human pause and resume in another process, and fan-out. Branches can run inline or be drained by workers from cron, a queue, or the CLI.

Choose a different foundation for retrieval workflows that require embeddings or vector stores: phpClaw explicitly does not provide those facilities and is not a RAG framework. Its focus is giving language models tools, memory, and controls around an application.

Capabilities

Provider selection can automatically detect Anthropic, OpenAI, Groq, Gemini, Mistral, DeepSeek, or Ollama from environment variables, in that order. A custom OpenAI-compatible endpoint is an opt-in option through PHPCLAW_PROVIDER=custom. The builder also supports explicit provider and model selection. Token-by-token streaming and hybrid streaming with tool calls are available. Anthropic prompt caching uses discounted cache-read pricing for cached input tokens, and Claude's extended thinking is exposed on the response.

Eight message guards are enabled by default: prompt injection, PII, code injection, Unicode, homoglyph, role-switch, destructive SQL, and message length. Rate limiting is optional. ToolOutputGuard sanitizes tool results outside the guard registry, and output sanitization is enabled by default with an option to disable it.

ShellTool accepts only allowlisted commands and checks a fixed, non-overridable command blocklist first. HttpTool checks hostname prefixes and revalidates resolved IP addresses to address DNS rebinding and blocked address ranges. FileReadTool and FileWriteTool stay within a configured workspace and refuse sensitive paths and extensions. Credentials, keys, and security directories are refused unconditionally; vendor and node_modules directories are refused by default.

Providers, tools, memory, guards, and skills are pluggable through registries. Lifecycle hooks provide 44 events across the loop. An optional cloud transport connects a hosted, continuously updated prompt-scan guard.

How to install

Install the MCP package with Composer:

composer require phpclaw/phpclaw-mcp

The core supports PHP 8.1 through 8.4 and requires ext-curl, ext-json, and ext-mbstring, with no framework dependencies. Adapters can have additional requirements. The core license is MIT.

Eight framework and CMS adapters connect the runtime to Laravel, Symfony, Drupal, Magento / Adobe Commerce, WordPress with WooCommerce, Joomla, OpenCart, and PrestaShop. Laravel uses Eloquent, Symfony uses Doctrine, WordPress uses WP-CLI, and Drupal uses Drush. Each adapter supplies an admin chat or CLI and the same three-table memory schema.

Laravel, Symfony, Drupal, and Magento adapters install through Composer. WordPress, Joomla, OpenCart, and PrestaShop adapters are distributed as ZIP downloads for installation through their host platforms. Supported versions include Laravel 10-13, Symfony 6.4/7.x/8.x, Drupal 10/11, Magento 2.4.x, WordPress 6.2+, Joomla 4-6, OpenCart 3.x/4.x, and PrestaShop 8.x/9.x.

Who it's for

phpClaw is built for the PHP community, including developers extending applications in the supported frameworks and CMS platforms. The MCP package serves developers who want to expose their application tools through the Model Context Protocol. Developers creating adapters or custom tools can extend the runtime through subsystem attributes and registration methods.

Source README

phpclawphpclaw

Core TestsPHP VersionLicense: MITVersionDownloads

The universal AI agent engine for PHP.

phpClaw demo: composer require phpclaw/phpclaw-laravel, then the agent calls real shell tools to check disk usage and clean logs

First agent in seconds

composer require phpclaw/phpclaw
export ANTHROPIC_API_KEY="sk-ant-..."
$agent = PhpClaw\Claw::builder()->build();
echo $agent->send('What can you help me with?')->text;

One env var, one builder, one send(). The builder checks ANTHROPIC_API_KEY, then OPENAI_API_KEY, GROQ_API_KEY, GEMINI_API_KEY, MISTRAL_API_KEY, DEEPSEEK_API_KEY, OLLAMA_HOST, in that order, and uses whichever it finds first. No YAML, no agent framework to learn, no vendor lock-in.

Give your agent tools

An agent without tools can only talk. Register the ones your application needs and it starts doing real work:

use PhpClaw\Claw;
use PhpClaw\Tools\ShellTool;
use PhpClaw\Tools\HttpTool;
use PhpClaw\Tools\FileReadTool;
use PhpClaw\Tools\DatabaseQueryTool;
use PhpClaw\Tools\CodeSearchTool;

$agent = Claw::builder()
    ->tools([
        new ShellTool(allowlist: ['ls', 'df', 'tail']),
        new HttpTool(),
        new FileReadTool(),
        new DatabaseQueryTool($pdo),
        new CodeSearchTool(),
    ])
    ->build();
> Check disk usage and tail the last 20 lines of the error log
> Is api.example.com responding right now?
> Run a read-only SELECT to count today's orders
> Find every place UserService is used in this codebase

The agent decides which tools to call and in what order, running a ReAct loop (reason, act, observe, repeat) until it has an answer or hits the iteration cap. This works identically whether the tools touch your shell, your database, your HTTP APIs, or your codebase.

Why phpClaw

Every "AI in PHP" tutorial ends the same way: an HTTP client bolted onto a provider API, a hand-rolled tool-call loop, and a prayer that the prompt holds up in production. A generic LLM SDK gives you the API client. phpClaw gives you the agent runtime around it: the loop, the guards, the memory, the framework wiring, already assembled.

phpClaw Generic LLM SDK
Tool-calling loop ReAct, built in You write it
Framework-native adapters 8, idiomatic per framework None
Prompt injection defence 8 default guards + opt-in rate limiting None
Memory abstraction Swappable drivers None
Streaming + tool-calls together Hybrid mode Varies
MCP server bundled Expose any app to Claude Desktop None
Chains and multi-agent graphs Pipeline and Graph: loops, human pause and resume, fan-out You build it
Zero framework deps in core ext-curl, ext-json, ext-mbstring, done Depends
Core license MIT, nothing gated Varies

Not trying to be everything. phpClaw isn't a RAG framework: there are no embeddings or vector stores. It's built to give an LLM tools, memory and security controls against your real application, and to chain those agents into pipelines and graphs when one call isn't enough.

What phpClaw provides

Agent runtime. A ReAct loop with a hard iteration cap (max_iterations, default 20), pluggable tools, pluggable memory, and skills the model loads on demand through the load_skill tool, all running inside a single reasoning cycle.

Pipelines and graphs. Pipeline chains steps (prompt template, agent, structured output, your own callables) with retry and fallback. Graph runs nodes that loop, branch, pause for a human, resume in another process, and fan out to branches that run inline or are drained by workers from cron, a queue or the CLI. See Pipelines and Graphs.

Provider flexibility. 7 providers auto-detected from environment variables: Anthropic, OpenAI, Groq, Gemini, Mistral, DeepSeek, Ollama. A custom OpenAI-compatible endpoint is also supported, opt-in via PHPCLAW_PROVIDER=custom. Switch providers with ->provider() and ->model(), no code changes elsewhere.

Production controls. 8 security guards on by default (prompt injection, PII, code injection, Unicode, homoglyph, role-switch, destructive SQL, message length), plus rate limiting available as an opt-in guard. Tool results are sanitised unconditionally by ToolOutputGuard, which sits outside the guard registry, and LLM output sanitisation is on by default and can be disabled with ->sanitiseOutput(false). ShellTool is allowlist-only with a hard-coded command blocklist that can't be overridden. HttpTool validates resolved IPs, not just hostnames, closing the DNS-rebinding gap a prefix blocklist alone would miss. FileReadTool/FileWriteTool are workspace-sandboxed and refuse sensitive paths and extensions.

Developer experience. Token-by-token streaming, prompt caching (cached input tokens billed at Anthropic's discounted cache-read rate, see Anthropic's pricing for the exact figure), and extended thinking (Claude's reasoning chain exposed on $response->thinking).

Ecosystem. 8 framework and CMS adapters, an MCP server for exposing your tools to Claude Desktop and Claude Code, and an optional cloud transport for a hosted, continuously-updated prompt-scan guard.

Framework & CMS adapters

Each adapter wires phpClaw into its host's own idioms: Eloquent for Laravel, Doctrine for Symfony, WP-CLI for WordPress, Drush for Drupal, and so on. Every adapter ships an admin chat or CLI and the same 3-table memory schema underneath.

Platform Package Install Versions
Laravel phpclaw/phpclaw-laravel Composer 10, 11, 12, 13
Symfony phpclaw/phpclaw-symfony Composer 6.4, 7.x, 8.x
Drupal phpclaw/phpclaw-drupal Composer 10, 11
Magento / Adobe Commerce phpclaw/phpclaw-magento Composer 2.4.x
WordPress + WooCommerce -- ZIP upload 6.2+
Joomla -- ZIP upload 4, 5, 6
OpenCart -- ZIP upload 3.x, 4.x
PrestaShop -- ZIP upload 8.x, 9.x

CMS adapters ship as ZIP downloads from Releases, not Composer, because that's how their host platforms install extensions.

php artisan phpclaw "deploy staging and notify #ops"          # Laravel
bin/console phpclaw "check all database connections"          # Symfony
drush phpclaw:run "list recently-active users"                # Drupal
bin/magento phpclaw:run "check order-queue status"             # Magento
wp phpclaw send "summarise today's posts"                     # WordPress
php cli/joomla.php phpclaw "list recent articles"              # Joomla
php cli/phpclaw.php send "check low stock products"            # OpenCart
php modules/phpclaw/cli/phpclaw.php send "check stock levels"  # PrestaShop

Full per-adapter reference (tools, REST routes, CLI commands, settings, memory drivers) lives on the doc site. Each adapter's own README is a short pointer, not a manual. Building a new one? See the community adapter guides.

MCP Server

phpclaw/phpclaw-mcp exposes your existing ToolRegistry over the Model Context Protocol, so Claude Desktop, Claude Code, Cursor, or any MCP-compatible client can call your tools directly, with the default guards scanning every tool call's arguments (the prompt-only code-injection, PII and length guards apply to chat messages, not tool arguments). No changes to the tools themselves.

composer require phpclaw/phpclaw-mcp

Full quick start, transport, and security details: phpclaw.ai/docs/mcp.

Security

Every message runs through the default guard chain before it reaches the provider. ShellTool runs only commands on its allowlist (default ls, pwd, df, wc, date, uptime, hostname, whoami), matched exactly and case-sensitively; a fixed, non-overridable blocklist of dangerous commands is checked first regardless of what's allowlisted. HttpTool blocks requests by hostname prefix, then re-validates every resolved IP address, catching CGNAT and DNS-rebinding attempts that hostname checks alone would miss. FileReadTool and FileWriteTool are sandboxed to a configured workspace root and refuse credentials, keys and security directories (.git, .ssh, wp-admin, ...) unconditionally, and vendor/ and node_modules/ by default.

Full guard reference, the exact ShellTool blocklist, and the SSRF/sandbox implementation details: phpclaw.ai/docs/security. Found a vulnerability? See SECURITY.md, do not open a public issue.

Architecture

Message
  → Guards       (blocks injection/PII before the LLM sees it)
  → Hooks         (lifecycle events fire, 44 across the loop)
  → Agent          (ReAct loop: provider + tools + memory + skills)
  → AgentResponse  (text, tokens, tool calls, timing)

Providers, tools, memory, guards, and skills are all pluggable through registries; every adapter wires them from its own config or environment. Full architecture diagram and design rules: phpclaw.ai/docs/architecture.

Extensibility

Five static registries (GuardRegistry, HookRegistry, MemoryRegistry, ProviderRegistry, SkillRegistry) plus the per-agent ToolRegistry instance. Drop a class in packages/core/src/<Subsystem>/ with the matching attribute (#[Tool], #[Provider], #[Memory], #[Skill], #[Hook], #[Guard]), run composer dump-autoload, it's live. Or register from code: GuardRegistry::register(), HookRegistry::on(), $toolRegistry->register([...]).

Full extension recipes with working code for every subsystem: phpclaw.ai/docs.

Testing

for pkg in core cloud mcp; do (cd packages/$pkg && composer test); done

Unit tests use mocks and stubs for HTTP clients, \Redis, and the filesystem: no external network calls and no API keys are needed to run the suite for core, cloud, or mcp. The full testing rules, including how to test a core change through an adapter, are in the contributing guide.

Documentation

This README gets you installed. Everything else, architecture, the full provider/tool/guard/hook/memory/skill reference, per-adapter tool and REST tables, code examples, upgrading, troubleshooting, lives at:

phpclaw.ai/docs

Requirements

  • PHP: 8.1, 8.2, 8.3, 8.4
  • Extensions: ext-curl, ext-json, ext-mbstring (core only; adapters may need more, documented per-package)

Discussion

Questions & comments · 0

Sign In Sign in to leave a comment.