Download the PHP package polygonlab/mcp-php-kit without Composer

On this page you can find all versions of the php package polygonlab/mcp-php-kit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package mcp-php-kit

mcp-php-kit

Build MCP (Model Context Protocol) servers in plain PHP, hosted on any classic PHP hosting, with an optional Cloudflare Worker in front.

CI Version

Why

Most MCP servers are written for Node.js or Python and run as long-lived processes. Many applications, though, live on PHP hosting where nothing runs between two requests: Apache or Nginx with PHP-FPM, no daemon, no Node. This kit implements the MCP Streamable HTTP transport as a plain PHP endpoint: each request is self-contained, the server keeps no state, and an index.php of fifteen lines is enough. It has no runtime dependency, validates every argument against the tool's JSON Schema before calling your code, and comes with an optional Cloudflare Worker that adds a bearer token check and a rate limit before traffic reaches your server.

Features

Installation

Quick start

Create index.php:

Start it with the PHP built-in server (or put it behind Apache or Nginx):

Call the add tool:

Expected response (this example is examples/minimal/index.php, and a test runs this exact request against it):

To connect Claude, add the URL of the endpoint as a custom connector (remote MCP server), with the bearer token described below.

Usage

Declaring tools with attributes

Mark public methods with #[Tool]; refine a parameter with #[Param]. The input schema is generated from the parameter types, and the arguments are passed by name.

The full example, with authentication, is in examples/attributes/.

PHP parameter JSON Schema Notes
string, int, float, bool string, integer, number, boolean 2.0 is accepted for an int
array array #[Param(items: [...])] describes the items
Backed enum string or integer with enum The method receives the enum case
?type or a default value Not in required The default value is published as default
Anything else Refused at registration Describe it with #[Param(schema: [...])]

#[Param] options: description, minimum, maximum, minLength, maxLength, pattern, enum, items, schema (replaces the generated schema) and header (mirrors the value in the Mcp-Param-{header} HTTP header, x-mcp-header in the specification).

Registering callables

With an explicit inputSchema, the arguments are still passed to the callable by name.

Results and errors

The tool… The client receives
returns a string one text content block
returns an array, a number, a boolean or a JsonSerializable structuredContent, and the same value as JSON text
returns ToolResult::text(...), ToolResult::structured(...) or ToolResult::error(...) exactly that result
returns null an empty content list
receives arguments that do not match its schema isError: true and the list of problems, without being called
throws ToolError isError: true and the message of the exception
throws any other exception JSON-RPC error -32603 Internal error; the message is never sent, only logged by class

ToolError messages are read by the language model: make them short and actionable.

Supported JSON Schema

Dialect 2020-12. Validated keywords: type, enum, const, properties, required, additionalProperties, items, minItems, maxItems, minimum, maximum, exclusiveMinimum, exclusiveMaximum, minLength, maxLength, pattern. Annotations title, description, default, examples, format and x-mcp-header are accepted. Any other keyword ($ref, anyOf, oneOf…) is refused when the tool is registered, so that no part of a schema is silently ignored.

Authentication

Cloudflare Worker

The worker/ folder holds an optional Worker (JavaScript modules, no runtime dependency) to place in front of the PHP server. For each request it:

  1. refuses any Origin header that is not in ALLOWED_ORIGINS (403);
  2. accepts POST only, and OPTIONS for the CORS preflight (405 otherwise);
  3. limits the rate per IP address with the Workers Rate Limiting API (429);
  4. checks the bearer token stored in the MCP_TOKEN secret, in constant time (401);
  5. refuses bodies larger than MAX_BODY_BYTES (413);
  6. relays the request to ORIGIN_URL with the MCP headers only, plus the shared secret header (X-Mcp-Origin-Secret), never following redirects;
  7. writes one JSON log line (method, status, duration), without token, body or IP address.

