haiku-code-server

dimav78/haiku-code-server

3.2

If you are the rightful owner of haiku-code-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

The Haiku Code Server is a Model Context Protocol (MCP) server designed to efficiently handle simple, repetitive code generation tasks by leveraging Claude Haiku 4.5.

Tools
5
Resources
0
Prompts
0

Haiku Code Server

A Model Context Protocol (MCP) server that delegates simple, repetitive code generation tasks to Claude Haiku 4.5 for cost-efficient execution. Designed to be called by smarter orchestrator models (like Claude Sonnet/Opus) for optimal cost and performance.

Overview

This MCP server provides specialized tools for generating:

  • Boilerplate code (CRUD, APIs, models, services)
  • Configuration files (Docker, K8s, CI/CD)
  • Test suites (unit, integration, edge cases)
  • Component scaffolding (React, Vue, classes, schemas)
  • Documentation (API docs, READs, docstrings)

Why Use This?

  • 90% Cost Reduction: Haiku costs ~$0.80/MTok input vs Sonnet's ~$3/MTok
  • Faster Responses: Simple tasks complete in 2-5 seconds
  • Better Resource Allocation: Save expensive model context for complex reasoning
  • Production Quality: Generates well-structured, typed, documented code

Architecture

┌─────────────────────────────────────────┐
│   Smart Model (Sonnet/Opus)            │
│   - Planning & Orchestration            │
│   - Complex Business Logic              │
│   - Architecture Decisions              │
└─────────────┬───────────────────────────┘
              │ Delegates simple tasks
              │ via MCP
              ▼
┌─────────────────────────────────────────┐
│   Haiku Code Server (this)             │
│   - Receives structured specs           │
│   - Validates inputs                    │
│   - Delegates to Haiku 4.5              │
└─────────────┬───────────────────────────┘
              │
              ▼
┌─────────────────────────────────────────┐
│   Claude Haiku 4.5                     │
│   - Fast, cost-efficient execution      │
│   - Boilerplate generation              │
│   - Template-based code                 │
└─────────────────────────────────────────┘

Installation

Prerequisites

  • Python 3.10 or higher
  • Anthropic API key
  • Claude Desktop (or any MCP-compatible client)

Step 1: Clone or Download

cd haiku_code_server

Step 2: Install Dependencies

pip install -r requirements.txt

Or using the package:

pip install -e .

Step 3: Set Up Environment Variables

Copy the example environment file:

cp .env.example .env

Edit .env and add your Anthropic API key:

ANTHROPIC_API_KEY=your_api_key_here

Optional environment variables:

# Use a specific Haiku model version
HAIKU_MODEL=claude-haiku-4.5-20250929

# Enable/disable features
ENABLE_COST_TRACKING=true
ENABLE_CACHING=true

# Logging
LOG_LEVEL=INFO

Step 4: Configure Claude Desktop

Add the server to your Claude Desktop configuration file:

Windows: %APPDATA%\Claude\claude_desktop_config.json

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

Linux: ~/.config/Claude/claude_desktop_config.json

Add this configuration:

{
  "mcpServers": {
    "haiku-code-server": {
      "command": "python",
      "args": [
        "-m",
        "haiku_code_server.src.server"
      ],
      "cwd": "D:\\Haiku MCP\\haiku_code_server",
      "env": {
        "ANTHROPIC_API_KEY": "your_api_key_here"
      }
    }
  }
}

Important:

  • Adjust the cwd path to your actual installation directory
  • Use double backslashes (\\) on Windows or forward slashes (/) on Unix
  • Replace your_api_key_here with your actual API key

Step 5: Restart Claude Desktop

Restart Claude Desktop to load the MCP server.

Step 6: Verify Installation

In Claude Desktop, type:

Can you list your available tools?

You should see the 5 Haiku Code Server tools listed:

  • generate_boilerplate_code
  • create_config_file
  • generate_test_suite
  • scaffold_component
  • generate_documentation

Usage

For Smart Models (Orchestrators)

If you're Claude Sonnet/Opus or another orchestrator model, see for detailed usage instructions.

For End Users

Simply ask Claude to generate boilerplate code, configs, tests, etc. Claude will automatically use the Haiku Code Server when appropriate.

Example Requests

Generate a REST API:

Create a REST API for managing products with FastAPI. Include CRUD operations,
pagination, filtering, and JWT authentication.

Generate Configuration:

Create a docker-compose.yml for a web app with PostgreSQL and Redis.

Generate Tests:

Write comprehensive pytest tests for this function:
[paste your function]

Scaffold a Component:

Create a React component for a user profile card with edit and delete functionality.

Generate Documentation:

Generate API reference documentation for this code:
[paste your code]

Available Tools

1. generate_boilerplate_code

Generates common code patterns and boilerplate.

Use for:

  • REST API CRUD operations
  • Database models (ORM)
  • Service classes
  • Middleware, validators, serializers
  • Design patterns (Repository, Factory, etc.)

Example:

{
  "code_type": "rest_api_crud",
  "entity_name": "User",
  "framework": "fastapi",
  "language": "python",
  "fields": {
    "id": "UUID",
    "email": "EmailStr",
    "full_name": "str",
    "is_active": "bool"
  },
  "features": ["pagination", "filtering", "jwt_auth"],
  "conventions": {
    "style": "google",
    "max_line_length": 88,
    "use_async": true
  }
}

