A Model Context Protocol (MCP) server for comprehensive TypeScript code analysis using ts-morph. This server provides advanced static analysis capabilities for TypeScript codebases, including symbol extraction, dependency analysis, code quality detection, and pattern matching.
- File Analysis: Comprehensive analysis of TypeScript files with configurable depth and detail
- Symbol Search: Semantic symbol search across codebases with scoring and filtering
- Pattern Matching: AST-based, semantic, and regex pattern detection
- Code Quality: Automated detection of code smells and complexity issues
- Reference Tracking: Find all references to symbols with context
- Dependency Analysis: Import/export dependency graph generation
- Context Extraction: AI-friendly context extraction for code understanding
- Codebase Summarization: High-level architectural analysis and metrics
-
Build the server:
pnpm install pnpm run build
-
Install to MCP clients:
# Install to all supported clients pnpm run install-server # Install to specific clients pnpm run install-cursor # Cursor IDE pnpm run install-desktop # Claude Desktop pnpm run install-code # Claude Code CLI
Download the latest release from GitHub releases and extract to your desired location:
# Download and extract
curl -L https://github.com/tryterra/static-analysis/releases/latest/download/mcp-typescript-analyzer-vX.X.X.tar.gz | tar -xz
# Make executable
chmod +x dist/index.js
Analyzes a single TypeScript file with configurable depth and detail.
Parameters:
filePath
(string): Path to the TypeScript fileanalysisType
(enum): Type of analysis - "symbols", "dependencies", "complexity", "all"depth
(number): Analysis depth (1-3, default: 2)includePrivate
(boolean): Include private members (default: false)outputFormat
(enum): Output format - "summary", "detailed", "full" (default: "summary")
Search for symbols across the codebase using various strategies.
Parameters:
query
(string): Search querysearchType
(enum): Search type - "text", "semantic", "ast-pattern"symbolTypes
(array): Filter by symbol types (class, interface, function, etc.)maxResults
(number): Maximum results to return (default: 50)includeReferences
(boolean): Include reference information (default: false)
Get detailed information about a specific symbol at a given position.
Parameters:
filePath
(string): Path to the fileposition
(object): Line and character positionincludeRelationships
(boolean): Include type relationships (default: true)includeUsages
(boolean): Include usage information (default: false)depth
(number): Analysis depth (default: 2)
Find all references to a symbol across the project.
Parameters:
filePath
(string): Path to the file containing the symbolposition
(object): Position of the symbolincludeDeclaration
(boolean): Include the declaration (default: false)scope
(enum): Search scope - "file" or "project" (default: "project")maxResults
(number): Maximum results (default: 100)
Analyze import/export dependencies and generate dependency graphs.
Parameters:
filePath
(string, optional): Specific file to analyzedirection
(enum): Analysis direction - "imports", "exports", "both"depth
(number): Analysis depth (default: 2)includeNodeModules
(boolean): Include node_modules (default: false)groupBy
(enum): Grouping strategy - "module", "file", "none" (default: "module")
Search for code patterns using AST matching, semantic analysis, or regex.
Parameters:
pattern
(string): Pattern to search forpatternType
(enum): Pattern type - "ast", "semantic", "regex"maxResults
(number): Maximum results (default: 100)includeContext
(boolean): Include surrounding context (default: true)
Identify common code quality issues and anti-patterns.
Parameters:
filePath
(string, optional): Specific file to analyzecategories
(array): Categories to check - complexity, duplication, coupling, naming, unused-code, async-issuesthreshold
(object): Configurable thresholds for various metrics
Extract relevant context for AI understanding and code completion.
Parameters:
filePath
(string): Path to the fileposition
(object, optional): Position to focus oncontextType
(enum): Context type - "function", "class", "module", "related"maxTokens
(number): Maximum tokens to return (default: 2000)includeImports
(boolean): Include import statements (default: true)includeTypes
(boolean): Include type information (default: true)
Generate a high-level summary of the entire codebase.
Parameters:
rootPath
(string, optional): Root directory to analyzeincludeMetrics
(boolean): Include complexity metrics (default: true)includeArchitecture
(boolean): Include architectural analysis (default: true)maxDepth
(number): Maximum directory depth (default: 5)
The server includes an intelligent caching system that:
- Caches parsed TypeScript files and analysis results
- Adapts caching strategy based on project size
- Provides significant performance improvements for repeated operations
- Parallel processing for multi-file operations
- Configurable timeouts and memory monitoring
- Adaptive algorithms based on codebase size
- Comprehensive error reporting with detailed context
- Graceful degradation for partially corrupt files
- Structured error codes for programmatic handling
Create a .env.local
file to configure the server:
# Optional: Set custom timeout values
ANALYSIS_TIMEOUT=30000
MEMORY_LIMIT=1000000000
# Optional: Configure caching
CACHE_SIZE=1000
CACHE_TTL=3600000
The server automatically detects and uses your project's tsconfig.json
file for accurate type analysis.
{
"tool": "analyze_file",
"params": {
"filePath": "./src/index.ts",
"analysisType": "all",
"outputFormat": "detailed"
}
}
{
"tool": "search_symbols",
"params": {
"query": "UserService",
"searchType": "semantic",
"symbolTypes": ["class", "interface"]
}
}
{
"tool": "find_patterns",
"params": {
"pattern": "console.log",
"patternType": "ast"
}
}
{
"tool": "detect_code_smells",
"params": {
"categories": ["complexity", "naming", "unused-code"],
"threshold": {
"complexity": 15,
"functionSize": 100
}
}
}
The server is built with a modular architecture:
src/index.ts
: MCP server setup and tool registrationsrc/tools.ts
: Tool implementations and schemassrc/analyzer.ts
: Core TypeScript analysis enginesrc/utils.ts
: Utility functions and project managementsrc/cache.ts
: Intelligent caching systemsrc/types.ts
: TypeScript type definitions
See TEST_RESULTS.md
for detailed test results and examples of all tool outputs.
MIT License - see LICENSE file for details.
This project includes automated GitHub Actions workflows for:
- Continuous Integration: Builds and tests across multiple operating systems (Ubuntu, Windows, macOS) and Node.js versions (18, 20)
- Automated Releases: Creates distribution packages (tar.gz and zip) when version tags are pushed
- Cross-platform Support: Ensures compatibility across different environments
To create a new release:
# Tag a new version
git tag v1.0.1
git push origin v1.0.1
# GitHub Actions will automatically build and create the release
- Node.js 18+
- TypeScript 5.0+
- A TypeScript project with valid
tsconfig.json