Context Generator MCP server

PHP-based tool for generating structured documentation from files, repositories, diffs, and URLs through a modular architecture with powerful configuration options for AI-assisted development workflows
Back to servers
Setup instructions
Provider
Pavel Buchnev
Release date
Apr 12, 2025
Language
PHP
Stats
139 stars

Context Generator (CTX) is a powerful tool that bridges the gap between your codebase and Language Learning Models (LLMs) like ChatGPT or Claude. It automatically builds organized context files from various sources including code files, repositories, web pages, and plain text, allowing AI tools to understand your project better without manually copying code snippets.

Installation

Installing CTX is quick and straightforward:

curl -sSL https://raw.githubusercontent.com/context-hub/generator/main/download-latest.sh | sh

This installs the ctx command to your system, typically in /usr/local/bin.

Basic Usage

Initialize Configuration

Start by creating a configuration file in your project directory:

ctx init

This generates a context.yaml file with a basic structure to help you get started.

Configure Your Context

Edit the generated context.yaml file to specify what code or content you want to include. Here's an example configuration:

$schema: 'https://raw.githubusercontent.com/context-hub/generator/refs/heads/main/json-schema.json'

documents:
  - description: "User Authentication System"
    outputPath: "auth-context.md"
    sources:
      - type: file
        description: "Authentication Controllers"
        sourcePaths:
          - src/Auth
        filePattern: "*.php"

      - type: file
        description: "Authentication Models"
        sourcePaths:
          - src/Models
        filePattern: "*User*.php"

This configuration will collect all PHP files from the src/Auth directory and any PHP files containing "User" in their name from the src/Models directory.

Build the Context

Generate your context file by running:

ctx

CTX will process your configuration and create the specified output file (auth-context.md in our example).

Using the Generated Context

Upload or paste the generated context file to your preferred LLM (like ChatGPT or Claude). Now you can ask specific questions about your codebase, and the LLM will have the necessary context to provide accurate assistance.

Example prompt:

I've shared my authentication system code with you. Can you help me identify potential security vulnerabilities in the user registration process?

Using the MCP Server

CTX includes a built-in MCP (Model Context Protocol) server that allows Claude AI to directly access your codebase information.

Setting Up the MCP Server

To use the built-in MCP server, configure your MCP client (like Claude) to point to the Context Generator server:

{
  "mcpServers": {
    "ctx": {
      "command": "ctx server -c /path/to/your/project"
    }
  }
}

With this setup, you can ask Claude questions about your codebase without manually uploading context files.

Running the Server

Start the MCP server directly with:

ctx server -c /path/to/your/project

Advanced Configuration

Source Types

CTX supports various source types:

  • File sources: Include specific files or directories
  • GitHub/GitLab repositories: Pull code from remote repositories
  • Git commits and diffs: Include changes between commits
  • Web pages: Extract content from websites using CSS selectors
  • Plain text: Include arbitrary text content

Using Modifiers

You can apply modifiers to transform your content, such as extracting PHP signatures without implementation details:

sources:
  - type: file
    sourcePaths:
      - src/Controllers
    filePattern: "*.php"
    modifiers:
      - type: php-signatures

Logging

Configure logging for more detailed output:

ctx -v     # Verbose logging
ctx -vv    # More verbose
ctx -vvv   # Debug level logging

How to install this MCP server

For Claude Code

To add this MCP server to Claude Code, run this command in your terminal:

claude mcp add-json "ctx" '{"command":"ctx server -c /path/to/your/project"}'

See the official Claude Code MCP documentation for more details.

For Cursor

There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json file so that it is available in all of your projects.

If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json file.

Adding an MCP server to Cursor globally

To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".

When you click that button the ~/.cursor/mcp.json file will be opened and you can add your server like this:

{
    "mcpServers": {
        "ctx": {
            "command": "ctx server -c /path/to/your/project"
        }
    }
}

Adding an MCP server to a project

To add an MCP server to a project you can create a new .cursor/mcp.json file or add it to the existing one. This will look exactly the same as the global MCP server example above.

How to use the MCP server

Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.

The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.

You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.config/Claude/claude_desktop_config.json

2. Add this to your configuration file:

{
    "mcpServers": {
        "ctx": {
            "command": "ctx server -c /path/to/your/project"
        }
    }
}

3. Restart Claude Desktop for the changes to take effect

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later