A specialized MCP server for recursive code analysis and dependency mapping. Designed to help understand complex codebases by building structured knowledge trees of functions, modules, constants, and their interdependencies.
This server was created to systematically analyze and understand complex code like the hr()
function in fp.umd.original.js
. It provides tools to:
- Build incremental understanding of code elements
- Track dependencies between functions, modules, and constants
- Identify missing dependencies that need further analysis
- Visualize code structure as dependency trees
- Import existing analysis work
# Install the server in Claude Desktop (creates knowledge-tree in current directory)
mcp install code_knowledge_server.py --name "Code Knowledge Tree"
# Install with custom base directory (creates knowledge-tree inside the specified directory)
mcp install code_knowledge_server.py --name "Code Knowledge Tree" -- --working-dir ./my_project_analysis
# Test with MCP Inspector (creates knowledge-tree in current directory)
mcp dev code_knowledge_server.py
# Test with custom base directory
mcp dev code_knowledge_server.py -- --working-dir ./my_project_analysis
# Test with absolute path
mcp dev code_knowledge_server.py -- --working-dir /absolute/path/to/base
The server creates a knowledge-tree
folder inside your specified working directory:
- Default:
./knowledge-tree/
(in current directory) - Custom relative:
./my_analysis/knowledge-tree/
- Custom absolute:
/home/user/projects/my_analysis/knowledge-tree/
This allows you to:
- Keep knowledge trees organized within project directories
- Share knowledge trees across team members using consistent paths
- Organize multiple analysis projects in separate base directories
- Use centralized storage locations while maintaining the knowledge-tree structure
-
add_code_element
- Add functions, modules, constants, or variables# Example: Add the main hr() function add_code_element( element_id="hr", element_type="function", code="function hr(t, e) { ... }", description="Main hybrid cryptography function", source_file="fp.umd.original.js", line_range="33490-33511" )
-
add_dependency
- Link dependencies between elements# Link hr() function to its dependency ge() add_dependency("hr", "ge")
-
get_element
- Retrieve detailed information about any elementget_element("hr") # Returns code, dependencies, metadata
-
find_missing_dependencies
- Identify unresolved dependenciesfind_missing_dependencies("hr") # Shows what needs to be analyzed next
-
get_tree_view
- Generate visual dependency treesget_tree_view("hr", max_depth=3) # ASCII tree visualization
-
list_all_elements
- Overview of all elements in the knowledge tree -
update_code_element
- Modify existing elements -
remove_element
- Remove elements and clean up references -
import_from_analysis_file
- Import from existing analysis files -
get_knowledge_tree_stats
- Health metrics and statistics -
get_working_directory_info
- Show current working directory configuration
-
Start with the main function:
add_code_element("hr", "function", "function hr(t, e) {...}", "Main crypto function")
-
Add known dependencies:
add_dependency("hr", "ge") # RSA key selector add_dependency("hr", "ze") # AES encryption add_dependency("hr", "Fe") # Crypto module
-
Find what's missing:
find_missing_dependencies("hr") # Returns: ["ge", "ze", "Fe"] - need to analyze these
-
Add the missing pieces:
add_code_element("ge", "function", "function ge() {...}", "RSA key selector") add_code_element("ze", "function", "function ze(t, e) {...}", "AES encryption") add_code_element("Fe", "module", "r(5634)", "Crypto module")
-
Visualize progress:
get_tree_view("hr")
Output:
hr [function] - Main crypto function βββ ge [function] - RSA key selector βββ ze [function] - AES encryption βββ Fe [module] - Crypto module
-
Continue recursively until all dependencies are understood
The server stores knowledge trees in a simple JSON-based format inside a knowledge-tree
subfolder:
<working-dir>/ # Configurable via --working-dir parameter
βββ knowledge-tree/ # Always named 'knowledge-tree'
βββ metadata.json # Global metadata
βββ elements/ # Individual element files
βββ hr.json # Main function
βββ ge.json # Dependencies
βββ ze.json
βββ Fe.json
Directory Examples:
- Default:
./knowledge-tree/
- Custom:
./my_project_analysis/knowledge-tree/
- Absolute:
/home/user/crypto_analysis/knowledge-tree/
Each element file contains:
{
"id": "hr",
"type": "function",
"code": "function hr(t, e) { ... }",
"description": "Main hybrid cryptography function",
"dependencies": ["ge", "ze", "Fe"],
"dependents": [],
"source_file": "fp.umd.original.js",
"line_range": "33490-33511",
"created_at": "2025-07-02T16:25:00Z",
"updated_at": "2025-07-02T16:25:00Z"
}
- β Complex JavaScript libraries with obfuscated code
- β Functions with many interdependent calls
- β Module systems with r(nnnn) style imports
- β Cryptographic implementations
- β Any codebase requiring systematic understanding
hr [function] - Main hybrid cryptography function
βββ ge [function] - RSA key selector
β βββ fe [function] - Environment detection
β βββ be [constant] - Production RSA key
β βββ me [constant] - Pre-prod RSA key
β βββ ve [constant] - Mobile RSA key
βββ ze [function] - AES encryption wrapper
β βββ Fe.O6 [function] - Random bytes generator
β βββ Fe.CW [function] - AES cipher creation
β βββ qe [constant] - AES algorithm constant
βββ Fe [module] - Crypto module (r5634)
β βββ Fe.O6 [function] - Random bytes
β βββ Fe.r0 [function] - RSA encryption
β βββ Fe._G [constant] - Crypto constants
βββ Ue [module] - Buffer module (r8764)
βββ Ue.from [function] - Buffer constructor
βββ buffer methods [function] - toString, slice, etc.
- Incremental Understanding: Build knowledge piece by piece
- Dependency Tracking: See exactly what depends on what
- Missing Element ID: Know what to analyze next
- Visual Structure: Understand code architecture at a glance
- Import Existing Work: Leverage previous analysis
- Tool-Only Design: Perfect compatibility with Claude Desktop
This server can import your existing analysis files from the analysis/
directory:
import_from_analysis_file("analysis/01_hr_main.js")
This automatically extracts functions and dependencies from your previous work.
- Install the server in Claude Desktop
- Start with your main function of interest
- Add dependencies as you discover them
- Use
find_missing_dependencies
to guide your analysis - Visualize progress with
get_tree_view
- Build complete understanding recursively
The server turns code analysis from a linear process into a systematic, visual, and manageable knowledge-building experience.