@goodfoot/codebase-mcp-server
v0.1.2
Published
MCP server for codebase analysis and code search
Readme
@goodfoot/codebase-mcp-server
Model Context Protocol (MCP) server providing intelligent codebase analysis and code search capabilities using Claude Code SDK. This package enables natural language queries to understand, navigate, and analyse codebases effectively.
Overview
The codebase MCP server delivers sophisticated code analysis through an intelligent agent that selects and orchestrates the appropriate tools for each query. It provides comprehensive codebase understanding through symbol analysis, dependency mapping, error investigation, and flow tracing.
Key Features
- Natural Language Queries: Ask questions about your codebase in plain English
- Intelligent Tool Selection: Automatic selection of optimal tools (VSCode LSP, Grep, ast-grep, etc.)
- Symbol Analysis: Understand functions, classes, types, and their relationships
- Dependency Mapping: Trace imports, exports, and module dependencies
- Error Investigation: Analyse TypeScript errors and runtime issues with full context
- Flow Analysis: Understand data flow and execution paths through code
- Configurable Logging: Optional diagnostic logging for troubleshooting
- Query Logs: Complete transcripts of analysis for review and debugging
Installation
yarn add @goodfoot/codebase-mcp-serverQuick Start
Starting the Server
node ./build/dist/src/codebase.jsThe server automatically uses the current working directory as the workspace path.
MCP Client Configuration
Configure in your MCP client settings:
{
"mcpServers": {
"codebase": {
"command": "node",
"args": ["/path/to/@goodfoot/codebase-mcp-server/build/dist/src/codebase.js"],
"env": {
"CODEBASE_MCP_SERVER_LOGGING": "false"
}
}
}
}Available Tools
ask
Searches and analyses codebases to answer technical questions. Optimised for focused questions about specific files, symbols, errors, or code flow.
Parameters:
| Parameter | Type | Required | Description |
| ---------- | ------ | -------- | ----------------------------------------------------------------------- |
| question | string | Yes | Technical question about the codebase with full file paths in monorepos |
Example Usage:
// Investigate TypeScript error
await client.callTool({
name: 'ask',
arguments: {
question: 'TypeScript error TS2322 at packages/api/src/user.ts:45: Why is email required?'
}
});
// Trace dependencies
await client.callTool({
name: 'ask',
arguments: {
question: 'What files import from packages/shared/src/types/user.ts?'
}
});
// Analyse code flow
await client.callTool({
name: 'ask',
arguments: {
question: 'How does the authentication system process login requests?'
}
});
// Find symbol definition and usage
await client.callTool({
name: 'ask',
arguments: {
question: 'Find the definition and all usages of UserService class'
}
});Configuration
Environment Variables
CODEBASE_MCP_SERVER_LOGGING
Enables diagnostic logging to stderr.
- Default:
false(logging disabled) - Values:
"true"or"false" - Output: All logs written to stderr with level prefixes
CODEBASE_MCP_SERVER_LOGGING=true node ./build/dist/src/codebase.jsLog Levels:
[DEBUG]- Detailed debugging information[INFO]- General informational messages[WARN]- Warning conditions[ERROR]- Error conditions
Tool Selection Guide
The server includes comprehensive system instructions that guide the analysis agent to select optimal tools:
Symbol Searches (Functions/Classes/Types)
Primary Approach: VSCode LSP
- Use Grep to find where symbol is defined
- Use
get_symbol_lsp_infowith definition file path - Use
get_referencesfor all usage locations
Example Flow:
Question: "Find all references to updateGitAvailability"
→ Grep for "updateGitAvailability" to find definition
→ get_symbol_lsp_info at definition file
→ get_references to find all usagesStructural Patterns (Inheritance/Implementation)
Use ast-grep for code structure patterns:
- Class inheritance (
class X extends Y) - Interface implementation (
class X implements Y) - Type constraints
- Decorator patterns
Text Patterns (Comments/Strings/Literals)
Use Grep for:
- console.log statements
- TODO comments
- String literals
- Regular expression patterns
TypeScript Errors
- Use
get_diagnosticsto see all errors - Use
get_symbol_lsp_infoto investigate specific types - Analyse type definitions and relationships
Module Dependencies
print-dependencies: Show what a file importsprint-inverse-dependencies: Show what imports a file (impact analysis)print-typescript-types: Analyse exported typesprint-type-analysis: Get complexity metrics
Query Best Practices
Effective Questions
Good:
- "TypeScript error TS2322 at packages/api/src/user.ts:45: Why is email required?"
- "What files import from packages/shared/src/types/user.ts?"
- "How does packages/api/src/services/user.ts depend on database types?"
- "Find all implementations of the UserRepository interface"
Less Effective:
- "How does useTranscriptSync work?" (missing full path)
- "Find all bugs" (too vague)
- "Analyse the codebase" (too broad)
Path Specifications
Always provide full paths in monorepos:
✓ packages/api/src/user.ts
✓ apps/web/src/components/UserProfile.tsx
✗ user.ts
✗ src/user.tsLogging and Monitoring
Query Logs
All questions and analysis transcripts are logged to:
/workspace/reports/.codebase-questions/{timestamp}.mdLog Contents:
- Original question (quoted)
- Complete tool execution trace
- Tool call parameters
- Tool responses
- Final analysis answer
Log Format:
> What files import from packages/shared/src/types/user.ts?
---
```tool-call
Grep(
pattern="...",
glob="**/*.ts"
)
```[Tool output][Final analysis answer]
### Diagnostic Logging
Enable with `CODEBASE_MCP_SERVER_LOGGING=true`:
- Server startup and shutdown
- Tool execution details
- Error conditions
- Request cancellations
### Log Location
- **Query Logs**: `/workspace/reports/.codebase-questions/`
- **Diagnostic Logs**: stderr (when enabled)
## Abort Support
The server handles request cancellation gracefully:
### Cancellation Handling
- Propagates abort signals to Claude Code SDK
- Cleans up resources on cancellation
- Returns proper error messages to clients
- Logs cancellation events (when diagnostic logging enabled)
### Implementation
```typescript
// Client can cancel requests
const controller = new AbortController();
const promise = client.callTool({
name: 'ask',
arguments: {
question: 'Analyse entire codebase'
}
});
// Cancel after 5 seconds
setTimeout(() => controller.abort(), 5000);System Instructions
The server includes comprehensive system instructions covering:
Tool Selection Rules
- When to use VSCode LSP vs Grep vs ast-grep
- Proper workflow for symbol lookups
- Fallback strategies when primary tools fail
- Parallel vs sequential tool execution
Output Formatting
- Direct answers with no preamble
- Structured sections with headers
- Code snippets with file:line references
- Evidence-based conclusions
Error Handling
- Zero results documentation
- Tool failure recovery
- Alternative search strategies
Result Size Handling
| Result Count | Action | | ------------- | -------------------------------------------- | | 0 results | State "No results found" with search details | | 1-5 results | Show all with full context | | 6-20 results | Show all with brief context | | 21-50 results | Show first 10 with summary | | 50+ results | Show first 5 with count and pattern analysis |
Troubleshooting
Long Response Times
Cause: Complex queries requiring many tool invocations
Solution: Be more specific in questions
# Less specific (slower)
"How does authentication work?"
# More specific (faster)
"How does packages/api/src/auth/login.ts validate passwords?"No Results Found
Common Causes:
- Incorrect file paths: Use full paths in monorepos
- Symbol not in indexed files: Check file extensions and patterns
- Private/internal symbols: May not be exported or referenced
Verification:
# Check file exists
ls packages/api/src/user.ts
# Check symbol exists in file
grep -r "UserService" packages/"Operation was aborted" Errors
Normal when client cancels long-running requests. Check diagnostic logs for details:
CODEBASE_MCP_SERVER_LOGGING=true node ./build/dist/src/codebase.jsIncomplete Analysis
If analysis seems incomplete:
- Check query logs for tool execution traces
- Verify all required files are accessible
- Ensure VSCode language server is running (for LSP features)
- Try more specific questions
Development
Building the Package
yarn buildRunning Tests
yarn testLinting
yarn lintTechnical Architecture
Component Overview
- Codebase Server: Main MCP server exposing the
asktool - Query Handler: Processes questions and invokes Claude Code SDK
- System Instructions: Comprehensive tool selection guide
- Logger: Optional diagnostic logging system
- Transcript Writer: Logs all queries and responses
Analysis Flow
- Client sends question via
asktool - Server constructs system instructions with tool guide
- Claude Code SDK processes query with available tools
- Tools execute (Grep, VSCode LSP, ast-grep, etc.)
- Agent synthesises findings into structured answer
- Response returned to client
- Full transcript logged to disk
Available Tools
The analysis agent has access to:
- Grep: Text and regex search
- Glob: File pattern matching
- Read: File reading
- Bash: Command execution (git, print-dependencies, etc.)
- VSCode LSP Tools:
get_symbol_lsp_info: Symbol definitions and typesget_references: Find all symbol usagesget_diagnostics: TypeScript/ESLint errorsrename_symbol: Rename with reference updates
Disallowed Tools
For security and focus:
ExitPlanMode: Not applicable for analysisKillBash/BashOutput: Background process managementmcp__codebase__ask: Prevents recursive calls
Dependencies
@anthropic-ai/claude-agent-sdk: Claude Code SDK for intelligent analysis@modelcontextprotocol/sdk: MCP protocol implementationzod: Runtime type validation
Type Safety
Comprehensive TypeScript types with runtime validation for all parameters.
Performance Characteristics
Query Response Time
- Simple symbol lookups: 2-5 seconds
- Dependency analysis: 5-10 seconds
- Flow tracing: 10-30 seconds
- Comprehensive analysis: 30-60 seconds
Resource Usage
- Memory: Scales with codebase size and query complexity
- CPU: Bursts during tool execution, idle between queries
- Disk: Query logs accumulate over time
Optimisation Tips
- Use specific file paths to reduce search scope
- Ask focused questions rather than broad analysis requests
- Use monorepo paths (packages/api/src/file.ts) not relative paths
- Clean up old query logs periodically
Limitations
Current Limitations
- Language Support: Optimised for TypeScript/JavaScript (other languages supported but less optimised)
- VSCode Dependency: LSP features require VSCode language server
- Monorepo Paths: Best results with full paths in monorepos
- Query Complexity: Very broad questions may time out or produce incomplete results
Future Enhancements
- Multi-language support optimisation
- Caching for frequently accessed symbols
- Incremental analysis for large codebases
- Query result pagination
Use Cases
Code Review
await client.callTool({
name: 'ask',
arguments: {
question: 'What would break if I change the User interface in packages/types/user.ts?'
}
});Onboarding
await client.callTool({
name: 'ask',
arguments: {
question: 'How does the authentication flow work from login to session creation?'
}
});Debugging
await client.callTool({
name: 'ask',
arguments: {
question: 'Why does packages/api/tests/user.test.ts fail with TypeError: Cannot read property "id"?'
}
});Refactoring
await client.callTool({
name: 'ask',
arguments: {
question: 'Find all usages of the deprecated getUserById function'
}
});Security Considerations
Safe Operations
- Read-only filesystem access
- No file modifications
- No external network requests (except for SDK)
- Process execution limited to analysis tools
Workspace Isolation
- Server operates only within workspace directory
- No access to parent directories
- Log files contained in workspace
Licence
MIT
Support
For issues, feature requests, and questions, please refer to the main repository documentation.