2. create_config_file

Generates configuration files.

Use for:

  • Docker/docker-compose
  • Kubernetes manifests
  • CI/CD configs (GitHub Actions, GitLab CI)
  • Web server configs (nginx, apache)
  • Package configs (package.json, pyproject.toml)

Example:

{
  "config_type": "docker_compose",
  "version": "3.8",
  "environment": "production",
  "settings": {
    "services": {
      "web": {
        "build": ".",
        "ports": ["8000:8000"]
      }
    }
  }
}

3. generate_test_suite

Generates comprehensive test suites.

Use for:

  • Unit tests
  • Integration tests
  • Edge case testing
  • Error handling tests

Example:

{
  "code_to_test": "def add(a: int, b: int) -> int:\n    return a + b",
  "test_framework": "pytest",
  "language": "python",
  "test_types": ["unit", "edge_cases"],
  "coverage_target": 90
}

4. scaffold_component

Scaffolds standard components.

Use for:

  • React/Vue/Angular components
  • Python/Java/Go classes
  • Database schemas
  • API routers

Example:

{
  "component_type": "react_component",
  "component_name": "UserCard",
  "language": "typescript",
  "props": {
    "user": "User",
    "onEdit": "(userId: string) => void"
  },
  "features": ["state_management", "error_handling"]
}

5. generate_documentation

Generates documentation.

Use for:

  • API reference docs
  • README files
  • Inline comments/docstrings
  • User guides
  • OpenAPI specs

Example:

{
  "doc_type": "api_reference",
  "language": "python",
  "code": "[your code here]",
  "style": "google",
  "include_examples": true
}

Features

Cost Tracking

The server tracks token usage and costs for each request and maintains session totals:

## Session Usage
- Total Tokens: 1,234
- Total Cost: $0.001234

Caching

Identical requests are cached for 15 minutes, reducing costs for repeated operations.

To disable caching:

ENABLE_CACHING=false

Quality Assurance

Every response includes:

  • Generated code with syntax highlighting
  • Generation metadata (time, tokens, cost)
  • Suggestions for improvements
  • Warnings when applicable

Error Handling

Comprehensive error handling with:

  • Input validation using Pydantic
  • Graceful failure messages
  • Actionable suggestions for fixing issues

Performance

Typical performance metrics:

MetricValue
Generation Time2-5 seconds
Cost per Request$0.001 - $0.005
Code QualityProduction-ready
Cache Hit Rate~30-40% (typical)

Development

Project Structure

haiku_code_server/
├── src/
│   ├── server.py              # Main MCP server
│   ├── tools/                 # Tool implementations
│   │   ├── boilerplate.py
│   │   ├── config.py
│   │   ├── tests.py
│   │   ├── scaffold.py
│   │   └── docs.py
│   ├── models/
│   │   └── schemas.py         # Pydantic models
│   ├── prompts/
│   │   └── templates.py       # Haiku prompt templates
│   └── utils/
│       └── haiku_client.py    # Anthropic client wrapper
├── SMART_MODEL_GUIDE.md       # Guide for orchestrator models
├── README.md                  # This file
├── requirements.txt
├── pyproject.toml
└── .env.example

Running Tests

pytest

Linting

black src/
ruff check src/

Troubleshooting

Server Not Appearing in Claude Desktop

  1. Check that the path in claude_desktop_config.json is correct
  2. Ensure Python is in your PATH
  3. Restart Claude Desktop
  4. Check Claude Desktop logs for errors

API Key Issues

Error: ANTHROPIC_API_KEY must be set

Solution: Ensure your API key is set in either:

  • .env file in the project directory
  • Environment variable in claude_desktop_config.json
  • System environment variable ANTHROPIC_API_KEY

Generation Failures

If code generation fails:

  1. Check that all required fields are provided
  2. Ensure specifications are detailed enough
  3. Review error messages for specific issues
  4. Check your API key has sufficient credits

Cache Issues

To clear the cache:

rm -rf .cache/

Or disable caching in .env:

ENABLE_CACHING=false

Cost Optimization Tips

  1. Be Specific: Detailed specifications reduce regeneration needs
  2. Use Caching: Leverage the 15-minute cache for similar requests
  3. Batch Operations: Group similar generation tasks
  4. Monitor Usage: Check session stats to track costs
  5. Right-Size Temperature: Lower temperature (0.2-0.3) for deterministic code

Limitations

What This Server Does NOT Do:

  • Complex business logic
  • Architecture decisions
  • Novel algorithms
  • Deep contextual understanding
  • Security audits
  • Performance optimization analysis

For these tasks, the orchestrator model (Sonnet/Opus) should handle them directly.

Contributing

Contributions are welcome! Areas for improvement:

  • Additional code templates
  • More configuration file types
  • Better error messages
  • Performance optimizations
  • Test coverage

License

MIT License - see LICENSE file for details

Support

For issues, questions, or suggestions:

  • Open an issue on GitHub
  • Check the for usage guidance
  • Review example usage in examples/usage_examples.md

Changelog

v0.1.0 (Initial Release)

  • 5 core tools for code generation
  • Cost tracking and caching
  • Comprehensive input validation
  • Smart model integration guide
  • Production-ready code generation

Acknowledgments

Built with:


Happy Coding! 🚀