A structured knowledge extraction system for Python codebases, built on the Model Context Protocol (MCP). Pathweave parses source code into queryable entities, stores them as JSON or in PostgreSQL with pgvector embeddings, and exposes everything through MCP servers that AI agents can use for intelligent code analysis.
Pathweave transforms Python projects into structured, searchable knowledge through a multi-stage pipeline:
- Parse β Tree-sitter AST analysis extracts files, functions, classes, methods, and TODO/FIXME issues
- Store β Entities saved as JSON with search indices; Git commits and GitHub metadata integrated
- Migrate (optional) β Entities migrated to PostgreSQL with 384-dimensional vector embeddings for semantic search
- Serve β Two MCP servers expose tools to AI agents: one JSON-based (19 tools), one database-backed (6 tools with semantic search)
Requirements: Python 3.10+
pip install -r requirements.txtOptional environment variables (.env file):
GITHUB_TOKEN=your_github_token # For GitHub metadata extraction
MISTRAL_API_KEY=your_mistral_key # For CrewAI agent tests
Python API:
from src.generator import generate_resources
summary = generate_resources(
project_path="path/to/project",
output_dir="output",
include_git=True,
max_commits=50,
include_github=True,
github_repo="owner/repo"
)
print(summary['statistics'])
# {'total_entities': 383, 'files': 56, 'functions': 114, ...}CLI:
python -m src.cli generate ./myproject -o output --git --github owner/repoFull pipeline (generate + migrate to database):
python generate_and_migrate.py ./myproject --github owner/repopython test/test_manual.py src # Core pipeline validation (no API keys needed)
python test/test_crewai.py # CrewAI agent test (requires MISTRAL_API_KEY)
python check_dependencies.py # Verify all dependencies are installedSource Code β Parser (tree-sitter) β Entities (JSON) β Query Engine
β
PGVector Migration β PostgreSQL + Embeddings
β
MCP Servers β AI Agents (CrewAI)
| Module | Purpose |
|---|---|
parser.py |
Tree-sitter AST parsing. Extracts files, functions, classes, methods, issues from Python source |
storage.py |
JSON persistence, Git commit extraction (GitPython), GitHub API integration |
generator.py |
Pipeline orchestration β runs parser β storage β indices β overview |
generator_with_db.py |
Extends generator with automatic PostgreSQL migration |
query.py |
In-memory query engine over JSON indices (search, filter, traverse) |
cli.py |
Click-based CLI interface for generation |
migrate_to_pgvector.py |
Migrates JSON entities to PostgreSQL with all-MiniLM-L6-v2 vector embeddings (384-dim) |
All entities inherit from BaseEntity with a unique ID format: type:filepath::name
| Entity | Source | Key Data |
|---|---|---|
FileEntity |
Parser | imports, exports, line count |
FunctionEntity |
Parser | parameters, return type, docstring, complexity |
ClassEntity |
Parser | base classes, methods, attributes, decorators |
MethodEntity |
Parser | signature, parent class, decorators |
IssueEntity |
Parser | TODO/FIXME/HACK comments extracted from code |
CommitEntity |
Git | author, message, SHA, files changed, date |
GitHubRepoEntity |
GitHub API | stars, forks, language, topics |
GitHubIssueEntity |
GitHub API | title, state, labels, body |
GitHubContributorEntity |
GitHub API | commits, additions, deletions |
| Server | Tools | Backend | Use Case |
|---|---|---|---|
MCP_Server_V2.py |
19 | JSON files | Full-featured: generation, search, commits, GitHub |
MCP_Server_Database.py |
6 | PostgreSQL + pgvector | Semantic search, vector similarity, SQL queries |
local_mcp_server.py |
β | Legacy format | Original prototype (pre-v2) |
MCP_Server_V2 tools include: generate_resources, find_entity, search_entities, get_entity_details, traverse_relations, multi_hop_query, get_statistics, search_functions, search_classes, get_class_methods, search_commits, get_commit_details, get_commit_statistics, list_commit_authors, get_github_repository, search_github_issues, get_github_issue_details, list_github_contributors, get_github_contributor_details
MCP_Server_Database tools: semantic_search, find_entity_by_id, search_by_name, get_relationships, find_commits_by_author, get_entity_statistics
After running generate_resources():
output/
βββ overview.json # Project statistics and metadata
βββ entities/ # Entity JSON files (MD5-hashed filenames)
β βββ file/ # Source file entities
β βββ function/ # Standalone functions
β βββ class/ # Classes
β βββ method/ # Class methods
β βββ issue/ # TODO/FIXME issues from comments
β βββ commit/ # Git commits
β βββ github_repo/ # Repository metadata
β βββ github_issue/ # GitHub issues
β βββ github_contributor/ # Contributors
βββ indices/ # Search indices for fast lookups
βββ functions_by_name.json
βββ classes_by_name.json
βββ files_by_path.json
βββ commits_by_author.json
βββ commits_by_sha.json
βββ github_issues_by_number.json
βββ github_contributors_by_login.json
βββ github_repo_info.json
# Start PostgreSQL with pgvector (Docker)
docker run --name vector_database \
-e POSTGRES_PASSWORD=GeneralPass1987 \
-e POSTGRES_DB=vectors \
-p 5432:5432 -d pgvector/pgvector:pg16
# Install Python packages
pip install psycopg2-binary sentence-transformers torch# Generate + migrate in one step
python generate_and_migrate.py ./myproject
# Or programmatically
from src.generator_with_db import generate_resources_with_db
generate_resources_with_db("./myproject", auto_migrate=True)PostgreSQL "vectors"
βββ entities # All entity data + embeddings
β βββ entity_id (PK) # e.g. "function:src/auth.py::validate"
β βββ entity_type # function, class, method, commit, etc.
β βββ name, defined_in
β βββ embedding vector(384) # all-MiniLM-L6-v2 embeddings
β βββ type_specific_data # JSONB (signature, params, docstring...)
β βββ metadata # JSONB
βββ entity_relationships # Relationship graph (calls, inherits, contains)
β βββ source_entity_id (FK)
β βββ target_entity_id (FK)
β βββ relationship_type
βββ projects # Project metadata + statistics
SELECT name, 1 - (embedding <=> query_vector) as similarity
FROM entities
WHERE entity_type = 'function'
ORDER BY embedding <=> query_vector
LIMIT 5;Note: Only relationships between entities within the analyzed project are migrated. External library references (e.g., inheriting from
BaseTool) are preserved in JSON but excluded from the database due to foreign key constraints.
| Test | What it validates | Requirements |
|---|---|---|
test_manual.py |
Full pipeline: generate β query β search β statistics | None |
test_crewai.py |
CrewAI agent querying entities via @tool functions |
MISTRAL_API_KEY |
test_crewai_rich.py |
CrewAI agent with 6 PGVector database tools (guided analysis of Rich library) | MISTRAL_API_KEY, PostgreSQL |
test_crewai_rich_autonomous.py |
Autonomous agent analysis β no guidance, open-ended task | MISTRAL_API_KEY, PostgreSQL |
test_crewai_rich_baseline.py |
Control experiment β same task with file-system tools instead of Pathweave | MISTRAL_API_KEY |
test_vector_search.py |
Standalone vector similarity search via pgvector | PostgreSQL |
Crew_mcp_test.py |
CrewAI + MCP server integration via stdio transport | MISTRAL_API_KEY |
| Benchmark | Purpose |
|---|---|
benchmark_rich.py |
Full pipeline benchmark on Textualize/rich: clone β parse β migrate β measure |
benchmark_rich_part2.py |
Supplementary: database statistics collection + semantic search benchmark |
from crewai import Agent, Task, Crew, LLM
from crewai.mcp import MCPServerStdio
agent = Agent(
role="Code Analyst",
goal="Analyze Python codebase",
llm=LLM(model="mistral/mistral-large-latest", api_key=api_key),
mcps=[MCPServerStdio(command="python", args=["Python/MCP_Server_V2.py"])]
)
task = Task(
description="Find all functions that parse Python code and explain their relationships",
agent=agent
)
crew = Crew(agents=[agent], tasks=[task])
result = crew.kickoff()Pathweave/
βββ src/ # Core library
β βββ __init__.py
β βββ parser.py # Tree-sitter AST parser
β βββ storage.py # JSON persistence + Git/GitHub integration
β βββ generator.py # Pipeline orchestrator
β βββ generator_with_db.py # Generator + PostgreSQL migration
β βββ query.py # Query engine (JSON indices)
β βββ cli.py # Click CLI
β βββ migrate_to_pgvector.py # PGVector migration + embeddings
β βββ entities/ # Entity dataclasses
β βββ base.py # BaseEntity
β βββ file.py, function.py, class_.py, method.py
β βββ issue.py, commit.py
β βββ github_repo.py, github_issue.py, github_contributor.py
β
βββ Python/ # MCP servers
β βββ MCP_Server_V2.py # JSON-based server (19 tools)
β βββ MCP_Server_Database.py # PGVector server (6 tools, semantic search)
β βββ local_mcp_server.py # Legacy server (prototype)
β
βββ test/ # Test suite
β βββ test_manual.py # Core pipeline validation
β βββ test_crewai.py # CrewAI + JSON tools
β βββ test_crewai_rich.py # CrewAI + PGVector tools (guided)
β βββ test_crewai_rich_autonomous.py # Autonomous agent experiment
β βββ test_crewai_rich_baseline.py # Baseline comparison (no Pathweave)
β βββ test_vector_search.py # Semantic search demo
β βββ Crew_mcp_test.py # MCP stdio integration
β
βββ benchmark/ # Performance benchmarks
β βββ benchmark_rich.py # Full pipeline benchmark (Rich library)
β βββ benchmark_rich_part2.py # DB stats + search benchmark
β
βββ output/ # Generated resources (gitignored)
βββ generate_and_migrate.py # CLI: generate + migrate in one step
βββ check_dependencies.py # Dependency verification
βββ requirements.txt
βββ .env # API keys (gitignored)
Core (required):
tree-sitter+tree-sitter-pythonβ AST parsingclickβ CLI interface
Optional integrations:
GitPythonβ Local Git commit extractionrequests+python-dotenvβ GitHub API integrationmcpβ MCP server protocolcrewaiβ AI agent framework
PGVector database (optional):
psycopg2-binaryβ PostgreSQL adaptersentence-transformersβ Vector embeddings (all-MiniLM-L6-v2)torchβ Required by sentence-transformers
See requirements.txt for pinned versions.
MIT License