Docs MCP Server

MCP Server Setup

Connect Plexor Labs to Claude Desktop and other MCP-compatible applications using the Model Context Protocol. Get intelligent LLM routing and prompt optimization directly in your AI assistant.

What is MCP?

The Model Context Protocol (MCP) is an open standard developed by Anthropic for connecting AI assistants with external tools and services. It provides a standardized way for AI applications like Claude Desktop, Cursor, and other MCP-compatible clients to communicate with external servers that provide additional capabilities.

With MCP, you can extend Claude's capabilities by connecting it to databases, APIs, file systems, and specialized tools. The Plexor Labs MCP server exposes prompt optimization and multi-provider routing tools that help you save tokens and reduce costs while maintaining response quality.

Why Use Plexor Labs via MCP?
Using Plexor Labs as an MCP server gives you access to prompt optimization and intelligent routing directly within Claude Desktop. Optimize prompts before sending them, analyze optimization potential, and route requests to the most cost-effective provider.

How Plexor Labs MCP Server Works

The Plexor Labs MCP server runs as a subprocess spawned by Claude Desktop. It communicates via JSON-RPC over stdin/stdout, following the MCP specification. When you invoke a Plexor Labs tool in Claude Desktop, the request is sent to the local MCP server which processes it and returns the result.

The server provides five primary tools:

  • Prompt Optimization - Compress prompts for reduced token usage while preserving meaning
  • Prompt Analysis - Analyze prompts to understand optimization potential
  • Statistics Tracking - Monitor your token savings across sessions
  • Provider Routing - Route prompts to optimal CLI providers (Claude Code, Codex)
  • Provider Listing - View available providers and their health metrics

Prerequisites

Before setting up the Plexor Labs MCP server, ensure you have:

  • Python 3.11+ installed on your system
  • uv package manager (recommended) or pip
  • Claude Desktop application installed
  • A Plexor Labs API key from your API Keys page

Installing uv (Recommended)

We recommend using uv for faster package installation. Install it with:

macOS / Linux
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows (PowerShell)
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Installation

Install the Plexor Labs package which includes the MCP server:

Using uv (Recommended)
uv pip install plexor
Using pip
pip install plexor

After installation, verify the MCP server is available:

Terminal
which plexor-mcp  # Should output the path to plexor-mcp

Claude Desktop Configuration

To connect Plexor Labs to Claude Desktop, you need to add it to your MCP server configuration file.

Locate Your Configuration File

The Claude Desktop configuration file is located at:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Linux: ~/.config/claude-desktop/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Add the Plexor Labs MCP Server

Open the configuration file and add the Plexor Labs server to the mcpServers section:

Restart Claude Desktop

Completely quit and restart Claude Desktop for the new configuration to take effect. The Plexor Labs tools will now be available in your conversations.

Configuration Using uv (Recommended)

Using uv ensures the correct Python environment is used:

claude_desktop_config.json
{
  "mcpServers": {
    "plexor": {
      "command": "uv",
      "args": [
        "run",
        "--with",
        "plexor",
        "plexor-mcp"
      ],
      "env": {
        "PLEXOR_API_KEY": "YOUR_API_KEY",
        "PLEXOR_BASE_URL": "https://api.plexor.dev"
      }
    }
  }
}

Configuration Using Direct Path

Alternatively, use the direct path to the plexor-mcp executable:

claude_desktop_config.json
{
  "mcpServers": {
    "plexor": {
      "command": "/path/to/plexor-mcp",
      "args": [],
      "env": {
        "PLEXOR_API_KEY": "YOUR_API_KEY",
        "PLEXOR_BASE_URL": "https://api.plexor.dev"
      }
    }
  }
}
Important: Replace YOUR_API_KEY
Replace YOUR_API_KEY with your actual Plexor Labs API key from the API Keys page. Never commit API keys to version control.

Environment Variables

The Plexor Labs MCP server supports the following environment variables for configuration:

Variable Required Default Description
PLEXOR_API_KEY Required - Your Plexor Labs API key for authentication
PLEXOR_BASE_URL Optional https://api.plexor.dev Base URL for the Plexor Labs API. Change for self-hosted deployments.
PLEXOR_MODE Optional balanced Default routing mode: eco, balanced, quality, passthrough
PLEXOR_PROVIDER Optional auto Force specific provider: auto, anthropic, openai, deepseek
PLEXOR_LOG_LEVEL Optional INFO Logging level: DEBUG, INFO, WARNING, ERROR

Available MCP Tools

Once configured, the Plexor Labs MCP server exposes five tools to Claude Desktop:

