Skip to main content

Code Structure with Graph — graph-powered code intelligence

Project description

CSG - Code Structure with Graph

CSG is a local code intelligence tool for building a graph index of a source repository and exposing that index to AI coding agents through MCP.

It parses source code with deterministic AST tooling, stores symbols and relationships in an embedded Kuzu graph database, and provides MCP tools for code exploration, impact analysis, change review, and graph-aware navigation.

Install

uv tool install --python 3.12 --index-url https://pypi.org/simple --refresh code-knowledge-graph-tool

Upgrade later with:

uv tool upgrade code-knowledge-graph-tool

One-Time OpenAI Setup

Semantic embeddings use OpenAI embeddings. Configure your key once:

csg config set openai-api-key sk-your-openai-api-key

This key is stored in CSG's local user config and is reused by:

  • csg analyze --embeddings
  • csg watch
  • csg mcp launched by Claude Code, Codex, or VS Code MCP clients

You can also use OPENAI_API_KEY or CSG_OPENAI_API_KEY as environment overrides. If no key is configured, CSG still builds the graph and skips embeddings with a clear reminder.

Basic Workflow

Run these commands from the repository you want to index:

cd /path/to/your/repo
csg analyze . --embeddings
csg setup .

csg analyze builds the local graph index. csg setup installs repo-local agent guidance files and registers the CSG MCP server for supported agent CLIs.

To keep indexed repositories fresh while you work:

csg watch

To open the local web UI:

cd /path/to/your/repo
csg web --open

The browser UI runs at http://127.0.0.1:8080 by default and can upload, analyze, and visualize repositories locally. If the directory where you launch csg web has already been analyzed, the UI loads that graph automatically.

MCP Usage

After setup, AI agents can use CSG MCP tools automatically:

  • csg_list_repos: discover indexed repositories
  • csg_explore: search and explore graph layers
  • csg_context: inspect a symbol with callers, callees, and source context
  • csg_impact: check blast radius before edits
  • csg_detect_changes: map git changes to affected symbols and flows
  • csg_rename: preview graph-aware symbol renames
  • csg_analyze: index a repository from the MCP client

Manual MCP registration is also possible:

claude mcp add --transport stdio --scope user csg -- csg mcp
codex mcp add csg -- csg mcp

MCP clients that use JSON configuration can launch:

{
  "mcpServers": {
    "csg": {
      "command": "csg",
      "args": ["mcp"]
    }
  }
}

Common Commands

csg analyze .                    # Build graph index
csg analyze . --force            # Rebuild index
csg analyze . --embeddings       # Build graph plus OpenAI embeddings
csg setup .                      # Install agent files and register MCP
csg setup-agents .               # Install repo-local agent files only
csg status                       # Show index status for current repo
csg list                         # List indexed repositories
csg web --open                   # Start the local browser UI
csg watch                        # Watch indexed repos for changes
csg logs                         # Show MCP logs
csg clean                        # Delete current repo index

Data Storage

For normal local repositories, CSG stores graph data inside the target checkout:

<repo>/.csg/
  meta.json
  lbug/
  cache/

A small global registry is also maintained so MCP clients can discover indexed repositories.

Notes

  • Indexing does not require an LLM.
  • Embeddings require an OpenAI key.
  • No local PyTorch, CUDA, or Hugging Face embedding model is installed by the package.
  • If embeddings are skipped, graph navigation, context, impact analysis, and BM25 search still work.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

code_knowledge_graph_tool-0.1.15.tar.gz (1.7 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

code_knowledge_graph_tool-0.1.15-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

Details for the file code_knowledge_graph_tool-0.1.15.tar.gz.

File metadata

  • Download URL: code_knowledge_graph_tool-0.1.15.tar.gz
  • Upload date:
  • Size: 1.7 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for code_knowledge_graph_tool-0.1.15.tar.gz
Algorithm Hash digest
SHA256 c22ed7d33510419f3ba0699583c58675401bec39a2bbcd8489c4c79c6af848b1
MD5 78bde947a0a0b285d584fa440568bd75
BLAKE2b-256 0f627c7968f8c1d46b1dc0fe7141bdc913f902465d17e97ef794d13cf6427e79

See more details on using hashes here.

File details

Details for the file code_knowledge_graph_tool-0.1.15-py3-none-any.whl.

File metadata

  • Download URL: code_knowledge_graph_tool-0.1.15-py3-none-any.whl
  • Upload date:
  • Size: 1.1 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for code_knowledge_graph_tool-0.1.15-py3-none-any.whl
Algorithm Hash digest
SHA256 e0545fc6fabf30dd45686ce314497b0f7eb55e7920145911fd3ee127ea57a689
MD5 ba5a6fd2d3e224e864e880e21a6faad7
BLAKE2b-256 5faa93c4eff10bdcda1ac6d201ae6d0cfdd03bb1213f641fcbf43d81b5f3f571

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page