lthn/php-mcp
Composer 安装命令:
composer require lthn/php-mcp
包简介
MCP (Model Context Protocol) tools module for Core PHP framework
README 文档
README
Model Context Protocol (MCP) tools and analytics for AI-powered automation and integrations.
Installation
composer require lthn/php-mcp
Features
MCP Tool Registry
Extensible tool system for AI integrations:
use Core\Mcp\Tools\BaseTool;
class GetProductsTool extends BaseTool
{
public function name(): string
{
return 'get_products';
}
public function description(): string
{
return 'Retrieve a list of products from the workspace';
}
public function schema(JsonSchema $schema): array
{
return [
'limit' => $schema->integer('Maximum number of products to return'),
];
}
public function handle(Request $request): Response
{
$products = Product::take($request->input('limit', 10))->get();
return Response::text(json_encode($products));
}
}
Workspace Context Security
Prevents cross-tenant data leakage:
use Core\Mcp\Tools\Concerns\RequiresWorkspaceContext;
class MyTool extends BaseTool
{
use RequiresWorkspaceContext;
// Automatically validates workspace context
// Throws exception if context is missing
}
SQL Query Validation
Multi-layer protection for database queries:
use Core\Mcp\Services\SqlQueryValidator;
$validator = new SqlQueryValidator();
$validator->validate($query); // Throws if unsafe
// Features:
// - Blocked keywords (INSERT, UPDATE, DELETE, DROP)
// - Pattern detection (stacked queries, hex encoding)
// - Whitelist matching
// - Comment stripping
Tool Analytics
Track tool usage and performance:
use Core\Mcp\Services\ToolAnalyticsService;
$analytics = app(ToolAnalyticsService::class);
$stats = $analytics->getToolStats('get_products');
// Returns: calls, avg_duration, error_rate, etc.
Admin dashboard: /admin/mcp/analytics
Tool Dependencies
Declare tool dependencies and validate at runtime:
use Core\Mcp\Dependencies\{HasDependencies, ToolDependency};
class AdvancedTool extends BaseTool implements HasDependencies
{
public function dependencies(): array
{
return [
new ToolDependency('get_products', DependencyType::REQUIRED),
new ToolDependency('send_email', DependencyType::OPTIONAL),
];
}
}
MCP Playground
Interactive UI for testing tools:
Route: /admin/mcp/playground
Features:
- Tool browser with search
- Dynamic form generation
- JSON response viewer
- Conversation history
- Example pre-fill
Query EXPLAIN Analysis
Performance insights for database queries:
{
"query": "SELECT * FROM users WHERE email = ?",
"explain": true
}
Returns:
- Raw EXPLAIN output
- Performance warnings
- Index usage analysis
- Optimization recommendations
Usage Quotas
Workspace-level rate limiting:
use Core\Mcp\Services\McpQuotaService;
$quota = app(McpQuotaService::class);
// Check if workspace can execute tool
if (!$quota->canExecute($workspace, 'expensive_tool')) {
throw new QuotaExceededException();
}
// Record execution
$quota->recordExecution($workspace, 'expensive_tool');
Configuration
// config/mcp.php
return [
'database' => [
'connection' => 'readonly', // Dedicated read-only connection
'use_whitelist' => true,
'blocked_tables' => ['users', 'api_keys'],
],
'analytics' => [
'enabled' => true,
'retention_days' => 90,
],
'quota' => [
'enabled' => true,
'default_limit' => 1000, // Per workspace per day
],
];
Security
Query Security (Defense in Depth)
- Read-only database user (infrastructure)
- Blocked keywords (application)
- Pattern validation (application)
- Whitelist matching (application)
- Table access controls (application)
Workspace Isolation
- Context MUST come from authentication
- Cross-tenant access prevented by design
- Tools throw exceptions without context
See changelog/2026/jan/security.md for security updates.
Requirements
- PHP 8.2+
- Laravel 11+ or 12+
Changelog
See changelog/2026/jan/features.md for recent changes.
License
EUPL-1.2 - See LICENSE for details.
lthn/php-mcp 适用场景与选型建议
lthn/php-mcp 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 0 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 03 月 09 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「tools」 「laravel」 「ai」 「mcp」 「claude」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 lthn/php-mcp 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 lthn/php-mcp 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 lthn/php-mcp 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
A Laravel package to retrieve data from Google Search Console
Secure HTTP transport wrapper for MCP servers with API key auth, IP/Origin allowlisting, and rate limiting
Standardized event classes for MCP (Model Context Protocol) tool execution lifecycle
JSON Schema builder and validator for MCP tool definitions
GHT D-Tools Bundle
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 15
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: EUPL-1.2
- 更新时间: 2026-03-09