Download the PHP package muxtorov98/yii2-mcp without Composer
On this page you can find all versions of the php package muxtorov98/yii2-mcp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download muxtorov98/yii2-mcp
More information about muxtorov98/yii2-mcp
Files in muxtorov98/yii2-mcp
Package yii2-mcp
Short Description Model Context Protocol (MCP) server integration for Yii2 applications.
License MIT
Informations about the package yii2-mcp
yii2-mcp
MCP server integration for Yii2 applications on PHP 8.1+.
This package exposes Yii2 classes as MCP tools and MCP resources so AI agents can discover and call them through a standard JSON-RPC endpoint.
Package: muxtorov98/yii2-mcp
What This Package Does
- exposes Yii2 classes as MCP
tools - exposes read-only content as MCP
resources - generates JSON Schema from PHP classes and Yii models
- supports Yii2 validation for tool input
- provides an HTTP MCP endpoint for AI clients
What This Package Does Not Do
This package is an MCP server. It is not an LLM provider SDK.
That means:
yii2-mcpdoes not choose OpenAI, Claude, Gemini, or any other modelyii2-mcpdoes not send prompts to an LLM by itself- the AI client chooses the model
Typical setup:
Yii2 + yii2-mcp= MCP serverChatGPT / Claude Desktop / Cursor / other agent= MCP client- model selection = inside the client
If you also want Yii2 itself to call an LLM, add a separate AI client component such as OpenAiClient, AnthropicClient, or your own adapter.
Requirements
- PHP
^8.1 - Yii2
^2.0 ext-json
Install
How It Works
- You create PHP classes and mark them with
#[McpTool]or#[McpResource]. - The
mcpcomponent scans configured folders. - The package builds MCP metadata and input schemas.
- AI clients connect to your
/mcpendpoint. - The client lists tools/resources and calls them when needed.
Minimal Working Setup
1. Configure the mcp component
Example for common/config/main.php or another shared config:
Notes:
pathmust point to the folder containing your MCP classesnamespacemust match those PHP classes- for web apps, the package bootstrap automatically registers
mcp/index
Production-ready config example
If you want to run this package in a more serious environment, enable authentication, rate limiting, cache, and logging explicitly:
This package now includes:
- API key or Bearer token auth
- cache-backed rate limiting
- registry/schema caching through Yii cache
- request and error logging
- safer internal error masking for production
Optional custom controller mapping
If you want your own controller namespace or route, map the package controller explicitly in your app config:
If you want a project-specific controller, extend the package controller:
File: frontend/controllers/McpController.php
Then map it:
2. Create the folder for MCP classes
Example:
3. Create a tool input class
File: common/mcp/SearchBooksInput.php
4. Create the tool handler
File: common/mcp/SearchBooksHandler.php
5. Create a resource
File: common/mcp/ApiDocsResource.php
File: common/mcp/ApiDocsProvider.php
6. Start your Yii2 web app
Your MCP endpoint will be available at:
If you use pretty URLs and route rules, you can map it to /mcp.
Example pretty URL rule:
AI Model Selection
This is the part most people mix up.
You do not set the AI model inside yii2-mcp.
You set the model inside the MCP client:
- ChatGPT app or OpenAI-based client
- Claude Desktop
- Cursor
- custom MCP client
Example logic:
- client connects to
https://your-domain.com/mcp/index - client reads
tools/list - client decides when to call
search_books - client uses its own selected model to reason over the results
If You Also Want Yii2 To Call OpenAI
That is separate from MCP. Add your own AI component.
Example config:
In this setup:
aicomponent calls the LLMmcpcomponent exposes tools/resources to external AI agents
These are different responsibilities.
Supported MCP Methods
The HTTP JSON-RPC endpoint currently supports:
initializepingtools/listtools/callresources/listresources/read
JSON-RPC Examples
Initialize
List Tools
Call Tool
List Resources
Read Resource
Testing With curl
List tools
Call a tool
Tool Declaration Rules
#[McpTool(...)] options:
name: MCP tool namedescription: human-readable descriptionhandler: handler class nameinput: optional separate input DTO classoutput: optional output DTO classvalidate: run Yii validation if input extendsyii\base\ModelstructuredContent: includestructuredContentin resultmeta: arbitrary metadata
Example:
Resource Declaration Rules
#[McpResource(...)] options:
uri: unique resource identifiername: display namedescription: human-readable descriptionprovider: provider class namemimeType: resource MIME typestructuredContent: reserved for future usemeta: arbitrary metadata
Example:
Validation
Validation is only applied when:
validate: trueis set on the tool- the input class extends
yii\base\Model
Example:
If validation fails, the MCP response returns an error payload.
Input Hydration
Tool input is hydrated by:
- public property assignment
setXxx()setter methods
Example:
This can be mapped to:
$input->query$input->setQuery('design')
Response Shape
Tool responses are normalized into JSON-friendly arrays.
Regular tool result:
Resource result:
Folder Layout Suggestion
Current Scope
This package currently provides:
- HTTP-based MCP endpoint
- attribute-based tool/resource discovery
- schema generation
- validation support
- basic tool/resource invocation
This package does not yet provide:
- stdio transport
- OAuth/authentication layer
- advanced MCP session management
- streaming responses
- provider SDK integration
- automatic OpenAPI or Hydra conversion
Troubleshooting
Tools do not appear in tools/list
Check:
discover.pathpoints to the correct folderdiscover.namespacematches the PHP namespace- classes are autoloadable
- class has
#[McpTool]
Validation is not running
Check:
- tool has
validate: true - input class extends
yii\base\Model rules()is defined
Handler is not called
Check:
handlerclass name is correct- handler has
handle($input)method or is invokable - dependency injection can build the class
Resource is not returned
Check:
uriis unique- provider class is valid
- provider has
provide()method or is invokable
Unauthorized response
Check:
authEnabledis enabled intentionally- request sends
Authorization: Bearer ...orX-API-Key: ... - provided token exists in
apiKeysorbearerTokens
Rate limit exceeded
Check:
enableRateLimitis enabled- cache component is configured
rateLimitandrateWindowvalues fit your traffic
Development Notes
This package is currently an MVP skeleton. It is suitable as a starting point for a real Yii2 MCP package and can be extended with:
- authentication
- provider integrations
- stdio bridge
- richer schema customization
- MCP protocol upgrades