Deployment, step by step:

  1. Install Node.js 22 or later, then, from the worker/ folder: npm install.
  2. Copy the configuration: cp wrangler.toml.example wrangler.toml, then set ORIGIN_URL (the URL of your index.php) and, if browsers call the server, ALLOWED_ORIGINS.
  3. Log in to Cloudflare: npx wrangler login.
  4. Store the secrets (the values are typed at the prompt, never written in a file): npx wrangler secret put MCP_TOKEN and npx wrangler secret put ORIGIN_SECRET (ORIGIN_SECRET: 32 characters or more, for example php -r 'echo bin2hex(random_bytes(32)), PHP_EOL;').
  5. Deploy: npx wrangler deploy. Wrangler prints the URL of the Worker: give it to your MCP client.
  6. On the PHP side, use SharedSecretAuthenticator with the same ORIGIN_SECRET.
  7. Check: a request without token gets 401 from the Worker; a direct request to the PHP server gets 403.
Setting Kind Default Role
MCP_TOKEN secret (required) Accepted bearer token(s), comma-separated for a rotation
ORIGIN_SECRET secret (required) Shared value added to relayed requests, 32 characters or more
ORIGIN_URL variable (required) URL of the PHP server, https (http for localhost only)
ALLOWED_ORIGINS variable empty Browser origins allowed, comma-separated
ORIGIN_SECRET_HEADER variable X-Mcp-Origin-Secret Header carrying the shared secret
MAX_BODY_BYTES variable 1048576 Largest accepted body
FORWARD_AUTHORIZATION variable false true to relay Authorization to PHP as well
MCP_RATE_LIMITER binding none Rate limiting binding ([[ratelimits]] in wrangler.toml)

Rate limiting relies on the Workers Rate Limiting API: the example allows 60 requests per minute and per IP address, counted per Cloudflare location (an approximate, not a global, counter). Without the binding the Worker still works, without rate limit; you can then add a rate limiting rule in the Cloudflare dashboard (WAF) instead.

The Worker fails closed: with a missing or invalid setting, it answers 500 to every request and logs which setting is wrong.

Configuration

Builder method Type Default Role
withTitle() string none Human-readable name in serverInfo
withInstructions() string none Guidance for the model, sent by server/discover and initialize
withTool() name, description, callable, schema, title none Registers a callable as a tool
withToolsFrom() object none Registers the #[Tool] methods of an object
withAuthenticator() Authenticator none Authentication of every request
withAllowedOrigins() list<string> empty Browser origins allowed (scheme://host[:port])
withLogger() Logger NullLogger Log sink; new CallableLogger($psrLogger->log(...)) for PSR-3
withPageSize() int 50 Tools per tools/list page
withCacheHints() int, ?string 60000, automatic ttlMs and cacheScope of tools/list and server/discover; scope private when an authenticator is set
withMaxBodyBytes() int 1048576 Largest request body

Logged events: request handled (info: method, status, duration), request rejected (warning: reason, status), tool failure (error: tool, exception class, file and line). Arguments, results, tokens and exception messages are never logged.

Compatibility

Item Supported
MCP specification 2026-07-28, the latest published revision; also 2025-11-25 and 2025-06-18 through the initialize handshake
Transport Streamable HTTP, POST with application/json responses
PHP 8.2, 8.3 and 8.4, tested by continuous integration; extensions json and mbstring
Hosting Apache or Nginx with PHP-FPM, any host that runs PHP; no daemon, no Node.js
Worker Cloudflare Workers (JavaScript modules); tests on Node.js 22, 24 and 26

Version negotiation: a request carrying _meta["io.modelcontextprotocol/protocolVersion"] is served statelessly under 2026-07-28; an initialize request opens a 2025 session, answered with the requested version when supported, otherwise with 2025-11-25. Any other version gets 400 and the error -32022 with the list of supported versions.

Limitations

Tests

Contributing

See CONTRIBUTING.md.

Security

What the kit does:

What it does not do:

To report a vulnerability, never open a public issue: see SECURITY.md.

License

MIT License: see LICENSE.


— Conçu et développé par PolygonLab · polygonlab.ai · Licence MIT


All versions of mcp-php-kit with dependencies

PHP Build Version
Package Version
Requires php Version >=8.2
ext-json Version *
ext-mbstring Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package polygonlab/mcp-php-kit contains the following files

Loading the files please wait ...