codescan
Provides tools to query a Neo4j graph database containing code structure, call graphs, and test coverage data, enabling advanced codebase exploration and dependency analysis.
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@codescanshow me the call graph for function process_data"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
CodeScan: Python Static Code Analyzer with Neo4j Integration
Website
Related MCP server: NervusDB MCP Server
Overview
scanner.py is a static code analysis tool designed to parse Python source code, extract structural and call-graph information, and store it in a Neo4j graph database. The tool is highly configurable via environment variables and is intended for advanced codebase exploration, dependency analysis, and visualization using Neo4j Browser with GraSS styling.
Features
AST-based parsing: Uses Python's
astmodule to traverse and analyze source code files.Class and function extraction: Identifies all classes, standalone functions, and class methods, including their file locations and line numbers.
Call graph construction: Detects function calls, including argument names/values, and creates
CALLSrelationships in the graph.Node labeling: Assigns multiple labels to nodes for advanced visualization (e.g.,
:Function,:MainFunction,:ClassFunction,:ReferenceFunction).Reference node handling: Creates special nodes for called functions that are not defined in the scanned codebase.
Test detection and coverage: Automatically identifies test components and establishes test coverage relationships:
Labels test files, functions, and classes with appropriate markers (
:Test,:TestFunction,:TestClass)Creates
TESTSrelationships between test code and the production code it testsConfigurable test patterns for different project structures and testing frameworks
Configurable directory traversal: Skips specified directories (e.g., virtualenvs,
.git, test folders) for efficient scanning.Relative path storage: Stores file paths relative to the project directory for improved portability.
Environment-based configuration: Reads Neo4j connection and project settings from a
.envfile.GraSS-compatible: Designed for use with Neo4j Browser's GraSS stylesheet for custom node/relationship coloring.
Progress visualization: Uses tqdm progress bars to show scanning progress and element discovery.
Statistics collection: Gathers and displays detailed statistics about the scanned codebase.
Verbosity control: Offers quiet and verbose modes for controlling output detail.
Setting Up Your Environment
Environment File Setup
CodeScan uses a .env file for configuration. Follow these steps to set it up:
Copy the example environment file to create your own:
cp example.env .envEdit the
.envfile and update thePROJECT_DIRvariable to point to the path of the project you want to scan:PROJECT_DIR=/absolute/path/to/your/project/For example:
Linux/macOS:
PROJECT_DIR=/home/username/projects/my-python-project/Windows:
PROJECT_DIR=C:/Users/username/projects/my-python-project/
Adjust other settings as needed:
Neo4j connection details (username, password, ports)
Logging options
Alternative to Environment File
Instead of using the .env file, you can also specify the project directory directly when running the scanner:
python scanner.py --project-dir /path/to/your/projectArchitecture
1. AST Traversal
The
CodeAnalyzerclass subclassesast.NodeVisitor.Visits
ClassDefandFunctionDefnodes to extract class/function metadata.Visits
Callnodes to extract call relationships and argument information.
2. Node and Relationship Creation
File nodes: Labeled
:File, with additional labels for specific file types::TestFilefor test files:ExampleFilefor example filesProperties include
path,type,is_test,is_example
Class nodes: Labeled
:Class, properties includename,file,line,end_line.Function nodes: Labeled
:Function, with additional labels::MainFunctionfor functions namedmain:ClassFunctionfor methods inside classes:ReferenceFunctionfor called-but-undefined functionsProperties:
name,file,line,end_line,is_reference,length
Constant nodes: Labeled
:Constant, properties includename,value,type,file,line,end_line,scopeRelationships:
CONTAINS: FromFiletoClass,Function, orConstant(file contents)CONTAINS: FromClasstoFunction(class membership)CALLS: From caller to callee, with propertiesline(call site),args(argument names/values)
3. Reference Node Handling
If a function is called but not defined in the scanned codebase, a
:ReferenceFunctionnode is created.When the function is later defined, all
CALLSrelationships to the reference node are redirected to the real function node.
4. Test Coverage Detection
Test files, functions, and classes are automatically identified based on configurable patterns
Test components receive appropriate labels (
:Test,:TestFunction,:TestClass)TESTSrelationships are created between test functions and production code through:Naming patterns: A test function named
test_foolikely tests the functionfooImport analysis: Test functions often import the modules/functions they test
Call analysis: Functions called by test functions are likely being tested
All detection patterns are configurable for different project structures and frameworks
5. Configuration
All connection and project settings are loaded from a
.envfile usingpython-dotenv.Example variables:
NEO4J_USER,NEO4J_PASSWORD,NEO4J_HOST,NEO4J_PORT_BOLT,PROJECT_DIR
The ignore list for directories is hardcoded but can be extended.
6. Usage
Prerequisites
Python 3.8+
Neo4j 5.x (Docker recommended)
Install dependencies:
pip install -r requirements.txt
Running Neo4j
Start Neo4j using Docker Compose:
docker-compose up -dNeo4j Browser will be available at
http://localhost:7400(or as configured).
Running the Scanner
Ensure your
.envfile is configured (see "Setting Up Your Environment" section).Run the scanner:
python scanner.pyThe script will:
Clear the Neo4j database
Traverse the project directory
Populate the graph with classes, functions, and call relationships
Output Control
Control the verbosity of scanner output:
# Minimal output (only errors)
python scanner.py --quiet
# Detailed output showing all elements found
python scanner.py --verboseVisualizing in Neo4j Browser
Use the provided
.grassfile for custom node/relationship coloring.Example queries:
MATCH (n) RETURN n(all nodes)MATCH (n)-[r]->(m) RETURN n, r, m(all relationships)MATCH (f:Function) WHERE f.line > 100 RETURN f(functions by line)MATCH ()-[r:CALLS {line: 42}]->() RETURN r(calls at a specific line)MATCH (f:Function) RETURN f.name, f.file, f.length ORDER BY f.length DESC LIMIT 10(find longest functions)MATCH (f:File)-[:CONTAINS]->(n) RETURN f.path, count(n) ORDER BY count(n) DESC LIMIT 10(files with most elements)MATCH (f:File)-[:CONTAINS]->(n) WHERE n:Class OR n:Function RETURN f.path, labels(n), count(n) GROUP BY f.path, labels(n) ORDER BY f.path, labels(n)(count of elements by type in each file)
Advanced Details
Argument Extraction: The scanner extracts argument names and constant values from function calls and stores them as a string in the
argsproperty ofCALLSrelationships.Dunder Method Skipping: Special methods (e.g.,
__init__,__str__) are ignored for clarity.Built-in and stdlib call filtering: Calls to Python built-ins and standard library modules are not included in the graph.
Error Handling: Syntax errors and undecodable files are reported and skipped.
Extensibility: The ignore list, node/relationship properties, and labeling logic can be easily extended for more advanced use cases.
MCP Server and Cursor Integration
CodeScan includes an MCP (Model Context Protocol) server for advanced code graph querying and integration with tools like Cursor IDE.
MCP Server (codescan_mcp_server.py)
This server exposes the code graph stored in Neo4j via the MCP protocol, making it accessible to compatible clients. It provides tools for listing files, functions, classes, call relationships, and unresolved references.
Available Tools
CodeScan provides various tools for code analysis through the MCP server:
Basic Code Structure
list_files- List all files in the codebase with their typesfile_contents- List all classes, functions, and constants in a specific filelist_functions- List functions in a specific filelist_classes- List classes in a specific file
Call Graph Analysis
callees- Find functions called by a specific functioncallers- Find functions that call a specific functiontransitive_calls- Find paths between functions (whether one function eventually calls another)most_called_functions- List functions with the most callersmost_calling_functions- List functions that call the most other functions
Test Coverage Analysis
untested_functions- List functions without testsuntested_classes- List classes without teststest_coverage_ratio- Get overall test coverage statisticsfunctions_tested_by- List functions tested by a specific test filetests_for_function- List tests for a specific function
Miscellaneous Analysis
recursive_functions- List functions that call themselvesclasses_with_no_methods- List classes without any methodsclasses_with_most_methods- List classes with the most methodsfunction_call_arguments- List arguments used in calls to a specific functionrepetitive_constants- Find constants with identical values used in multiple placesrepetitive_constant_names- Find constants with the same name but potentially different values used in multiple places
Running the MCP Server
Use the provided shell script to launch the server (ensure your virtual environment is activated and Neo4j is running):
./run_mcp_stdio_server.shThis will start the MCP server using stdio transport, ready for integration with Cursor or other MCP clients.
Cursor IDE Integration
To use CodeScan's MCP server with Cursor IDE, add the following to your .cursor/mcp.json (adjust the path as needed):
{
"mcpServers": {
"codescan_neo4j": {
"command": "/path/to/codescan/run_mcp_stdio_server.sh",
"args": []
}
}
}After configuring, restart Cursor and open the MCP tools panel. You should see CodeScan's tools (e.g., graph_summary, list_files, list_functions, etc.) available for querying your codebase.
Troubleshooting
Ensure Neo4j is running and accessible with the credentials in your
.envfile.Check the server logs for errors if tools do not appear in Cursor.
The server must be started from the project root for relative paths to resolve correctly.
Relevant files:
codescan_mcp_server.py— MCP server implementationrun_mcp_stdio_server.sh— Shell script to launch the server
Docker
docker pull ghcr.io/cocodedk/codesacan:latest
docker run ghcr.io/cocodedk/codesacan:latestAuthor
Babak Bandpey — cocode.dk | LinkedIn | GitHub
License
Apache-2.0 | © 2026 Cocode | Created by Babak Bandpey
This server cannot be installed
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/cocodedk/codescan'
If you have feedback or need assistance with the MCP directory API, please join our Discord server