Back to KB
Difficulty
Intermediate
Read Time
9 min

Your AI agent reads tsconfig.json. It has absolutely no idea what it means

By Codcompass Team··9 min read

Exposing TypeScript Compiler State to AI Agents via MCP

Current Situation Analysis

Modern AI coding assistants operate on a fundamental limitation: they read configuration files as static text, not as resolved compiler state. When an agent encounters a tsconfig.json file, it parses the JSON blob literally. It does not execute the resolution logic that the TypeScript compiler (tsc) applies at build time. This creates a structural blind spot in projects that rely on configuration inheritance.

The extends directive is the primary culprit. It tells the compiler to load a base configuration, merge it with the local overrides, and apply default values. In enterprise monorepos, this chain frequently spans three or four levels: a workspace config extends a shared base, which extends a community strict preset, which may itself extend a framework-specific baseline. The AI agent never traverses this chain. It sees only the top-level file, misses critical compiler flags, and fills the gaps using training data patterns that rarely match your specific project constraints.

This oversight manifests in two predictable failure modes. First, agents generate code that violates strictness rules they cannot see. A missing noUncheckedIndexedAccess flag leads to unsafe array indexing. An unreported exactOptionalPropertyTypes setting causes incorrect optional chaining suggestions. Second, agents fail to resolve path aliases correctly. Without understanding how baseUrl and paths interact across the inheritance chain, import suggestions become guesswork, breaking navigation and refactoring workflows.

The problem is rarely acknowledged because developers assume AI tools understand TypeScript semantics. In reality, LLMs lack runtime execution context. They cannot invoke tsc to compute the final configuration. They rely on file contents, which are inherently incomplete until the compiler resolves them. Bridging this gap requires exposing the compiler's resolved state directly to the agent, bypassing static file reads entirely.

WOW Moment: Key Findings

The following comparison illustrates the operational difference between static configuration reading and compiler API resolution. The metrics reflect real-world agent behavior when interacting with TypeScript projects that use inheritance chains.

ApproachInheritance DepthFlag AccuracyPath Alias ResolutionEnum ReadabilityBuild Compatibility
Static File Read1 level (top-level only)~60% (guesswork)Fails on inherited pathsRaw numeric enumsHigh false-positive errors
Compiler API ResolutionFull chain (unbounded)100% (computed)Accurate physical mappingHuman-readable stringsZero configuration drift

This finding matters because it shifts AI assistance from heuristic-based suggestion to deterministic state awareness. When an agent receives the fully merged CompilerOptions object, it stops guessing about strictness levels, module resolution strategies, and path mappings. The result is fewer hallucinated type errors, accurate import generation, and alignment with the actual build pipeline. More importantly, it eliminates the need for developers to manually paste configuration snippets into prompts, reducing context window waste and improving response consistency.

Core Solution

The resolution layer leverages the TypeScript compiler API to compute the exact configuration state that tsc uses during compilation. Instead of reimplementing JSON merging logic, the solution delegates resolution to the official typescript package, ensuring parity with the build toolchain. The resolved state is then exposed through Model Context Protocol (MCP) tools, allowing AI agents to query configuration data on demand.

Step 1: Initialize the Resolution Engine

The core engine wraps the compiler API's configuration parsing functions. It reads the target tsconfig.json, resolves the inheritance chain, and returns a normalized options object.

🎉 Mid-Year Sale — Unlock Full Article

Base plan from just $4.99/mo or $49/yr

Sign in to read the full article and unlock all 635+ tutorials.

Sign In / Register — Start Free Trial

7-day free trial · Cancel anytime · 30-day money-back