A comprehensive Model Context Protocol (MCP) server that provides a graph database for tracking software codebase components, their relationships, and associated tasks/goals. Built with Neo4j for powerful graph queries and analysis, featuring both STDIO MCP and HTTP/SSE interfaces.
- Dual Interface Support: Both STDIO MCP and HTTP/SSE interfaces
- Component Management: Track files, functions, classes, modules, and systems
- Relationship Mapping: Model dependencies, inheritance, imports, and other relationships
- Task Integration: Link tasks and goals directly to codebase components
- Bulk Operations: Efficient bulk creation of components, relationships, and tasks
- Multi-level Abstraction: Support analysis at any level from individual functions to entire systems
- Real-time Events: Server-Sent Events (SSE) for live updates
- Change History: Complete audit trail with snapshots and replay capabilities
- Command Queue: Agent coordination and external integration system
- Voting System: Community-driven type proposal and approval system
- MCP Compatible: Works with any MCP-compatible AI agent or tool
- Download Neo4j Community Edition: https://neo4j.com/download/
- Install and start Neo4j:
- Default URL:
bolt://localhost:7687
- Default username:
neo4j
- Default password:
password
(you may need to change this on first login)
- Default URL:
- Node.js 18+ required
- npm or yarn package manager
- Clone and install dependencies:
cd codebase-graph-mcp
npm install
- Set up the database:
npm run setup-db
- Start the MCP server:
npm start
The server supports multiple operation modes:
npm start
# or
node src/index.js
- Runs both STDIO MCP server and HTTP/SSE server
- Default HTTP port: 3000
- Suitable for development and full-featured access
HTTP_ONLY=true HTTP_PORT=3001 npm run start:http
- Runs only the HTTP server with SSE support
- No STDIO MCP interface
- Ideal for web integrations and external tools
ENABLE_HTTP=false npm start
- Runs only the STDIO MCP server
- No HTTP interface
- Minimal resource usage for MCP-only scenarios
To connect an MCP client (like Claude Desktop) to this server, use this configuration:
{
"mcpServers": {
"codebase-graph": {
"command": "node",
"args": ["src/index.js"],
"cwd": "C:/Users/magne/codebase-graph-mcp"
}
}
}
For Claude Desktop:
- Copy the configuration from
claude-desktop-config.json
- Add it to your Claude Desktop MCP settings
- Restart Claude Desktop
- The codebase-graph tools will be available
Alternative configurations are available in config-examples.json
for different setups (remote Neo4j, custom credentials, etc.).
Edit the database connection in src/database.js
if needed:
const db = new GraphDatabase(
'bolt://localhost:7687', // Neo4j URI
'neo4j', // Username
'password' // Password
);
export NEO4J_URI=bolt://localhost:7687
export NEO4J_USERNAME=neo4j
export NEO4J_PASSWORD=your_password
# HTTP Server Settings
export ENABLE_HTTP=true # Enable/disable HTTP server (default: true)
export HTTP_ONLY=false # HTTP-only mode, disable STDIO (default: false)
export HTTP_PORT=3000 # HTTP server port (default: 3000)
export HTTP_HOST=localhost # HTTP server host (default: localhost)
export CORS_ORIGIN=* # CORS origin setting (default: *)
# Feature Toggles
export ENABLE_VOTING=false # Enable voting system (default: false)
export ENABLE_AUTH=false # Enable authentication (default: false)
export NODE_ENV=development # Environment mode
export DEBUG=true # Enable debug logging
FILE
: Source code filesFUNCTION
: Functions or methodsCLASS
: Classes or typesMODULE
: Modules or packagesSYSTEM
: High-level system componentsINTERFACE
: Interfaces or contractsVARIABLE
: Variables or constantsCONSTANT
: Constants or configuration
REQUIREMENT
: System or functional requirementsSPECIFICATION
: Technical specificationsFEATURE
: Feature definitionsUSER_STORY
: User stories and scenariosACCEPTANCE_CRITERIA
: Acceptance criteria for featuresTEST_CASE
: Test cases and scenarios
DEPENDS_ON
: Component depends on anotherIMPLEMENTS
: Implements an interfaceEXTENDS
: Inherits from another componentCONTAINS
: Contains another componentCALLS
: Calls a function or methodIMPORTS
: Imports another moduleEXPORTS
: Exports functionalityOVERRIDES
: Overrides parent functionalityUSES
: Uses another componentCREATES
: Creates instances of another component
SATISFIES
: Satisfies a requirement or specificationDERIVES_FROM
: Derived from another requirementREFINES
: Refines or elaborates on another componentTRACES_TO
: Traces to another component for complianceVALIDATES
: Validates another componentVERIFIES
: Verifies implementation of another componentCONFLICTS_WITH
: Conflicts with another componentSUPPORTS
: Supports or enables another componentALLOCATES_TO
: Allocates resources to another componentREALIZES
: Realizes or implements a specification
TODO
: Not startedIN_PROGRESS
: Currently being worked onDONE
: CompletedBLOCKED
: Blocked by dependenciesCANCELLED
: Cancelled
create_component
: Create a new componentget_component
: Retrieve component by IDsearch_components
: Search with filtersupdate_component
: Update component propertiesdelete_component
: Delete a component
create_components_bulk
: Create multiple components efficientlycreate_relationships_bulk
: Create multiple relationships efficientlycreate_tasks_bulk
: Create multiple tasks efficiently
create_relationship
: Create relationship between componentsget_component_relationships
: Get all relationships for a componentget_dependency_tree
: Get dependency tree (supports max depth)
create_task
: Create a new taskget_task
: Get task by IDget_tasks
: Get all tasks (optional status filter)update_task_status
: Update task status and progress
get_change_history
: Get change history for entities or recent changescreate_snapshot
: Create a snapshot of current database statelist_snapshots
: List all available snapshotsrestore_snapshot
: Restore database from a snapshotreplay_to_timestamp
: Replay changes to recreate state at specific timeget_history_stats
: Get statistics about change history
wait_for_command
: Wait for commands from external systemssend_command
: Send commands to waiting agentsget_waiting_agents
: Get status of agents waiting for commandsget_pending_commands
: Get queued but undelivered commandscancel_command
: Cancel a pending commandcancel_wait
: Cancel an agent's wait for commandsget_command_history
: Get command queue execution history
propose_type
: Propose new component or relationship typesvote_on_type
: Vote on proposed typesget_proposed_types
: Get all proposed types with status filterget_proposed_type
: Get details of specific proposed typeapply_approved_type
: Apply approved types to the systemget_voting_stats
: Get voting system statistics
get_codebase_overview
: Get statistics for a codebase
For terminal-enabled agents, the system provides CLI-based queue waiters that don't require MCP client integration:
# Wait indefinitely with auto-generated ID
node examples/cli-queue-waiter.js
# Wait with custom session name
node examples/cli-queue-waiter.js my-analysis-agent
node examples/cli-queue-waiter.js build-agent-1
# Show current waiting agents and capacity
node examples/list-agents.js
# Continuous monitoring (refreshes every 5 seconds)
node examples/list-agents.js --watch
# JSON output for programmatic use
node examples/list-agents.js --json
- Indefinite waiting: Runs until manually canceled (Ctrl+C)
- Named sessions: Custom agent IDs for identification
- Capacity reporting: Automatically reports availability to the system
- Status updates: Real-time uptime and command processing stats
- Graceful shutdown: Clean session termination with statistics
- Auto-reconnection: Automatically re-registers after processing commands
The server also provides an HTTP REST API with Server-Sent Events for real-time updates:
- Components:
GET|POST|PUT|DELETE /api/components[/:id]
- Relationships:
GET|POST /api/relationships
- Tasks:
GET|POST|PUT /api/tasks[/:id]
- Bulk Operations:
POST /api/{components|relationships|tasks}/bulk
- Analysis:
GET /api/codebase/:name/overview
- Change History:
GET /api/history
- Command Queue:
GET|POST|DELETE /api/commands
- Connection:
GET /events
- Events:
component-created
,component-updated
,task-created
, etc. - Bulk Events:
components-bulk-created
,relationships-bulk-created
, etc. - Real-time Updates: Live notifications of all database changes
# Test bulk operations
node test-bulk-operations.js
# Test SSE connection
node test-sse-client.js
// Create multiple components efficiently
const components = [
{
type: 'FILE',
name: 'UserService.ts',
codebase: 'my-app',
description: 'User management service'
},
{
type: 'CLASS',
name: 'UserService',
codebase: 'my-app',
description: 'Main user service class'
}
];
const result = await createComponentsBulk({ components });
console.log(`Created ${result.length} components`);
// Create a file component
await createComponent({
type: 'FILE',
name: 'UserService.ts',
description: 'User management service',
path: '/src/services/UserService.ts',
codebase: 'my-app'
});
// Create a class component
await createComponent({
type: 'CLASS',
name: 'UserService',
description: 'Handles user CRUD operations',
path: '/src/services/UserService.ts',
codebase: 'my-app'
});
// File contains class
await createRelationship({
type: 'CONTAINS',
sourceId: fileId,
targetId: classId,
details: { location: 'line 10' }
});
// Class depends on database
await createRelationship({
type: 'DEPENDS_ON',
sourceId: classId,
targetId: databaseId,
details: { reason: 'data persistence' }
});
// Create a task linked to components
await createTask({
name: 'Add user validation',
description: 'Implement input validation for user creation',
status: 'TODO',
progress: 0,
relatedComponentIds: [userServiceId, validatorId]
});
// Get all components in a codebase
const components = await searchComponents({
codebase: 'my-app'
});
// Get dependency tree
const dependencies = await getDependencyTree(componentId, 3);
// Get codebase overview
const overview = await getCodebaseOverview('my-app');
This MCP server is designed to work with AI agents for:
- Code Analysis: Understanding existing codebase structure
- Impact Assessment: Analyzing changes and their effects
- Architecture Planning: Designing new features and components
- Task Management: Tracking development goals and progress
- Dependency Management: Understanding and managing dependencies
- "What components depend on the User class?"
- "Show me all TODO tasks related to authentication"
- "What would be affected if I change the Database interface?"
- "Create a task to refactor the payment system"
npm test
npm run dev
To reset the database:
- Stop the server
- Clear Neo4j database (in Neo4j Browser:
MATCH (n) DETACH DELETE n
) - Run setup again:
npm run setup-db
- Components: Nodes with labels
[:Component:TYPE]
- Tasks: Nodes with label
[:Task]
- Relationships: Edges between components with type-specific labels
- Task Relations:
[:RELATES_TO]
edges between tasks and components
- Unique constraints on component and task IDs
- Indexes on component name, type, and codebase
- Index on task status
-
Neo4j Connection Failed
- Ensure Neo4j is running
- Check connection details
- Verify authentication credentials
-
Schema Initialization Failed
- Check Neo4j permissions
- Ensure database is empty or compatible
-
MCP Connection Issues
- Verify stdio transport setup
- Check MCP client configuration
- For port conflicts with HTTP server, use MCP-only mode:
node src/mcp-only.js
-
"Child process ended (EOF on stdout)" Error
- This usually indicates the server process crashed during startup
- Check if another process is using port 3000 (
lsof -i :3000
) - Use the MCP-only entry point to avoid HTTP server conflicts
- For Goose: Update config to use
src/mcp-only.js
instead ofsrc/index.js
Server logs are written to stderr and include:
- Database connection status
- Schema initialization progress
- Error messages with details
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
MIT License - see LICENSE file for details