15 unstable releases (3 breaking)
Uses new Rust 2024
| 0.10.9 | Jan 2, 2026 |
|---|---|
| 0.10.8 | Dec 26, 2025 |
| 0.8.0 | Dec 6, 2025 |
| 0.5.0 |
|
#2667 in Development tools
Used in 3 crates
4MB
1.5K
SLoC
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
git clone https://github.com/cyrup-ai/kodegen-tools-prompt.git
cd kodegen-tools-prompt
cargo build --release
The binary will be available at target/release/kodegen-prompt.
Usage
Running the Server
cargo run --bin kodegen-prompt
The server typically runs on port 30438 when managed by kodegend.
MCP Tools
The server provides four MCP tools:
1. prompt_add - Create New Prompt
{
"name": "my_workflow",
"content": "---\ntitle: \"My Workflow\"\ndescription: \"Custom workflow\"\ncategories: [\"custom\"]\nauthor: \"your-name\"\nparameters:\n - name: \"project_path\"\n description: \"Project directory\"\n required: false\n default: \".\"\n---\n\n# My Workflow\n\nProject: {{ project_path }}\nUser: {{ env.USER }}"
}
2. prompt_get - Retrieve and Render Prompts
List all categories:
{
"action": "list_categories"
}
List prompts by category:
{
"action": "list_prompts",
"category": "onboarding"
}
Get prompt metadata and content:
{
"action": "get",
"name": "getting_started"
}
Render prompt with parameters:
{
"action": "render",
"name": "analyze_project",
"parameters": {
"project_path": "/path/to/project"
}
}
3. prompt_edit - Update Existing Prompt
{
"name": "my_workflow",
"content": "---\ntitle: \"Updated Workflow\"\n..."
}
4. prompt_delete - Remove Prompt
{
"name": "my_workflow"
}
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:
- name: "param_name"
description: "Parameter description"
param_type: "string" # string | number | boolean | array
required: false
default: "default_value"
---
# Template Content
Use {{ param_name }} for parameters.
Access environment variables: {{ env.USER }}, {{ env.HOME }}
## Jinja2 Syntax Support
{% if condition %}
Conditional content
{% endif %}
{% for item in items %}
- {{ item }}
{% endfor %}
Apply filters: {{ value | upper }}
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
cargo build
# Run tests
cargo test
# Run with logging
RUST_LOG=info cargo run --bin kodegen-prompt
# Format code
cargo fmt
# Lint
cargo clippy -- -D warnings
Run Examples
The repository includes integration test examples:
# Run the prompt demo (tests all CRUD operations)
cargo run --example prompt_demo
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
Dependencies
~56–97MB
~1.5M SLoC