GraphSense
STDIO结合图数据库、向量搜索和LLM的代码分析检索系统
结合图数据库、向量搜索和LLM的代码分析检索系统
A code analysis and retrieval system that combines graph databases, vector search, and LLMs to understand and query codebases through natural language.
It indexes JavaScript/TypeScript codebases into both a Neo4j graph database and a PostgreSQL vector database, enabling sophisticated queries about code structure, dependencies, and semantic relationships.
# Navigate to your git repository $ cd ~/path/to/repo # Run GraphSense from within the repository $ npx graphsense
Note: You will need environment variables declared in ~/.graphsense/.env:
Required variables (must be set):
ANTHROPIC_API_KEY - Claude API keyPINECONE_API_KEY - Pinecone API keyGraphSense provides an MCP server to integrate with AI assistants like Claude Desktop, enabling natural language queries about your codebase.
The MCP server uses stdio transport and is automatically started when you run the main application.
# Navigate to your git repository $ cd ~/path/to/repo # Run GraphSense from within the repository $ npx graphsense
Add this to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{ "mcpServers": { "graphsense": { "command": "npx", "args": ["graphsense"], "env": {} } } }
Note: Your preferred AI coding editor/agent will have similar configuration options.
similar_functions - Find functions based on semantic description
function_description (string), topK (number, optional)function_callers - Find functions that call a specific function
functionId (string) - The element ID of the target functionfunction_callees - Find functions called by a specific function
functionId (string) - The element ID of the source functionfunction_details - Get detailed information about a specific function
functionId (string) - The element ID of the functionOnce configured, you can use natural language queries in your AI assistant:
Natural Language Queries:
Structural Queries:
Database Connection Errors
# Check if PostgreSQL is running docker ps | grep postgres # Check if Neo4j is running docker ps | grep neo4j # Test database connections psql -h localhost -p 5432 -U postgres -d graphsense
Port Conflicts
docker ps output for actual ports if differentEnvironment Variables
Verify required environment variables are set in ~/.graphsense/.env.
If not:
# Create a dedicated config directory mkdir -p ~/.graphsense # Store environment variables securely cat > ~/.graphsense/.env << EOF ANTHROPIC_API_KEY=your-key-here PINECONE_API_KEY=your-key-here EOF # Set proper permissions chmod 600 ~/.graphsense/.env
# Run with debug output DEBUG=* node build/mcp.js # Check server logs tail -f ~/.graphsense/logs/mcp.log
The system uses a hybrid approach combining:
Neo4j Graph Database: Stores structural relationships between files and functions
PostgreSQL with pgvector: Stores function embeddings for semantic search
Pinecone Vector Databases: Dual-index setup for enhanced search
The system uses two databases:
Both databases are automatically started via docker, for each repository path there will be a separate set of these 2 databases.
See ENVIRONMENT.md for complete configuration guide.
The system uses 2 AI providers:
Hybrid search approach:
src/
├── db.ts           # Database setup and connections
├── env.ts          # Environment configuration
├── index.ts        # Main indexing logic
├── mcp.ts          # Model Context Protocol HTTP server
├── parse.ts        # Code parsing and AI processing
├── watcher.ts      # File watcher for real-time analysis
└── entrypoint.ts   # Entrypoint for the package
# Compile TypeScript npx tsc # Watch mode for development npx tsc --watch
Licensed under GPL v3.0