No description
Find a file
Snider fc1c2ef573 refactor: update namespaces for L1 package convention
- Mod\Mcp -> Core\Mcp
- Core\Mod\Tenant -> Core\Tenant

Part of namespace restructure to align with L1/L2 module conventions.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-27 17:34:35 +00:00
.gemini Initial commit 2026-01-26 20:49:02 +00:00
.github Initial commit 2026-01-26 20:49:02 +00:00
app Initial commit 2026-01-26 20:49:02 +00:00
bootstrap Initial commit 2026-01-26 20:49:02 +00:00
changelog/2026/jan refactor: move MCP module from Core\Mod\Mcp to Core\Mcp namespace 2026-01-27 16:26:14 +00:00
config Initial commit 2026-01-26 20:49:02 +00:00
database Initial commit 2026-01-26 20:49:02 +00:00
public Initial commit 2026-01-26 20:49:02 +00:00
resources Initial commit 2026-01-26 20:49:02 +00:00
routes Initial commit 2026-01-26 20:49:02 +00:00
src refactor: update namespaces for L1 package convention 2026-01-27 17:34:35 +00:00
storage Initial commit 2026-01-26 20:49:02 +00:00
tests Initial commit 2026-01-26 20:49:02 +00:00
.editorconfig Initial commit 2026-01-26 20:49:02 +00:00
.env.example Initial commit 2026-01-26 20:49:02 +00:00
.gitattributes Initial commit 2026-01-26 20:49:02 +00:00
.gitignore Initial commit 2026-01-26 20:49:02 +00:00
AGENTS.md Initial commit 2026-01-26 20:49:02 +00:00
artisan Initial commit 2026-01-26 20:49:02 +00:00
CLAUDE.md Initial commit 2026-01-26 20:49:02 +00:00
cliff.toml Initial commit 2026-01-26 20:49:02 +00:00
composer.json refactor: move MCP module from Core\Mod\Mcp to Core\Mcp namespace 2026-01-27 16:26:14 +00:00
GEMINI.md Initial commit 2026-01-26 20:49:02 +00:00
LICENSE Initial commit 2026-01-26 20:49:02 +00:00
package.json Initial commit 2026-01-26 20:49:02 +00:00
phpunit.xml Initial commit 2026-01-26 20:49:02 +00:00
postcss.config.js Initial commit 2026-01-26 20:49:02 +00:00
README.md monorepo sepration 2026-01-26 20:57:41 +00:00
tailwind.config.js Initial commit 2026-01-26 20:49:02 +00:00
TODO.md monorepo sepration 2026-01-26 20:57:41 +00:00
vite.config.js Initial commit 2026-01-26 20:49:02 +00:00

Core MCP Package

Model Context Protocol (MCP) tools and analytics for AI-powered automation and integrations.

Installation

composer require host-uk/core-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)

  1. Read-only database user (infrastructure)
  2. Blocked keywords (application)
  3. Pattern validation (application)
  4. Whitelist matching (application)
  5. 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.