How dedeveloper23/codebase-mcp works
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: server/index.ts Server core · transport.ts Transport types · client/index.ts Client core · mcp.ts MCP runtime
Components 23
CLI
Package entrypoint and startup commands
- CLI · Command-line entrypoint for starting the package
src/cli.ts
Server runtime
MCP server composition, transports, and auth
- Server core · Top-level server wiring and runtime assembly
src/server/index.ts - MCP runtime · MCP session handling and tool registration
src/server/mcp.ts - Server stdio · Server-side stdio transport implementation
src/server/stdio.ts - Server SSE · Server-side SSE transport implementation
src/server/sse.ts - Completable · Deferred completion abstraction used by server flows
src/server/completable.ts - Auth router · Routes auth endpoints into a structured HTTP surface
src/server/auth/router.ts - Auth provider · Provider abstraction behind auth operations
src/server/auth/provider.ts - Auth handlers · Authorize, register, token, revoke, and metadata handlers
src/server/auth/handlers/authorize.ts - Auth middleware · Allowed-methods, client-auth, and bearer-auth checks
src/server/auth/middleware/allowedMethods.ts
Client SDK
Reusable client-side MCP connection helpers
- Client core · Client-side entrypoint and connection orchestration
src/client/index.ts - Client auth · Client-side auth setup and token/session handling
src/client/auth.ts - Client stdio · Client transport for stdio-connected MCP servers
src/client/stdio.ts - Client SSE · Client transport for SSE-connected MCP servers
src/client/sse.ts - WebSocket client · Client transport for websocket MCP connections
src/client/websocket.ts
Shared core
Protocol, transport, and utility contracts used across the repo
- Protocol types · Shared MCP protocol shapes and message contracts
src/shared/protocol.ts - Transport types · Shared transport interfaces and wiring contracts
src/shared/transport.ts - Stdio shared · Shared stdio helpers used by client and server
src/shared/stdio.ts - Shared auth · Common auth utilities and shared auth shapes
src/shared/auth.ts - URI templates · URI template helpers for resource addressing
src/shared/uriTemplate.ts
Tools
Repository-processing business logic
- Codebase tool · Main tool logic for turning repositories into text output
src/tools/codebase.ts
Other components
- RepoMix · External codebase-to-text engine used by the tool layer
- GitHub · Remote repository source for codebase ingestion
Connections 29
- 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