labrodev/laravel-mcp-espectro
Laravel connector for the Espectro MCP server, giving AI assistants access to 159 colors and 348 palettes from Sanzo Wada’s Dictionary of Color Combinations. Generates a .mcp.json for Cursor and works with Claude and any MCP client.
Install the package:
composer require labrodev/laravel-mcp-espectro
php artisan espectro:install
This generates .mcp.json in your project root and outputs the MCP endpoint URL.
Configure your AI client:
.mcp.json.https://espectro.dev/mcp/espectro in MCP server settings.First use case: Ask your AI assistant to:
"Search for colors named 'cerulean' using the search-colors tool."
Verify the response includes color details (name, hex, palette).
AI-Assisted Color Selection:
search-combinations with paletteSize: 3.["#E6E6FA", "#F0F8FF", "#DDA0DD"]).Dynamic Theming:
get-color (slug: sacred-gold) + search-combinations (filter by paletteSize: 2).Debugging UI Issues:
get-color to fetch contrast metrics or search-combinations to find high-contrast pairs.Laravel Artisan Commands:
Cache color/combination data locally (e.g., in storage/app/espectro-cache.json) to reduce API calls:
// Example: Fetch and cache combinations
$combinations = Cache::remember('espectro-combinations', now()->addHours(1), function () {
return Http::post('https://espectro.dev/mcp/espectro', [
'tool' => 'search-combinations',
'paletteSize' => 3,
])->json();
});
AI Prompt Templates:
Store reusable prompts in a resources/ai-prompts/ directory and reference them in your AI client:
// resources/ai-prompts/color-palette.md
Use the `search-combinations` tool to find a {paletteSize}-color palette for {theme}.
Return the hex codes and suggest a use case (e.g., "primary/secondary/accent").
Laravel Blade Directives: Create a custom Blade directive to embed color data in views:
// app/Providers/BladeServiceProvider.php
Blade::directive('color', function ($hex) {
return "<?php echo app(\\Labrodev\\Espectro\\Color::fromHex('{$hex}')->toHtml(); ?>";
});
Usage:
<div style="background: {{ $color->hex }}">{{ $color->name }}</div>
Rate Limiting:
Tool Name Sensitivity:
search-colors vs. searchColor) break requests..mcp.json schema.AI Client Quirks:
.mcp.json changes.Hex Case Inconsistency:
#4a90e2), others uppercase.$hex = strtoupper($color['hex']);
Validate .mcp.json:
Ensure the file contains:
{
"mcp": {
"servers": {
"espectro": {
"url": "https://espectro.dev/mcp/espectro",
"transport": "http"
}
}
}
}
Use php artisan espectro:install --force to regenerate.
Test Tools Manually:
Use curl to verify endpoints:
curl -X POST https://espectro.dev/mcp/espectro \
-H "Content-Type: application/json" \
-d '{"tool":"search-colors","query":"blue"}'
Custom Tools:
Extend the package by adding a tools/ directory in your project root. Example:
// .mcp.json
{
"mcp": {
"tools": {
"my-custom-tool": {
"description": "Fetches color accessibility metrics",
"parameters": {
"hex": "string"
}
}
}
}
}
Register the tool in AppServiceProvider:
MCP::extend('my-custom-tool', function ($hex) {
return Http::post('https://espectro.dev/mcp/espectro', [
'tool' => 'my-custom-tool',
'hex' => $hex,
])->json();
});
Local Overrides:
Override the default MCP endpoint in .env:
ESPECTRO_MCP_URL=https://your-proxy.espectro.dev/mcp/espectro
Then publish the config:
php artisan vendor:publish --provider="Labrodev\Espectro\EspectroServiceProvider"
Webhook Integration:
Use Laravel’s HandleIncomingWebhook to process Espectro responses as webhooks:
// routes/web.php
Route::post('/espectro-webhook', [EspectroWebhookHandler::class, 'handle']);
Example handler:
class EspectroWebhookHandler {
public function handle(Request $request) {
$data = $request->json();
if ($data['tool'] === 'search-colors') {
Cache::put('latest-colors', $data['result'], now()->addMinutes(5));
}
}
}
How can I help you explore Laravel packages today?