Skip to main content
Glama

codeigniter-mcp

πŸ’Ό Enterprise Modernization & Custom AI Tooling: Migrating monolithic CodeIgniter 3 systems to CI4? Need custom MCP servers, architecture audits, or dedicated team support? Message Cristofher on Agensi →

Model Context Protocol (MCP) server built for high-velocity AI development on CodeIgniter 4 and modern PHP architectures (MVC + Services/Repository layer).

Eliminates LLM hallucinations, scaffolds complete production-ready modules in <15 milliseconds, and unlocks real-time live database and route introspection directly inside your AI IDE (Claude Code, Cursor, Windsurf, Trae, OpenAI Codex, and Google Project Astra).


Architecture: The "Top 1%" Dual-Engine Design

Most MCP servers are either purely external (blind to running application state) or heavy PHP extensions. codeigniter-mcp uses a Dual-Engine Architecture bridging the best of both worlds:

flowchart TB
    subgraph AI["AI Coding Assistant"]
        Client["Claude Code / Cursor / Windsurf / Trae / Codex / Astra"]
    end

    subgraph Outer["Engine 1: Outer Server (Node/TypeScript)"]
        MCPNode["codeigniter-mcp (stdio / HTTP)"]
        Scaffold["Lightning Scaffolding (<15 ms)\nCRUD, Controllers, Services, Entities"]
        Linter["AST Linter & Conventions\nStrict types, PascalCase, Zero-SQL Controllers"]
        RouteVal["Route Collision Analyzer\nCI4 placeholders, (:segment), $routes->resource()"]
        Migrator["Safe Migration Runner\nExplicit confirmation, interpreted PHP errors"]
    end

    subgraph Inner["Engine 2: Inner In-App Server (PHP Spark Command)"]
        SparkCmd["php spark mcp:serve\n(Generated via scaffold_ci4_mcp_server)"]
        LiveDB["Live DB Introspection\nReal tables, columns, nullability, keys"]
        SafeQuery["Safe SELECT Query Engine\nCapped row limit, mutation blocking"]
        ActiveRoutes["Live Route Reflector\nReads compiled Services::routes()"]
        MigStatus["Migration Version Status\nReads active batch history"]
    end

    Client -->|Local stdio or Streamable HTTP| MCPNode
    MCPNode --> Scaffold
    MCPNode --> Linter
    MCPNode --> RouteVal
    MCPNode --> Migrator
    MCPNode -.->|Generates app/Commands/McpServer.php| SparkCmd
    Client -.->|Direct live introspection| SparkCmd
    SparkCmd --> LiveDB
    SparkCmd --> SafeQuery
    SparkCmd --> ActiveRoutes
    SparkCmd --> MigStatus
  1. Outer Engine (codeigniter-mcp): Runs in Node/TypeScript over stdio or http. Handles sub-millisecond code scaffolding, static syntax validation, and route collision checks without touching PHP runtime dependencies.

  2. Inner Engine (php spark mcp:serve): Scaffolds a zero-dependency, native CodeIgniter 4 Spark command (app/Commands/McpServer.php) that runs a pure JSON-RPC 2.0 MCP server over stdio for real-time live schema reflection, safe read-only SQL queries, and compiled route inspection.


Related MCP server: MySQL MCP Server

Highlights

  • 8 Production Tools: Complete CRUD scaffolding, modular controllers, services, repositories, route validation, migration runner, AST convention linter, and native CI4 MCP server generator.

  • Vibecoding Ready (Zero Hallucinations): The AI assistant never confuses CI3, Laravel, and CI4 syntax. Generates clean BaseController, dependency-injected Services, Query Builder Models, and CSRF-protected forms.

  • Enterprise-Grade Security:

    • Symlink Traversal Mitigation: Canonical realpathSync resolution prevents reading or writing outside APP_ROOT.

    • DNS Rebinding Protection: Enforces strict Host header matching (returns 403 Forbidden).

    • HTTP API Key Authentication: Supports Authorization: Bearer <key> or X-API-Key headers.

    • Safe PDO Mutations: Prevents false 404s on unchanged MySQL row updates (rowCount() > 0 || $this->findById($id)).

    • Destructive Operations Guarded: Requires explicit confirm: true or overwrite: true.

  • 4 Convention Resources + 3 Token-Saving Prompts: Compact prompt templates save token context and speed up LLM responses.


