Download the PHP package organiseyou/mcp-server without Composer
On this page you can find all versions of the php package organiseyou/mcp-server. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download organiseyou/mcp-server
More information about organiseyou/mcp-server
Files in organiseyou/mcp-server
Package mcp-server
Short Description Drop-in MCP (Model Context Protocol) server for Laravel applications
License MIT
Informations about the package mcp-server
Laravel MCP
A Model Context Protocol (MCP) server for Laravel built around runtime tool registration. Tools are registered programmatically at request time rather than declared upfront as static classes, making this package the right choice when your tool surface is dynamic — multi-tenant platforms, schema-driven APIs, feature-flagged environments, or anything else where you don't know your tools at boot time.
If your tools are static and known at boot time, laravel/mcp (the official first-party package) is likely the better fit.
Requirements
- PHP 8.2+
- Laravel 11+
Installation
The service provider and Mcp facade are registered automatically via Laravel's package discovery.
Publish the config file:
Configuration
config/mcp.php:
Registering Tools
Inline via the Mcp facade (dynamic)
Register tools anywhere that runs before the request is handled — a service provider, middleware, or a tenant boot hook:
A multi-tenant example where tools are generated from tenant configuration:
Class-based tools (static)
For tools that are the same across all tenants or contexts, implement OrganiseYou\McpServer\Contracts\McpTool and register the class in config/mcp.php:
Tools are resolved from the Laravel container, so constructor dependencies are injected automatically.
Tool context
A tool receives a ToolContext as its second argument only when it declares one. One-argument tools are called exactly as before.
Class tools can add an optional parameter: public function __invoke(array $input, ?ToolContext $context = null): mixed.
The package never reads tenants or users itself. Supply the context by binding it in the container, for example from middleware or a service provider. Use scoped() so it is rebuilt per request:
If nothing is bound, tools get an empty context. The JSON-RPC id fills requestId unless your bound context already sets one.
Reporting tool errors
Throw ToolError for expected failures. The call returns isError: true with a JSON body, so the client can tell "you may not do this" from "the server is broken":
Any other exception is still returned as a JSON-RPC error.
Annotations
Declare tool annotations so clients can tell reads from writes. They appear in tools/list only for tools that set them. The package adds no defaults.
Class tools: add a public function annotations(): array method.
Supported keys: readOnlyHint, destructiveHint, idempotentHint, openWorldHint.
Calling tools in-process
McpServer::callTool() runs a tool without HTTP or JSON-RPC. It returns the same array as tools/call:
Long-lived workers
The registry, server and transports are bound with scoped(). Under Octane or in a queue worker, each request starts with an empty registry (plus the class tools from config), so tools registered for one tenant never leak into the next request.
Logging
Logging is off by default. Enable it in .env:
Or publish the config (php artisan vendor:publish --tag=mcp-config) and set:
To keep secrets out of the logged tool input, set redact to a callable or an invokable class name. It receives the input and returns the copy to log. The tool itself still gets the original input. Use a class name if you run config:cache, because closures can't be cached.
When enabled, the following is logged automatically:
| Event | Message | Context keys |
|---|---|---|
| Request received | MCP request |
method, id |
| Request completed | MCP response |
method, id, duration_ms |
| Tool invoked | MCP tool call |
tool, input |
| Tool returned | MCP tool result |
tool, duration_ms |
Tool threw ToolError |
MCP tool error |
tool, reason, message |
| Any error | MCP error |
code, message, id |
Errors always log at warning level regardless of MCP_LOG_LEVEL.
Logging inside tools
Class-based tools — inject McpLogger and call logActivity():
logActivity() respects the same channel, level, and any extended context (e.g. tenant ID) as the rest of the logger.
Closure-based tools — use Laravel's Log facade directly:
Multi-tenant: adding tenant context to every log entry
Extend McpLogger, override context(), and rebind the singleton:
Every log entry — from the server, from tool calls, and from logActivity() inside your tools — will automatically include tenant_id. No changes required to individual tools.
Transports
HTTP (default)
When mcp.transport.http is true, the package registers a POST /mcp route. Any MCP client that supports HTTP can point to https://your-app.test/mcp.
To secure the endpoint, add middleware in config/mcp.php:
Stdio (Claude Desktop / local clients)
Run the artisan command to start an stdio MCP server:
Add it to your claude_desktop_config.json:
Protocol
The server speaks JSON-RPC 2.0 and supports MCP protocol versions 2025-03-26 and 2024-11-05. On initialize it echoes the client's version if it supports it, and otherwise offers 2025-03-26. Supported methods:
| Method | Description |
|---|---|
initialize |
Handshake, returns server info and capabilities |
ping |
Health check |
tools/list |
List all registered tools |
tools/call |
Invoke a tool by name |
Example HTTP request
Calling a tool:
Batch requests are also supported — send an array of JSON-RPC objects and receive an array of responses.
Testing
Or with Docker (no local PHP required):
License
MIT