Download the PHP package sw9t/php-mcp-tool-definition without Composer
On this page you can find all versions of the php package sw9t/php-mcp-tool-definition. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sw9t/php-mcp-tool-definition
More information about sw9t/php-mcp-tool-definition
Files in sw9t/php-mcp-tool-definition
Package php-mcp-tool-definition
Short Description Zero-dependency PHP library for describing MCP tool definitions via typed PHP classes
License MIT
Informations about the package php-mcp-tool-definition
php-mcp-tool-definition
Zero-dependency PHP library for describing Model Context Protocol (MCP) tool definitions via typed PHP classes.
Produces the exact JSON structure that MCP clients and servers expect, with full support for all four official protocol versions.
Table of Contents
- Requirements
- Installation
- Protocol Version Support
- Quick Start
- Class Reference
- McpSchema
- McpProperty
- Latest — always current version
- V20241105 — McpToolDefinition
- V20250326 — McpToolDefinition + McpToolAnnotations
- V20250618 — McpToolDefinition
- V20251125 — McpToolDefinition + McpToolExecution + TaskSupport
- Usage Examples
- Tool without parameters
- Tool with typed parameters
- Enum constraint
- Nested object
- Array of objects
- Annotations and hints (2025-03-26+)
- Output schema (2025-06-18+)
- Long-running task execution (2025-11-25+)
- Full example — latest version
- Development
- License
Requirements
- PHP >= 8.2
No runtime dependencies. PHPUnit 11 is required for running tests.
Installation
Protocol Version Support
The library ships one namespace per official MCP protocol version. Each version is a class that extends the previous one — fields are strictly additive, so you always get a superset of the older version's output.
| Namespace | Protocol date | New fields |
|---|---|---|
McpToolDefinition\V20241105 |
2024-11-05 | name, description, inputSchema |
McpToolDefinition\V20250326 |
2025-03-26 | annotations (title + behaviour hints) |
McpToolDefinition\V20250618 |
2025-06-18 | title (top-level), outputSchema |
McpToolDefinition\V20251125 |
2025-11-25 | execution (task support mode) |
McpToolDefinition\Latest |
always latest | alias — points to the most recent above |
McpSchema and McpProperty are shared across all versions — import them from the root namespace.
Quick Start
Use McpToolDefinition\Latest to always stay on the most recent protocol version,
or pick a specific versioned namespace if you need to pin to a particular protocol date.
Class Reference
Latest — always current version
The McpToolDefinition\Latest namespace is a stable alias that always points to the most
recent protocol version. Use this if you don't need to pin to a specific protocol version.
When a new MCP protocol version is released and added to the library, the Latest files are
updated to point to it — your use statements stay untouched.
Why is
TaskSupportnot inLatest? PHP does not support extending enums, so it is impossible to create aLatest\TaskSupportthat is a subtype ofV20251125\TaskSupport. Import it directly from the version namespace — it is a simple backed enum and unlikely to change between versions.
McpSchema
Represents a JSON Schema object. Wraps an array of McpProperty instances and builds
the properties map and required array automatically.
When constructed with no arguments it produces {"type":"object","properties":{}} — a valid
empty schema for tools that accept no input.
McpProperty
Represents one property inside a schema. All factory methods accept $name, $description,
and $required. The string factory additionally accepts $enum.
| Factory | JSON type | Extra parameters |
|---|---|---|
McpProperty::string($name, $desc, $req, $enum, $maxLength) |
string |
enum: list<string>, maxLength: int |
McpProperty::integer($name, $desc, $req, $min, $max, $enum) |
integer |
minimum, maximum: int\|float, enum: list<int> |
McpProperty::number($name, $desc, $req, $min, $max) |
number |
minimum, maximum: int\|float |
McpProperty::boolean($name, $desc, $req) |
boolean |
— |
McpProperty::object($name, McpSchema, $desc, $req) |
object |
— |
McpProperty::array($name, McpSchema\|PropertyType, $desc, $req, $minItems, $maxItems) |
array |
minItems, maxItems: int |
Pass PropertyType::StringType (or any other PropertyType) as $items to produce a primitive item schema
(e.g. "items": {"type": "string"}). Pass a McpSchema for arrays of objects.
V20241105 — McpToolDefinition
Minimal tool definition. Suitable for servers running the initial 2024-11-05 protocol.
V20250326 — McpToolDefinition + McpToolAnnotations
Adds annotations with a display title and four behavioural hints.
All annotation fields are optional; null values are omitted from the output.
V20250618 — McpToolDefinition
Adds a top-level title field and outputSchema.
Display name precedence (highest to lowest): title → annotations.title → name.
V20251125 — McpToolDefinition + McpToolExecution + TaskSupport
Adds execution to support long-running tools via the MCP task polling mechanism.
Usage Examples
Tool without parameters
Tool with typed parameters
Enum constraint
Numeric constraints
Array of primitives
Nested object
Array of objects
Annotations and hints (2025-03-26+)
Output schema (2025-06-18+)
Long-running task execution (2025-11-25+)
Full example — latest version
Development
No local PHP installation required — all commands run inside Docker.
License
MIT — see LICENSE.