# dedeveloper23/codebase-mcp architecture

> Architecture diagram of the GitHub repository dedeveloper23/codebase-mcp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dedeveloper23/codebase-mcp
- Repository: https://github.com/dedeveloper23/codebase-mcp

## Overview

1. **What this repository is**
   - This is a **TypeScript/Node.js MCP server package** named `codebase-mcp`.
   - Its purpose is to expose tools that let an AI agent **analyze an entire codebase** locally or from a remote GitHub repo, using **RepoMix** as the codebase-to-text processor.

2. **Top-level architecture**
   - The repo is split into four main areas:
     - `src/tools` for the actual codebase-processing tool logic
     - `src/server` for the MCP server runtime and auth
     - `src/client` for client-side helpers for talking to MCP servers
     - `src/shared` for protocol, transport, and utility types reused by both sides
   - This separation is important: shared protocol shapes are kept out of transport-specific or server-specific code.

3. **CLI and startup path**
   - `src/cli.ts` is the entrypoint for the package’s command-line interface.
   - From the README, the primary runtime command is `codebase-mcp start`, which launches the MCP server in **stdio mode** for MCP-compatible clients like Cursor.
   - The CLI is the boundary between the published package and the server implementation.

4. **Server core**
   - `src/server/index.ts` and `src/server/mcp.ts` look like the main server composition layer.
   - `src/server/completable.ts` suggests a small abstraction for request/response completion or deferred resolution.
   - `src/server/stdio.ts` and `src/server/sse.ts` are transport adapters for serving MCP over different channels.
   - The server side is responsible for wiring transport, protocol handling, and tool registration into a single runtime.

5. **Tooling layer: the actual product behavior**
   - `src/tools/codebase.ts` is the main functional payload of the repo.
   - Based on the README, this tool likely:
     - reads the current workspace or a remote repository
     - invokes RepoMix to convert the codebase into a large textual representation
     - optionally formats/saves the output
   - The tool layer is where repository-specific business logic lives; everything else is infrastructure around it.

6. **MCP protocol and shared abstractions**
   - `src/shared/protocol.ts`, `src/shared/transport.ts`, and `src/shared/stdio.ts` define reusable protocol and transport contracts.
   - `src/shared/auth.ts` and `src/shared/uriTemplate.ts` provide common auth and URI-template utilities.
   - These shared modules form the contract boundary between clients, transports, and server handlers, which keeps the implementation consistent across modes.

7. **Authentication subsystem**
   - `src/server/auth` is a complete auth stack for MCP-style access control.
   - It includes:
     - OAuth-like handlers: `authorize`, `register`, `token`, `revoke`, `metadata`
     - middleware: `allowedMethods`, `clientAuth`, `bearerAuth`
     - supporting types and error definitions
   - The presence of these handlers indicates the server can operate with a structured auth flow rather than only anonymous local stdio access.

8. **Auth routing and provider model**
   - `src/server/auth/router.ts` and `src/server/auth/provider.ts` suggest auth is assembled as a routed HTTP surface with a provider abstraction behind it.
   - `src/server/auth/clients.ts` likely manages client registration or client lookup state.
   - Architecture-wise, auth is a distinct subsystem that sits beside the MCP transport, not inside the tool logic.

9. **Client-side library**
   - `src/client/index.ts`, `auth.ts`, `stdio.ts`, `sse.ts`, and `websocket.ts` implement a client SDK for connecting to MCP servers.
   - This client layer mirrors server transport choices, which implies the repo is not only a server package but also includes reusable connection logic.
   - The client likely handles protocol setup, auth, and stream/session lifecycle for different transport types.

10. **In-memory and test harnesses**
    - `src/inMemory.ts` and the corresponding tests indicate an in-memory transport or server/client harness.
    - That lets the project test protocol behavior without launching real processes or network sockets.
    - `src/integration-tests/process-cleanup.test.ts` shows the repo also validates process lifecycle and cleanup, which matters for CLI/stdio server reliability.

11. **Data flow at runtime**
    - Typical flow:
      - a client launches or connects to `codebase-mcp`
      - MCP messages arrive over stdio or SSE
      - the server routes requests through its protocol layer
      - tool calls reach `src/tools/codebase.ts`
      - RepoMix produces the codebase representation
      - the result is returned to the client, or saved if requested
    - For remote repos, the flow includes a GitHub fetch step before processing.