optimize_prompt
Optimize a prompt for reduced token usage while preserving semantic meaning. Automatically detects task type and applies appropriate optimization strategies.
Parameters:
prompt (string) required - The prompt text to optimize
task_type (string) - Task type: auto, code_generation, code_review, analysis, general
preserve_code_blocks (boolean) - Whether to preserve code blocks unchanged (default: true)
aggressiveness (string) - Optimization level: conservative, moderate, aggressive
analyze_prompt
Analyze a prompt for optimization potential without modifying it. Returns detailed breakdown of compression opportunities and recommendations.
Parameters:
prompt (string) required - The prompt text to analyze
get_optimization_stats
Get aggregated statistics for prompt optimizations performed in the current session. Shows total prompts, tokens saved, and average reduction percentage.
Parameters:
scope (string) - Statistics scope: session or all_time (default: session)
route_prompt
Route a prompt to the optimal CLI provider (Claude Code or Codex) based on task type, quality scores, and provider health. Can optionally optimize the prompt first and/or execute with the selected provider.
Parameters:
prompt (string) required - The prompt to route
task_type (string) - Task type for routing: auto, code_generation, code_review, analysis, research, summarization, email_draft, general
provider_preference (string) - Preferred provider: none, claude-code, codex
optimize_first (boolean) - Optimize prompt before routing (default: true)
execute (boolean) - Execute the prompt with selected provider (default: false)
list_providers
List all available CLI providers with their status, health metrics, and quality scores. Shows which providers are installed and currently available.
Parameters:
include_health (boolean) - Include health metrics for each provider (default: true)
refresh_availability (boolean) - Re-check CLI availability before listing (default: false)

Verification

After configuration, verify that the Plexor Labs MCP server is working correctly:

Check Claude Desktop Logs

Open Claude Desktop's developer console or check the logs for MCP server initialization messages. Look for: plexor_mcp_starting and stdio_streams_connected

Verify Tool Availability

In Claude Desktop, ask: "What MCP tools do you have available from Plexor Labs?" Claude should list the five Plexor Labs tools: optimize_prompt, analyze_prompt, get_optimization_stats, route_prompt, and list_providers.

Test Tool Execution

Ask Claude to analyze a sample prompt using the Plexor Labs tools: "Use the Plexor Labs analyze_prompt tool to check this prompt: 'Please help me write a function'"

Example Usage in Claude Desktop

Example Conversation
# You can ask Claude to use Plexor Labs tools:

User: Use the Plexor Labs optimize_prompt tool to optimize this prompt:
      "I would really appreciate it if you could please help me to write
       a Python function that calculates the factorial of a number"

Claude: I'll optimize that prompt using Plexor Labs.
        [Calls optimize_prompt tool]

        The optimized prompt is:
        "Write Python factorial function"

        Results:
        - Original tokens: 32
        - Optimized tokens: 5
        - Reduction: 84.4%
        - Tokens saved: 27

Troubleshooting

MCP Server Not Starting

Error: Command not found
If Claude Desktop reports the command is not found, verify the path to plexor-mcp is correct. Run which plexor-mcp in your terminal and use the full path in the config.

Authentication Errors

Error: Invalid API key
Verify your PLEXOR_API_KEY is correct. Check the API Keys page to confirm the key is active. Ensure there are no extra spaces or quotes around the key value.

Tools Not Appearing

Tools not visible in Claude Desktop
  1. Completely quit Claude Desktop (not just close the window)
  2. Verify JSON syntax in claude_desktop_config.json is valid
  3. Check that the file is saved in the correct location
  4. Restart Claude Desktop and check the developer console for errors

Common Fixes

  • JSON Syntax Errors: Use a JSON validator to check your config file
  • Path Issues on Windows: Use forward slashes or escaped backslashes in paths
  • Python Version: Ensure Python 3.11+ is installed and in PATH
  • Package Not Installed: Run pip install --upgrade plexor

Debug Logging

Enable debug logging by setting the environment variable in your config:

claude_desktop_config.json (with debug logging)
{
  "mcpServers": {
    "plexor": {
      "command": "uv",
      "args": ["run", "--with", "plexor", "plexor-mcp"],
      "env": {
        "PLEXOR_API_KEY": "YOUR_API_KEY",
        "PLEXOR_LOG_LEVEL": "DEBUG"
      }
    }
  }
}

Advanced Configuration

Multiple MCP Servers

You can configure multiple MCP servers alongside Plexor Labs:

claude_desktop_config.json (multiple servers)
{
  "mcpServers": {
    "plexor": {
      "command": "uv",
      "args": ["run", "--with", "plexor", "plexor-mcp"],
      "env": {
        "PLEXOR_API_KEY": "YOUR_API_KEY"
      }
    },
    "filesystem": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/files"]
    },
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"],
      "env": {
        "GITHUB_PERSONAL_ACCESS_TOKEN": "ghp_..."
      }
    }
  }
}

Self-Hosted Plexor Labs

If you're running a self-hosted Plexor Labs instance, update the base URL:

Self-hosted configuration
{
  "mcpServers": {
    "plexor": {
      "command": "plexor-mcp",
      "args": [],
      "env": {
        "PLEXOR_API_KEY": "YOUR_API_KEY",
        "PLEXOR_BASE_URL": "https://plexor.your-company.com"
      }
    }
  }
}

Default Routing Mode

Set the default routing mode for all optimization and routing operations:

Mode Description Best For
eco Maximum cost savings, aggressive optimization Simple queries, drafts, brainstorming
balanced Balance between cost and quality (default) General use, most applications
quality Prioritize response quality, minimal optimization Complex reasoning, production code
passthrough No optimization, direct pass-through Testing, benchmarks, comparison

Alternative: HTTP API Integration

If MCP doesn't fit your use case, you can integrate Plexor Labs directly via the HTTP API. This is useful for:

  • Server-side applications
  • Custom integrations not using Claude Desktop
  • Direct API access without MCP overhead

See the HTTP API documentation for complete details.