Code Generator MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Code Generator MCP Server Generate a Python function to calculate factorial"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Code Generator MCP Template Server
An MCP (Model Context Protocol) server built using Python's FastMCP framework. It exposes 4 precise, structured code-generation tools backed by prompt templates to generate production-grade, parsed code using local or cloud-based OpenAI-compatible APIs (such as llama-server, qwen-coder, coder-expert, or OpenAI's API).
π Features
Exposes 4 key MCP tools that use structured templates to instruct the model to think step-by-step and produce clean, executable code:
generate_standard_function(Template 1): Generates a standalone function based on constraints, edge cases, test cases, and external integration notes.generate_codebase_context(Template 2): Generates a function that respects and integrates with existing codebase structures and dependencies.generate_bugfix_refactor(Template 3): Focuses on refactoring or repairing current buggy implementations based on problem descriptions and test expectations.generate_multi_function_module(Template 4): Generates a multi-function module, validating that there are no circular dependencies or undefined functions.
βοΈ Parser & Guardrails
Markdown Stripper: Automatic code parsing (
extract_code_from_response) strips any markdown code blocks (```python) generated by instruct models, guaranteeing only raw executable code is returned.Reasoning Fallback: Correctly handles DeepSeek-style reasoning models or
llama-serverconfigurations where all output is redirected into thereasoning_contentfield instead ofcontent.Max Tokens Guardrail: Enforces a
2048token limit per request to prevent local model reasoning loops and timeouts.
Related MCP server: opencode-mcp-bridge
π οΈ Configuration
Configure the server using command-line arguments or environment variables:
Setting | CLI Argument | Environment Variable | Default Value | Description |
API URL |
|
|
| OpenAI-compatible endpoint |
Model |
|
|
| The model name to target |
API Key |
|
| (Empty) | API token (optional for local endpoints) |
For security reasons, do not pass--api-key via command-line arguments as it will be visible in plain text in the host process table. Use the environment variables instead.
π¦ Installation & Setup
You can install and configure the server either automatically using the installation script or manually via Python.
Option 1: Quick Installation Script (Recommended)
The project includes an install.sh script that automatically builds a standalone executable using PyInstaller, installs it to ~/.local/bin/code-generator-mcp, and configures your target AI coding agent.
Run the script and specify your target agent:
chmod +x install.sh ./install.sh <agent_type>Supported
<agent_type>values:claude-desktop(Claude Desktop global configuration)claude-code(Claude CLI global configuration at~/.claude.json)cursor(Cursor editor global config at~/.cursor/mcp.json)codex(Codex agent global config at~/.codex/config.toml)github-copilot(VS Code workspace-specific config at.vscode/mcp.json)windsurf(Windsurf IDE configuration at~/.codeium/windsurf/mcp_config.json)zed(Zed editor config at~/.config/zed/settings.json)agy(Antigravity settings config at~/.gemini/settings.json)
(Optional) Customize the endpoint and model in the agent's configuration file or environment variables after installation.
Option 2: Manual Setup via Python
Prerequisites
Python 3.10+
Dependencies installed in virtual environment:
python -m venv .venv source .venv/bin/activate pip install -r requirements.txt
Running Locally
To run the MCP server directly over standard input/output (stdio):
python src/code_generator_mcp/server.py --api-url http://localhost:8008/v1 --model coder-expertTesting during development
You can use mcp dev (from MCP CLI) to test the server interactively in a development UI:
mcp dev src/code_generator_mcp/server.py -- --api-url http://localhost:8008/v1 --model coder-expertπ Integration Setup
To manually use this server with your favorite MCP client (like Claude Desktop or Cursor):
Claude Desktop Configuration
Open your Claude Desktop config file (usually located at ~/.config/Claude/claude_desktop_config.json on Linux/macOS or %APPDATA%\Claude\claude_desktop_config.json on Windows) and add the following entry:
{
"mcpServers": {
"code-generator-mcp": {
"command": "/path/to/project/.venv/bin/python",
"args": [
"/path/to/project/src/code_generator_mcp/server.py"
],
"env": {
"CODE_GEN_API_URL": "http://localhost:8008/v1",
"CODE_GEN_MODEL": "coder-expert"
}
}
}
}π§ͺ Testing
The codebase includes a fully-featured unit and integration test suite using pytest. Run tests with:
.venv/bin/pytestAvailable Tools
5 toolsgenerate_bugfix_refactorC
Generate fixed or refactored code (Template 3) using coder expert model.
If generate_test_file is True, it will co-generate a matching unit test suite.
IMPORTANT: All parameters (such as 'task', 'problem', 'expected_behavior', 'constraints', etc.) MUST be provided in English. If the user's prompt or request is in Vietnamese or another language, the calling agent must automatically translate the text of these parameter values into English before invoking this tool.
Inputs: problem (required), language (required), test_cases (required), current_code (required), +4 more. Returns: result
generate_codebase_contextC
Generate code for a function with codebase context (Template 2) using coder expert model.
If generate_test_file is True, it will co-generate a matching unit test suite.
IMPORTANT: All parameters (such as 'task', 'description', 'constraints', etc.) MUST be provided in English. If the user's prompt or request is in Vietnamese or another language, the calling agent must automatically translate the text of these parameter values into English before invoking this tool.
Inputs: task (required), language (required), signature (required), test_cases (required), +5 more. Returns: result
generate_multi_function_moduleB
Generate code for a multi-function module (Template 4) using coder expert model.
If generate_test_file is True, it will co-generate a matching unit test suite.
IMPORTANT: All parameters (such as 'task', 'module_purpose', 'context', 'functions' list with its descriptions/constraints, etc.) MUST be provided in English. If the user's prompt or request is in Vietnamese or another language, the calling agent must automatically translate the text of these parameter values into English before invoking this tool.
Inputs: task (required), language (required), functions (required), test_cases (required), +6 more. Returns: result
generate_standard_functionC
Generate code for a standard function spec (Template 1) using coder expert model.
If generate_test_file is True, it will co-generate a matching unit test suite.
IMPORTANT: All parameters (such as 'task', 'description', 'constraints', 'edge_cases', etc.) MUST be provided in English. If the user's prompt or request is in Vietnamese or another language, the calling agent must automatically translate the text of these parameter values into English before invoking this tool.
Inputs: task (required), language (required), signature (required), test_cases (required), +7 more. Returns: result
run_project_testsA
Automatically detects and runs the project's test suite, returning the command's stdout and stderr. Can be used by the AI to verify correct behavior of generated code.
If 'custom_command' is provided, it runs that command line instead of auto-detecting.
Inputs: custom_command. Returns: result
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogβ¦
TDQS
Scored across 5 tools
The four generate_* tools map to distinct templates/scenarios (standard function, codebase-aware function, bugfix/refactor, multi-function module), so an agent can usually pick correctly. However, generate_standard_function and generate_codebase_context both produce a single function and differ only by whether codebase context is used, which could cause occasional misselection.
All names use snake_case with a consistent verb_noun pattern (generate_* plus run_project_tests). The generate_* family is predictable and self-describing.
Five tools is well-scoped for a code-generation server: four generation templates plus a test runner, each earning its place. No redundant or filler tools.
The surface covers code generation across common scenarios and test execution/verification, with test suites co-generated. Minor gaps exist around applying/writing generated code back to disk or editing existing files, but core workflows are covered.
Maintenance
Related MCP Connectors
MCP server for your apps' tools and custom tools, plus hosted AI agents and approval-gated workflows
Use AI models for chat, image, and video generation from Claude Code and other MCP hosts.
Shared memory MCP server for Claude Code, Codex, Gemini CLI and Cursor. Cited, editable.
The OpenRouter for tools. One MCP connection gives any AI agent 254 hosted tools, pay per call.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceExposes a set of CLI tools (test generation, documentation generation, linting, test running, code search) to AI assistants via MCP, allowing them to perform these tasks through natural language.3-
- AlicenseNot gradedqualityBmaintenanceExposes opencode's coding agent and shell as MCP tools, enabling MCP-only AI clients to execute shell commands, manage files, and run agent sessions with async job handling.23 npmMIT
- AlicenseNot gradedqualityBmaintenanceEnables automatically generating standalone MCP servers from any Python library, exposing its functions as deterministic callable tools.MIT
- AlicenseNot gradedqualityAmaintenanceEnables AI clients such as Claude, Cursor, VS Code, and Windsurf to read and manage workspaces, projects, tasks, and AI agents, and to build automations through natural language. It also includes an OpenAPI codegen that turns any OpenAPI spec into MCP tools.2,105 npmMIT