kodegen-tools-prompt
Memory-efficient, blazing-fast MCP tools for prompt template management in code generation agents.
Overview
kodegen-tools-prompt is a Rust-based Model Context Protocol (MCP) server that provides AI agents with powerful prompt template management capabilities. It enables creating, editing, retrieving, and rendering Jinja2-templated prompts with YAML frontmatter metadata.
Part of the KODEGEN.ai ecosystem, this server runs as an HTTP service managed by the kodegend daemon.
Features
- 🚀 Fast: Blazing-fast template operations with async I/O
- 🔒 Secure: Built-in validation, size limits, and path traversal prevention
- 📝 Jinja2 Templates: Full Jinja2 syntax support with parameters and environment variables
- 🏷️ Rich Metadata: YAML frontmatter with categories, descriptions, and parameter definitions
- 🔄 CRUD Operations: Complete create, read, update, delete workflow
- 🎯 MCP Native: First-class MCP protocol support via HTTP/SSE transport
- 📦 Default Prompts: Ships with curated templates for common workflows
Installation
Prerequisites
- Rust nightly toolchain (automatically installed via rust-toolchain.toml)
- Cargo
Build from Source
The binary will be available at target/release/kodegen-prompt.
Usage
Running the Server
The server typically runs on port 30438 when managed by kodegend.
MCP Tools
The server provides four MCP tools:
1. add_prompt - Create New Prompt
2. get_prompt - Retrieve and Render Prompts
List all categories:
List prompts by category:
Get prompt metadata and content:
Render prompt with parameters:
3. edit_prompt - Update Existing Prompt
4. delete_prompt - Remove Prompt
Prompt Template Format
Prompts are stored as .j2.md files with YAML frontmatter:
title: "Prompt Title"
description: "What this prompt does"
categories: ["category1", "category2"]
author: "your-name"
verified: true
parameters:
-
Use {{ param_name }} for parameters.
Access environment variables: {{ env.USER }}, {{ env.HOME }}
{% if condition %}
Conditional content
{% endif %}
{% for item in items %}
-
Template Features
- Variables:
{{ variable_name }} - Conditionals:
{% if condition %}...{% endif %} - Loops:
{% for item in items %}...{% endfor %} - Filters:
{{ value | filter_name }} - Environment Variables:
{{ env.USER }},{{ env.HOME }},{{ env.SHELL }}, etc.
Storage Location
Prompts are stored in: ~/.kodegen/prompts/
Development
Build and Test
# Build the project
# Run tests
# Run with logging
RUST_LOG=info
# Format code
# Lint
Run Examples
The repository includes integration test examples:
# Run the prompt demo (tests all CRUD operations)
This example:
- Connects to the local HTTP server
- Creates a test prompt
- Retrieves the prompt
- Edits the prompt
- Deletes the prompt
Project Structure
src/
├── lib.rs # Public API exports
├── main.rs # HTTP server binary
├── manager.rs # PromptManager core logic
├── template.rs # Jinja2 parsing/rendering
├── metadata.rs # Data structures
├── validation.rs # Security validation
├── add_prompt.rs # AddPromptTool
├── edit_prompt.rs # EditPromptTool
├── delete_prompt.rs # DeletePromptTool
├── get_prompt.rs # GetPromptTool
└── defaults.rs # Embedded default prompts
data/default_prompts/ # Default templates
examples/ # Integration examples
Architecture
Core Components
- PromptManager: Orchestrates all prompt operations with async file I/O
- Template Engine: Parses YAML frontmatter and renders Jinja2 templates
- MCP Tools: Four tools implementing the MCP Tool trait
- Validation System: Security-focused validation with size limits and forbidden directives
- Default Prompts: Compile-time embedded templates for common workflows
Security Features
- Template Size Limit: Maximum 1MB per template
- Forbidden Directives: Blocks
{% include %},{% extends %},{% import %} - Path Traversal Prevention: Name validation prevents directory traversal
- Environment Variable Whitelist: Only safe variables exposed (USER, HOME, SHELL, PWD, EDITOR, TERM)
- Recursion Limits: MiniJinja built-in protection (~500 levels)
- Timeout Enforcement: 5-second rendering timeout
See CLAUDE.md for detailed architecture documentation.
Dependencies
Core Dependencies
- rmcp (0.8) - MCP SDK for server/client/transport
- minijinja (2) - Jinja2 template engine
- gray_matter (0.3) - YAML frontmatter parsing
- tokio (1) - Async runtime
- serde / serde_json (1) - Serialization
- anyhow (1) - Error handling
- dirs (6) - Cross-platform paths
KODEGEN Dependencies
- kodegen_mcp_tool (0.1) - Tool trait definitions
- kodegen_mcp_schema (0.1) - Args schema definitions
- kodegen_server_http (0.1) - HTTP server framework
Default Prompts
The server ships with curated default prompts:
- getting_started - Introduction to Kodegen MCP basics
- code_generation - Code generation workflow examples
- env_demo - Environment variable usage demonstration
- refactor_example - Refactoring workflow template
Default prompts are automatically installed on first run if the prompts directory is empty.
Contributing
Contributions are welcome! Please ensure:
- Code is formatted with
cargo fmt - All tests pass with
cargo test - Clippy produces no warnings:
cargo clippy -- -D warnings - New features include appropriate tests
- Security considerations are documented
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT License (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Related Projects
- KODEGEN.ai - Main project website
- MCP Protocol - Model Context Protocol specification
- MiniJinja - Jinja2 template engine for Rust
Built with ❤️ by the KODEGEN.ai team