Skip to content

MechCrate MCP Server Usage

A Model Context Protocol (MCP) server that enables LLMs to interact with MechCrate projects, providing full operational capabilities for project management, service orchestration, infrastructure configuration, and intelligent documentation retrieval.

Features

  • Full MX Command Access: Create projects, add services, manage router, configure infrastructure
  • Project Makefile Operations: dev, up, down, logs, shell, restart, build, and more
  • Project Analysis: Detect projects, list services, inspect configuration
  • Techniques Corpus: Hybrid semantic + lexical search over development techniques, backed by Postgres + pgvector
  • Comprehensive Tool Descriptions: Detailed documentation for LLM understanding
  • Resilient Corpus Access: Neon primary with a local Postgres fallback; RAG tools degrade to an offline message instead of crashing the server

Quick Start

1. Build the Server

Terminal window
# From mech-crate root:
mx mcp build
# Or manually:
cd mcp-server && cargo build --release

2. Ingest the Techniques Corpus

The corpus lives in Postgres + pgvector. Point it at a database via ~/.mech-crate/config/rag.toml (Neon primary, local Postgres fallback), or spin up a local instance:

Terminal window
docker run -d --name mx-rag -p 5432:5432 \
-e POSTGRES_DB=mx_rag -e POSTGRES_HOST_AUTH_METHOD=trust pgvector/pgvector:pg17

Then ingest docs/development (embeddings use OPENAI_API_KEY):

Terminal window
mx rag ingest # scan, chunk, embed, upsert (idempotent)
mx rag status # backend, doc/chunk counts, embedding model

3. Get Client Configuration

Terminal window
mx mcp config

This outputs the MCP client configuration for the server.

4. Configure MCP Client

The mx mcp config command outputs the configuration. Example for Claude Desktop (~/.claude/claude_desktop_config.json):

{
"mcpServers": {
"mechcrate": {
"command": "/Users/you/.mech-crate/mcp/mx-mcp-wrapper.sh",
"env": {
"MECH_CRATE_ROOT": "/path/to/mech-crate"
}
}
}
}

Alternative: Direct Binary

Point the client straight at the built binary. The server connects to the corpus lazily on the first RAG call and never blocks startup on it:

{
"mcpServers": {
"mechcrate": {
"command": "/path/to/mech-crate/target/release/mx-mcp",
"env": {
"MECH_CRATE_ROOT": "/path/to/mech-crate"
}
}
}
}

Pass --no-rag to disable the corpus entirely (RAG tools then report offline).

Available Tools (47 total)

Global MX Commands

ToolDescription
mx_newCreate a new MechCrate project
mx_recipes_listList available recipes
mx_recipe_infoGet details about a specific recipe
mx_router_installInstall the global Traefik router
mx_router_upStart the global router
mx_router_downStop the global router
mx_router_statusShow router container status
mx_router_inspectShow router details and connected services
mx_infra_setupConfigure infrastructure provider credentials
mx_infra_listList configured providers
mx_infra_linkLink project to global credentials
mx_doctorCheck system health
mx_helpShow mx command help

Project Commands

ToolDescription
mx_add_serviceAdd a service to a project (with optional recipe)
mx_upgradeUpdate project with latest scaffolding
mx_buildBuild Docker image for a service

Make Commands (Project Operations)

ToolDescription
make_devStart services in development mode
make_upStart services in production mode
make_downStop services
make_logsView service logs
make_restartRestart a service
make_shellGet shell access information
make_psList running services
make_helpShow available make targets
make_keyGenerate cryptographic keys

Project Analysis

ToolDescription
project_analyzeAnalyze project structure and services
project_listFind all MechCrate projects in a directory
project_detectDetect if a path is within a project
service_infoGet details about a specific service

Techniques Corpus / RAG (8 tools)

ToolDescription
rag_contextPrimary entry point. Describe what you’re working_on (+ optional language/category) and get relevant techniques grouped by source doc
rag_searchHybrid semantic + lexical search across the techniques corpus
rag_search_categorySearch within a specific category (theory, patterns, concurrency, database, etc.)
rag_find_implementationFind implementations for a concept, filtered by language
rag_get_guidanceGet architecture/design guidance with optional constraints
rag_compare_approachesCompare two approaches side by side with relevant chunks
rag_find_relatedDiscover related techniques from other docs
rag_healthReport the active backend (neon/local/offline), doc/chunk counts, and embedding model

RAG search is hybrid (vector + trigram) only when the server can embed the query. The embedding key resolves at server startup, precedence high→low:

  1. MX_RAG_EMBEDDING_API_KEY env, then OPENAI_API_KEY env
  2. embedding_api_key in ~/.mech-crate/config/rag.toml

MCP launch configs (e.g. a checked-in .mcp.json) usually pass no env, so rag.toml is the reliable source for MCP servers — never put the key in a tracked file. Without a working key (missing, or the provider rejects it — e.g. exhausted OpenAI credits return 429 insufficient_quota), every search silently degrades to trigram-only and results carry a lexical-only note. Diagnose with mx rag status (shows Embedding key: configured / MISSING). Config changes need an MCP server restart; embedding_base_url in the same file can point at any OpenAI-compatible provider (Ollama, LM Studio) — switching models requires mx rag ingest --reembed.

Architecture

