This page explains how the current codebase is structured and where to add new behavior safely.
System overview
coding-mcp is organized as a layered TypeScript service with one shared application core and two transports.
src/config: validates and normalizes runtime configurationsrc/core: shared contracts (errors, responses, logging, telemetry, locks)src/services: domain services (registry, filesystem, patch, git, commands, auth)src/mcp: MCP server setup with tool/resource/prompt registriessrc/main: bootstrap and transport entrypoints (stdio,http,cli)
Bootstrap and dependency wiring
The application starts insrc/main/bootstrap.ts.
You can treat this file as the service container for the project:
- Load and validate config
- Construct infrastructure services
- Construct domain services
- Return
AppServicesfor transports and MCP registries
- Project indexing is initialized through
ProjectRegistryService - Safety controls are applied through
PathGuard, command policy, and lock manager - Auth and telemetry are attached once in bootstrap, then reused everywhere
Request flow
For HTTP transport, requests flow through these stages:src/main/http-server.tsauthenticates request headers when auth is enabled- Auth context is attached for downstream authorization
- MCP transport forwards calls to registered handlers
executeOperationinsrc/mcp/tools/tool-helpers.tsruns RBAC checks and wraps execution in a response envelope- Services perform the operation and return structured data
MCP registration model
src/mcp/server.ts creates the MCP server and registers:
- Tools from
src/mcp/tools - Resources from
src/mcp/resources - Prompts from
src/mcp/prompts
- Validate input with zod schemas in
src/mcp/schemas - Delegate to a service
- Return consistent envelope data
Project registry and multi-root behavior
The registry is implemented in:src/services/project-registry/project-registry.service.tssrc/services/project-registry/project-scanner.tssrc/services/project-registry/registry-store-json.ts
- Supports multiple roots (
PROJECTS_ROOTS) - Persists roots and discovered projects
- Supports CLI root management via:
coding-mcp initcoding-mcp add <folder>coding-mcp remove <folder>
Safety model
Safety controls are implemented by default in service boundaries. Core controls:- Path traversal prevention and project-root boundary checks
- Protected path enforcement for mutations
- Confirm flags for destructive operations
- Allowlist-only command execution with arg checks
- Timeout and output/file size limits
- Per-project lock for mutating operations
- Audit log entries for file mutations
Auth and RBAC
HTTP deployments can require API keys with role-based operation permissions. Roles:viewer: read-oriented operationseditor: read + most write/build/test operationsadmin: full operation set
executeOperation before the service action runs.
Telemetry and observability
OpenTelemetry spans are emitted when enabled:mcp.http.requestmcp.tool.{operation}
File and patch operations
The file layer insrc/services/filesystem/filesystem.service.ts implements:
- Directory listing and file reads
- Safe writes, deletes, and moves
- Content search and project tree
- Binary-safe resource reads (text or base64 blob)
src/services/patch includes:
- Structured edit operations
- Unified diff hunk parsing and application
- Conflict reporting for non-matching hunks
How to add a new tool safely
Register the tool handler
Register in the correct file under
src/mcp/tools and call executeOperation.Recommended next deep-dive pages
Quickstart
Run the server locally and verify your setup.
Development
Use the local preview workflow and validation commands.