code2prompt

code2prompt

4.5

code2prompt is hosted online, so all tools can be tested directly either in theInspector tabor in theOnline Client.

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

Code2Prompt is a tool that converts your codebase into a single LLM prompt, facilitating code analysis and generation.

Code2Prompt is a versatile tool designed to transform entire codebases into structured prompts for large language models (LLMs). It automates the process of code ingestion, making it easier to generate prompts for code analysis, generation, and other tasks. The tool traverses directories, builds a tree structure, and gathers information about each file, which can then be used to create customized prompts using Handlebars templates. Code2Prompt is available as a command line interface (CLI), a software development kit (SDK) with Python bindings, and as a Model Context Protocol (MCP) server, allowing it to be integrated into various applications and workflows. It supports smart filtering, token tracking, and Git integration, making it a powerful tool for developers looking to leverage AI models for code-related tasks.

Features

  • Automatic Code Processing: Convert codebases of any size into readable, formatted prompts.
  • Smart Filtering: Include/exclude files using glob patterns and respect .gitignore rules.
  • Flexible Templating: Customize prompts with Handlebars templates for different use cases.
  • Token Tracking: Track token usage to stay within LLM context limits.
  • Git Integration: Include diffs, logs, and branch comparisons in your prompts.

Tools

  1. get_context

    Retrieve context from a codebase using code2prompt with the specified parameters.

    Args: path: Path to the codebase include_patterns: List of glob patterns for files to include exclude_patterns: List of glob patterns for files to exclude include_priority: Give priority to include patterns line_numbers: Add line numbers to code absolute_paths: Use absolute paths instead of relative paths full_directory_tree: List the full directory tree code_blocks: Wrap code in markdown code blocks follow_symlinks: Follow symbolic links include_hidden: Include hidden directories and files template: Custom Handlebars template encoding: Token encoding (cl100k, gpt2, p50k_base)

    Returns: Dictionary with the prompt and metadata