kodegen_tools_prompt

Crates.iokodegen_tools_prompt
lib.rskodegen_tools_prompt
version0.10.9
created_at2025-10-29 03:25:40.147272+00
updated_at2026-01-02 15:04:46.261219+00
descriptionKODEGEN.ᴀɪ: Memory-efficient, Blazing-Fast, MCP tools for code generation agents.
homepagehttps://kodegen.ai
repositoryhttps://github.com/cyrup-ai/kodegen-tools-prompt
max_upload_size
id1906011
size4,119,019
David Maple (kloudsamurai)

documentation

README

Kodegen AI Banner

kodegen-tools-prompt

License Rust

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:

  1. Connects to the local HTTP server
  2. Creates a test prompt
  3. Retrieves the prompt
  4. Edits the prompt
  5. 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

  1. Template Size Limit: Maximum 1MB per template
  2. Forbidden Directives: Blocks {% include %}, {% extends %}, {% import %}
  3. Path Traversal Prevention: Name validation prevents directory traversal
  4. Environment Variable Whitelist: Only safe variables exposed (USER, HOME, SHELL, PWD, EDITOR, TERM)
  5. Recursion Limits: MiniJinja built-in protection (~500 levels)
  6. 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:

  1. Code is formatted with cargo fmt
  2. All tests pass with cargo test
  3. Clippy produces no warnings: cargo clippy -- -D warnings
  4. New features include appropriate tests
  5. Security considerations are documented

License

Licensed under either of:

at your option.

Related Projects


Built with ❤️ by the KODEGEN.ai team

Commit count: 0

cargo fmt