AI Agent Skill (Agensi.io Marketplace)

Prefer installing as a ready-to-use AI Agent Skill?
Get the CodeIgniter 4 Master skill directly from Agensi.io:

  • Plug-and-play workflow instructions (SKILL.md) for Claude Code, Cursor, Trae, Copilot, and Windsurf.

  • Architectural Guardrails: Guarantees zero SQL in controllers, CSRF-protected forms, and type safety.

  • Automated MCP Triggers: Configures your agent to automatically invoke codeigniter-mcp tools when creating modules or inspecting databases.


Quickstart

Run with npx (No installation needed)

npx -y codeigniter-mcp

Install globally

npm install -g codeigniter-mcp

From source (Contributors)

git clone https://github.com/X-Gunner/codeigniter-mcp.git
cd codeigniter-mcp
npm install
npm run build
npm test
npm run verify

IDE & AI Agent Configuration

1. Claude Code / Claude Desktop

Add to claude_desktop_config.json or run claude mcp add codeigniter-mcp:

{
  "mcpServers": {
    "codeigniter-mcp": {
      "command": "npx",
      "args": ["-y", "codeigniter-mcp"],
      "env": {
        "APP_ROOT": "/absolute/path/to/your/codeigniter4_project",
        "RATE_LIMIT_PER_MINUTE": "30"
      }
    }
  }
}

2. Cursor / Windsurf / Trae

In your project root or global settings (.cursor/mcp.json or settings UI):

{
  "mcpServers": {
    "codeigniter-mcp": {
      "command": "npx",
      "args": ["-y", "codeigniter-mcp"],
      "env": {
        "APP_ROOT": "/absolute/path/to/your/codeigniter4_project"
      }
    }
  }
}

3. Remote Agents / OpenAI Codex / Google Project Astra (Streamable HTTP)

For cloud agents that connect over HTTP instead of spawning local sub-processes:

# Start server in HTTP mode
MCP_TRANSPORT=http MCP_PORT=3000 MCP_BIND_HOST=127.0.0.1 MCP_API_KEY=secret_token APP_ROOT=/path/to/project npx codeigniter-mcp

Configure your remote AI agent:

{
  "mcpServers": {
    "codeigniter-mcp": {
      "url": "http://127.0.0.1:3000/mcp",
      "headers": {
        "Authorization": "Bearer secret_token"
      }
    }
  }
}

Available Tools (8 Tools)

Tool

Purpose

Key Parameters

scaffold_full_resource

Generates full CRUD in ~15 ms: Controller + Service + Model/Repository + Migration + View + Tests (8 files).

resourceName, fields[], withTests, withRepository, overwrite

scaffold_controller

Generates standalone Controller with strict validation; enforces zero SQL in controllers.

resourceName, methods[], fields[], overwrite

scaffold_service

Generates business logic Service with contract-first DI (injects Model in CI4).

resourceName, fields[], withRepository, overwrite

scaffold_repository

Generates Repository interface + PDO implementation (no-op in CI4, data lives in Models).

resourceName, overwrite

validate_route

Analyzes app/Config/Routes.php to detect route collisions, CI4 placeholders ((:num), (:segment)), and $routes->resource().

method, path

run_migration

Executes native migrations (spark migrate or bin/migrate). Interprets PHP errors into actionable messages; requires explicit confirmation.

direction (up|down), confirm (bool)

lint_against_framework_rules

Lints PHP source code against framework conventions and AST security rules.

filePath

scaffold_ci4_mcp_server

Scaffolds native CI4 in-app MCP command (app/Commands/McpServer.php) for live runtime introspection via php spark mcp:serve.

commandName, className, readOnly, overwrite


In-App Live Introspection (php spark mcp:serve)

Once you run scaffold_ci4_mcp_server, your CodeIgniter 4 application gains its own native MCP server:

php spark mcp:serve