12. **External dependencies and infrastructure**
    - The main external runtime dependency is **RepoMix**, which the README treats as required.
    - Remote repository support is centered on **GitHub repositories**.
    - Beyond that, the package is mostly self-contained Node.js infrastructure: no evidence of a database or long-lived backend service.

13. **Testing and quality boundaries**
    - Every major area has tests alongside it: server auth handlers, transports, protocol utilities, client helpers, and integration cleanup.
    - `jest.config.js`, `eslint.config.mjs`, and the TypeScript config files show a conventional TS library build/test pipeline.
    - The test layout reinforces the architectural boundaries: protocol, transport, auth, and tool logic are independently testable.

14. **How to draw the architecture**
    - A useful diagram would show:
      - **CLI** at the top
      - **Server runtime** in the middle
      - **Transport adapters** on the left/right for stdio/SSE
      - **Auth subsystem** adjacent to transport/server routing
      - **Tool layer** at the core
      - **Shared protocol/types** as a foundation underneath both client and server
      - **External services**: RepoMix and GitHub as the external data source/processor path

Main entry points: [`src/server/index.ts`](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/index.ts) (Server core), [`src/shared/transport.ts`](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/shared/transport.ts) (Transport types), [`src/client/index.ts`](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/client/index.ts) (Client core), [`src/server/mcp.ts`](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/mcp.ts) (MCP runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_group_cli["CLI"]
  node_cli["CLI<br/>entrypoint<br/>[cli.ts]"]
end

subgraph group_group_server["Server runtime"]
  node_server_index["Server core<br/>composition<br/>[index.ts]"]
  node_server_mcp["MCP runtime<br/>protocol runtime<br/>[mcp.ts]"]
  node_server_stdio["Server stdio<br/>transport adapter<br/>[stdio.ts]"]
  node_server_sse["Server SSE<br/>transport adapter<br/>[sse.ts]"]
  node_server_completable["Completable<br/>async helper<br/>[completable.ts]"]
  node_auth_router["Auth router<br/>http routing<br/>[router.ts]"]
  node_auth_provider["Auth provider<br/>auth backend<br/>[provider.ts]"]
  node_auth_handlers["Auth handlers<br/>oauth endpoints<br/>[authorize.ts]"]
  node_auth_middleware["Auth middleware<br/>request guards<br/>[allowedMethods.ts]"]
end

subgraph group_group_client["Client SDK"]
  node_client_index["Client core<br/>sdk composition<br/>[index.ts]"]
  node_client_auth["Client auth<br/>auth helper<br/>[auth.ts]"]
  node_client_stdio["Client stdio<br/>transport client<br/>[stdio.ts]"]
  node_client_sse["Client SSE<br/>transport client<br/>[sse.ts]"]
  node_client_ws["WebSocket client<br/>transport client<br/>[websocket.ts]"]
end

subgraph group_group_shared["Shared core"]
  node_shared_protocol["Protocol types<br/>contract<br/>[protocol.ts]"]
  node_shared_transport["Transport types<br/>contract<br/>[transport.ts]"]
  node_shared_stdio["Stdio shared<br/>shared transport<br/>[stdio.ts]"]
  node_shared_auth["Shared auth<br/>auth contract<br/>[auth.ts]"]
  node_shared_uri["URI templates<br/>[uriTemplate.ts]"]
end

subgraph group_group_tools["Tools"]
  node_codebase_tool["Codebase tool<br/>repo processor<br/>[codebase.ts]"]
end

node_external_repomix[("RepoMix<br/>external processor")]
node_external_github[("GitHub<br/>remote source")]

node_cli -->|"starts"| node_server_index
node_server_index -->|"composes"| node_server_mcp
node_server_index -->|"serves"| node_server_stdio
node_server_index -->|"serves"| node_server_sse
node_server_index -->|"mounts"| node_auth_router
node_server_mcp -->|"uses"| node_shared_protocol
node_server_mcp -->|"uses"| node_shared_transport
node_server_mcp -->|"invokes"| node_codebase_tool
node_server_stdio -->|"uses"| node_shared_stdio
node_server_sse -->|"uses"| node_shared_transport
node_auth_router -->|"delegates"| node_auth_provider
node_auth_router -->|"routes"| node_auth_handlers
node_auth_handlers -->|"guards"| node_auth_middleware
node_auth_provider -->|"uses"| node_shared_auth
node_client_index -->|"configures"| node_client_auth
node_client_index -->|"connects"| node_client_stdio
node_client_index -->|"connects"| node_client_sse
node_client_index -->|"connects"| node_client_ws
node_client_index -->|"uses"| node_shared_protocol
node_client_stdio -->|"uses"| node_shared_stdio
node_client_sse -->|"uses"| node_shared_transport
node_client_ws -->|"uses"| node_shared_transport
node_codebase_tool -->|"depends on"| node_external_repomix
node_codebase_tool -->|"fetches"| node_external_github
node_codebase_tool -->|"returns"| node_shared_protocol
node_shared_protocol -->|"aligns with"| node_shared_transport
node_shared_transport -->|"specializes"| node_shared_stdio
node_shared_auth -->|"uses"| node_shared_uri
node_server_index -->|"coordinates"| node_server_completable

click node_cli "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/cli.ts"
click node_server_index "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/index.ts"
click node_server_mcp "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/mcp.ts"
click node_server_stdio "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/stdio.ts"
click node_server_sse "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/sse.ts"
click node_server_completable "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/completable.ts"
click node_auth_router "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/auth/router.ts"
click node_auth_provider "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/auth/provider.ts"
click node_auth_handlers "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/auth/handlers/authorize.ts"
click node_auth_middleware "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/auth/middleware/allowedMethods.ts"
click node_codebase_tool "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/tools/codebase.ts"
click node_client_index "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/client/index.ts"
click node_client_auth "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/client/auth.ts"
click node_client_stdio "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/client/stdio.ts"
click node_client_sse "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/client/sse.ts"
click node_client_ws "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/client/websocket.ts"
click node_shared_protocol "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/shared/protocol.ts"
click node_shared_transport "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/shared/transport.ts"
click node_shared_stdio "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/shared/stdio.ts"
click node_shared_auth "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/shared/auth.ts"
click node_shared_uri "https://github.com/dedeveloper23/codebase-mcp/blob/main/src/shared/uriTemplate.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli toneBlue
class node_server_index,node_server_mcp,node_server_stdio,node_server_sse,node_server_completable,node_auth_router,node_auth_provider,node_auth_handlers,node_auth_middleware toneAmber
class node_client_index,node_client_auth,node_client_stdio,node_client_sse,node_client_ws toneMint
class node_shared_protocol,node_shared_transport,node_shared_stdio,node_shared_auth,node_shared_uri toneRose
class node_codebase_tool toneIndigo
class node_external_repomix,node_external_github toneNeutral
```

## Components

### CLI

Package entrypoint and startup commands

- [CLI](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/cli.ts): entrypoint · Command-line entrypoint for starting the package · `src/cli.ts`

### Server runtime

MCP server composition, transports, and auth

- [Server core](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/index.ts): composition · Top-level server wiring and runtime assembly · `src/server/index.ts`
- [MCP runtime](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/mcp.ts): protocol runtime · MCP session handling and tool registration · `src/server/mcp.ts`
- [Server stdio](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/stdio.ts): transport adapter · Server-side stdio transport implementation · `src/server/stdio.ts`
- [Server SSE](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/sse.ts): transport adapter · Server-side SSE transport implementation · `src/server/sse.ts`
- [Completable](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/completable.ts): async helper · Deferred completion abstraction used by server flows · `src/server/completable.ts`
- [Auth router](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/auth/router.ts): http routing · Routes auth endpoints into a structured HTTP surface · `src/server/auth/router.ts`
- [Auth provider](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/auth/provider.ts): auth backend · Provider abstraction behind auth operations · `src/server/auth/provider.ts`
- [Auth handlers](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/auth/handlers/authorize.ts): oauth endpoints · Authorize, register, token, revoke, and metadata handlers · `src/server/auth/handlers/authorize.ts`
- [Auth middleware](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/server/auth/middleware/allowedMethods.ts): request guards · Allowed-methods, client-auth, and bearer-auth checks · `src/server/auth/middleware/allowedMethods.ts`

### Client SDK

Reusable client-side MCP connection helpers

- [Client core](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/client/index.ts): sdk composition · Client-side entrypoint and connection orchestration · `src/client/index.ts`
- [Client auth](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/client/auth.ts): auth helper · Client-side auth setup and token/session handling · `src/client/auth.ts`
- [Client stdio](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/client/stdio.ts): transport client · Client transport for stdio-connected MCP servers · `src/client/stdio.ts`
- [Client SSE](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/client/sse.ts): transport client · Client transport for SSE-connected MCP servers · `src/client/sse.ts`
- [WebSocket client](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/client/websocket.ts): transport client · Client transport for websocket MCP connections · `src/client/websocket.ts`

### Shared core

Protocol, transport, and utility contracts used across the repo

- [Protocol types](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/shared/protocol.ts): contract · Shared MCP protocol shapes and message contracts · `src/shared/protocol.ts`
- [Transport types](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/shared/transport.ts): contract · Shared transport interfaces and wiring contracts · `src/shared/transport.ts`
- [Stdio shared](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/shared/stdio.ts): shared transport · Shared stdio helpers used by client and server · `src/shared/stdio.ts`
- [Shared auth](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/shared/auth.ts): auth contract · Common auth utilities and shared auth shapes · `src/shared/auth.ts`
- [URI templates](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/shared/uriTemplate.ts): utility · URI template helpers for resource addressing · `src/shared/uriTemplate.ts`

### Tools

Repository-processing business logic

- [Codebase tool](https://github.com/dedeveloper23/codebase-mcp/blob/main/src/tools/codebase.ts): repo processor · Main tool logic for turning repositories into text output · `src/tools/codebase.ts`

### Other components

- **RepoMix**: external processor · External codebase-to-text engine used by the tool layer
- **GitHub**: remote source · Remote repository source for codebase ingestion

## Connections

- CLI → Server core: starts · CLI launches the server runtime
- Server core → MCP runtime: composes · Server core wires MCP runtime
- Server core → Server stdio: serves · Server core exposes stdio transport
- Server core → Server SSE: serves · Server core exposes SSE transport
- Server core → Auth router: mounts · Server core mounts auth routing
- MCP runtime → Protocol types: uses · MCP runtime relies on shared protocol shapes
- MCP runtime → Transport types: uses · MCP runtime uses shared transport contracts
- MCP runtime → Codebase tool: invokes · Tool calls are dispatched to codebase processing
- Server stdio → Stdio shared: uses · Server stdio transport uses shared stdio helpers
- Server SSE → Transport types: uses · SSE transport implements shared transport contracts
- Auth router → Auth provider: delegates · Auth routing delegates to provider logic
- Auth router → Auth handlers: routes · Router exposes auth endpoint handlers
- Auth handlers → Auth middleware: guards · Handlers are protected by auth middleware
- Auth provider → Shared auth: uses · Provider implementation uses shared auth utilities
- Client core → Client auth: configures · Client core configures auth/session behavior
- Client core → Client stdio: connects · Client core can connect over stdio
- Client core → Client SSE: connects · Client core can connect over SSE
- Client core → WebSocket client: connects · Client core can connect over WebSocket
- Client core → Protocol types: uses · Client core speaks the shared protocol
- Client stdio → Stdio shared: uses · Client stdio transport uses shared stdio helpers
- Client SSE → Transport types: uses · Client SSE transport uses shared transport contracts
- WebSocket client → Transport types: uses · WebSocket client uses shared transport contracts
- Codebase tool → RepoMix: depends on · Repository analysis is delegated to RepoMix
- Codebase tool → GitHub: fetches · Remote repository support sources code from GitHub
- Codebase tool → Protocol types: returns · Tool results are shaped by shared protocol contracts
- Protocol types → Transport types: aligns with · Protocol shapes sit on transport contracts
- Transport types → Stdio shared: specializes · Shared transport includes stdio-specific helpers
- Shared auth → URI templates: uses · Auth utilities rely on URI template helpers
- Server core → Completable: coordinates · Server runtime uses deferred completion for lifecycle handling