┌─────────────────────────────────────────────────────────────────┐
│ MCP Client (LLM) │
└─────────────────────────────┬───────────────────────────────────┘
│ JSON-RPC over stdio
┌─────────────────────────────▼───────────────────────────────────┐
│ mx-mcp Server │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────────────────┐ │
│ │ MX Executor │ │ Make Exec. │ │ Project Detector │ │
│ │ (bin/mx) │ │ (make) │ │ (analyze, discover) │ │
│ └─────────────┘ └─────────────┘ └─────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────────────┐│
│ │ Tool Registry (47 tools) ││
│ │ Comprehensive LLM descriptions for intelligent tool use ││
│ └─────────────────────────────────────────────────────────────┘│
│ ┌─────────────────────────────────────────────────────────────┐│
│ │ CorpusStore (8 rag_* tools, hybrid search) ││
│ └─────────────────────────────────────────────────────────────┘│
└─────────────────────────────┬───────────────────────────────────┘
│ SQL (Neon primary → local fallback)
┌─────────────────────────────▼───────────────────────────────────┐
│ Postgres + pgvector │
│ ┌─────────────────┐ ┌─────────────────────────────────────┐ │
│ │ technique_docs │ │ technique_chunks │ │
│ │ technique_chunks│ │ HNSW cosine + pg_trgm (0.85/0.15) │ │
│ └─────────────────┘ └─────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
Embeddings come from an OpenAI-compatible `/embeddings` endpoint
(`text-embedding-3-small`, 1536 dims) via the `EmbeddingProvider` trait.

Example LLM Interactions

Create a New Project

User: Create a new project called "myapp" with Cloudflare infrastructure
LLM uses: mx_new(name="myapp", with_infra=["cloudflare"], working_directory="/Users/me/projects")

Add a Laravel API Service

User: Add a Laravel API service to the myapp project
LLM uses: mx_add_service(name="api", recipe="laravel", project_path="/Users/me/projects/myapp")

Start Development

User: Start the API service in development mode
LLM uses:
1. mx_router_up() # Ensure router is running
2. make_dev(service="api", project_path="/Users/me/projects/myapp")

Query Documentation

User: How do I configure Traefik routing for my services?
LLM uses: rag_search(query="configure Traefik routing labels for services", limit=5)

Find Code Examples

User: Show me how to write a multi-stage Dockerfile
LLM uses: rag_find_implementation(pattern="multi-stage Dockerfile", language="dockerfile")

Get Architecture Guidance

User: I need to choose between Laravel and Nuxt for my project. It needs SSR and good SEO.
LLM uses:
1. rag_compare_approaches(approaches=["laravel", "nuxt"], criteria=["SSR", "SEO"])
2. rag_get_guidance(problem="choosing between Laravel and Nuxt for SSR with SEO", constraints=["needs SSR", "SEO important"])

Analyze Project Structure

User: What services does this project have?
LLM uses: project_analyze(project_path="/Users/me/projects/myapp")

Development

Running Tests

Terminal window
cargo test

Building Debug Version

Terminal window
cargo build

Logging

Set RUST_LOG for debug output:

Terminal window
RUST_LOG=debug ./target/release/mx-mcp

MX MCP Commands

Terminal window
mx mcp build # Build the MCP server binary
mx mcp status # Show corpus backend + doc/chunk counts
mx mcp config # Show MCP client configuration
mx mcp run # Run MCP server interactively
mx mcp test # Test MCP server response
mx mcp info # Show MCP server information
mx mcp help # Show help

Corpus ingestion lives under mx rag:

Terminal window
mx rag ingest # Ingest docs/development into the pgvector corpus
mx rag ingest --clear # Clear and re-ingest
mx rag ingest --dry-run # Parse/chunk only (no DB or embeddings)
mx rag status # Backend, doc/chunk counts, embedding model

Environment Variables

VariableDescriptionDefault
MECH_CRATE_ROOTMechCrate installation directoryAuto-detected
MX_RAG_DATABASE_URLNeon (primary) corpus URLFrom rag.toml, else local fallback
MX_RAG_FALLBACK_DATABASE_URLLocal Postgres fallback URLpostgres://postgres@localhost:5432/mx_rag
OPENAI_API_KEYEmbedding API key (or MX_RAG_EMBEDDING_API_KEY)—
MX_RAG_EMBEDDING_MODELEmbedding modeltext-embedding-3-small
RUST_LOGLog levelinfo

Corpus config is read from ~/.mech-crate/config/rag.toml; the env vars above override it.

Troubleshooting

Corpus Offline

Terminal window
# Show the active backend (neon / local / offline) and counts
mx rag status
# Start a local pgvector instance if neither Neon nor local is reachable
docker run -d --name mx-rag -p 5432:5432 \
-e POSTGRES_DB=mx_rag -e POSTGRES_HOST_AUTH_METHOD=trust pgvector/pgvector:pg17
# Or set the primary URL
export MX_RAG_DATABASE_URL=postgres://...neon.tech/mx_rag

The MCP server never crashes when the corpus is unreachable — the rag_* tools return an actionable offline message instead.

MechCrate Root Not Found

Set explicitly:

Terminal window
./mx-mcp --mech-crate-root /path/to/mech-crate

Or via environment:

Terminal window
export MECH_CRATE_ROOT=/path/to/mech-crate

RAG Search Returns No Results

Confirm the corpus is populated, then re-ingest if needed:

Terminal window
mx rag status
mx rag ingest --clear

If rag_health reports search running in trigram-only mode, no embedding API key is configured — set OPENAI_API_KEY and run mx rag ingest --reembed.

License

MIT


🦝 Built with MechCrate