This exposes live runtime tools to your AI assistant:

  • ci4_db_tables: Reflects active database schema, columns, data types, and primary keys.

  • ci4_db_query: Runs safe, read-only SELECT queries (capped at 50 rows, destructive keywords blocked).

  • ci4_routes_list: Reads dynamically compiled routes directly from Services::routes().

  • ci4_migration_status: Queries Services::migrations() for active and pending migration batches.


Token-Saving Prompts (3 Prompts)

Compact input templates that minimize token consumption:

Prompt

Description

create_full_resource

Converts compact definitions (e.g. Patient fullName:string:true, age:int:false) into exact tool parameters.

run_migration

Prepares migration direction while enforcing safety confirmation.

lint_file

Directs the model to inspect and repair a specific file against framework standards.


Convention Resources (4 Resources)

Read-only context injected into the LLM context window:

  • convention://naming: Rules for PascalCase, camelCase, kebab-case, and mandatory suffixes.

  • convention://architecture: Explains MVC + Service + Repository separation.

  • convention://folder-structure: CodeIgniter 4 directory tree mapping.

  • convention://security-rules: Guidelines for CSRF tokens, PDO parameterized statements, and strict typing.


Configuration Variables

Variable

Default

Description

APP_ROOT

β€”

Required. Absolute path to the PHP application root directory.

RATE_LIMIT_PER_MINUTE

20

Maximum write/scaffold operations permitted per minute per session.

MCP_TRANSPORT

stdio

Communication protocol (stdio or http).

MCP_PORT

3000

Port for Streamable HTTP transport mode.

MCP_BIND_HOST

127.0.0.1

Local IP binding to guard against DNS rebinding attacks.

MCP_API_KEY

β€”

Optional Bearer token or X-API-Key required for HTTP transport.

PHP_BINARY

php

Path or name of the PHP CLI binary to execute.


Testing & Quality Assurance

# Run complete test suite (165 tests across 17 files)
npm test

# Typecheck with zero warnings
npm run typecheck

# Acceptance checklist against real stdio MCP transport
npm run verify
codeigniter-mcp β€” acceptance checklist

  βœ…  Handshake: serverInfo.name = codeigniter-mcp
  βœ…  Exposes 8 tools (found 8)
  βœ…  Exposes 4 convention resources (found 4)
  βœ…  Exposes 3 token-saving prompts (found 3)
  βœ…  scaffold_full_resource creates 8 files on disk (7 ms)
  βœ…  php -l passes on all generated files (8 files OK)
  βœ…  lint_against_framework_rules β†’ compliant
  βœ…  validate_route POST /orders β†’ valid
  βœ…  run_migration without confirm β†’ blocked (zero executions)
  βœ…  run_migration with confirm=true executes via bin/migrate
  βœ…  scaffold again β†’ no overwrite, 8 files skipped
  βœ…  Path traversal outside APP_ROOT β†’ ValidationError
  βœ…  Runner failure β†’ actionable MigrationFailedError

Result: 13 passed Β· 0 failed Β· 0 skipped

Documentation

  • docs/tools.md β€” Comprehensive parameter references for all 8 tools.

  • docs/profiles.md β€” Profiles, auto-detection (ci4 vs spec), and configuration.

  • docs/security.md β€” Deep dive into the security architecture and guardrails.

  • docs/testing.md β€” Testing strategy, E2E fixtures, and CI automation.


πŸ’Ό Enterprise Support, Migration & Consulting Services

Need dedicated support, custom tool development, or legacy modernization for your engineering team?

We offer professional architecture and migration services tailored for enterprise CodeIgniter ecosystems:

  • Legacy Migration (CI3 β†’ CI4): Safe, phased migration of legacy monolithic CodeIgniter 3 systems to modern CodeIgniter 4 + PHP 8.2+ with clean MVC, Service layer, and typed entities.

  • Custom MCP & AI Tooling: Custom-tailored Model Context Protocol servers and specialized IDE prompts tailored to your proprietary schema, internal libraries, and coding standards.

  • Architecture & Security Audits: Comprehensive review of existing repositories to eliminate controller SQL leakage, harden PDO parameters, implement CSRF/Auth safeguards, and modernize routing.

  • Monthly Retainer / Dedicated Support: Direct SLA-backed architecture advisory, prompt engineering support, and framework maintenance for engineering teams.

πŸ‘‰ Inquire or Request a Consultation:


Contributing

Contributions are welcome! Please read CONTRIBUTING.md before submitting pull requests.

License

Distributed under the MIT License. Copyright (c) 2026 Cristofher Robles. See LICENSE for more information.

Available Tools

7 tools
lint_against_framework_rulesLint against the framework conventionsA

Validates a PHP file of the project against the framework conventions: strict_types, naming, no queries in controllers, input validation and repositories behind an interface. Returns structured violations; compliant=false when there is any error.

Inputs: filePath (required).

run_migrationRun migrations (DESTRUCTIVE)A

Runs framework migrations (up/down) through the project's native migration runner (spec: php bin/migrate; ci4: php spark migrate). DESTRUCTIVE OPERATION: requires an explicit confirm: true. Without that flag nothing is executed.

Inputs: confirm (required), direction (required), migrationName.

scaffold_controllerGenerate PHP ControllerA

Generates a PHP Controller for a resource (presentation layer only). The controller only calls the corresponding Service: zero queries and zero inline validation. Does not overwrite existing files unless overwrite=true.

Inputs: resourceName (required), methods, overwrite.

scaffold_full_resourceGenerate a complete CRUD resourceA

Generates the full CRUD of a PHP resource: Controller, Service, Repository (interface + implementation), Entity, Migration and tests (unit & integration). Requires overwrite=true to overwrite existing files.

Inputs: fields (required), resourceName (required), overwrite, withTests, +1 more.

scaffold_repositoryGenerate PHP Repository (interface + implementation)A

Generates the Repository of a resource: ALWAYS the interface (contract) and the implementation (PDO adapter with prepared statements) together. Does not overwrite existing files unless overwrite=true.

Inputs: fields (required), resourceName (required), overwrite.

scaffold_serviceGenerate PHP ServiceA

Generates a PHP Service for a resource (business logic + input validation). Receives the Repository through dependency injection via interface (contract first). Does not overwrite existing files unless overwrite=true.

Inputs: resourceName (required), overwrite, withRepository.

validate_routeValidate a route against Routes.phpA

Verifies (read-only) that a route does not collide with the routes registered in app/Config/Routes.php and follows the framework's kebab-case {param} syntax. Never modifies files.

Inputs: path (required), method (required).

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.2/5.0

    Scored across 7 tools

    Disambiguation5/5

    Each tool targets a clearly distinct action: layer-specific scaffolds, full resource scaffolding, route validation, migration execution, and linting. The full resource tool is explicitly named and described as a superset, so there is little risk of misselection.

    Naming Consistency5/5

    All tools follow a consistent verb-first snake_case pattern: scaffold_*, validate_route, run_migration, lint_against_framework_rules. The naming conventions are uniform and predictable.

    Tool Count5/5

    Seven tools is well-scoped for a CodeIgniter scaffolding and validation server. Each tool earns its place and the set is neither bloated nor thin.

    Completeness4/5

    The server covers the main resource scaffolding workflow, routing validation, migrations, and framework linting. Minor gaps exist such as no standalone entity/migration/test generator outside the full resource scaffold, but common workflows can be completed without dead ends.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      D
      maintenance
      A comprehensive Model Context Protocol server that provides advanced Node.js development tooling for automating project creation, component generation, package management, and documentation with AI-powered assistance.
      7
      9
      MIT
    • A
      license
      B
      quality
      B
      maintenance
      Comprehensive Model Context Protocol server for MySQL databases featuring 191 specialized tools for CRUD operations, JSON functions, spatial/GIS, schema management, performance monitoring, and advanced features like OAuth 2.1 authentication and connection pooling.
      43
      135 npm
      11
      MIT
    • A
      license
      A
      quality
      D
      maintenance
      A production-ready Model Context Protocol (MCP) server that bridges your Symfony/PHP project with LLMs such as Claude. It exposes tools that let the AI read your project's routes, services, Twig templates, and PHP source code.
      8
      MIT
    • F
      license
      Not graded
      quality
      D
      maintenance
      A Model Context Protocol server integrating developer tools including Git control, document conversion, remote SSH execution, database operations, and utilities for automation and development productivity.
      1
      -