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:

csg web --open

The browser UI runs at http://127.0.0.1:8080 by default and can upload, analyze, and visualize repositories locally.

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.14.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.14-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: code_knowledge_graph_tool-0.1.14.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.14.tar.gz
Algorithm Hash digest
SHA256 63db5d610b2f0cf1e1e024dc55cdd9590df42323f31424bd4931bb75c94654bb
MD5 03e087fa5d5e74b2469f1e31eabe371b
BLAKE2b-256 8ea0a930df664bb5e235f87a33925d1a5168aec866636c9d1418356d6d21e104

See more details on using hashes here.

File details

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

File metadata

  • Download URL: code_knowledge_graph_tool-0.1.14-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.14-py3-none-any.whl
Algorithm Hash digest
SHA256 ac97e7ab549747a1faf949147cdf116e25054cd7f5fe7aad8dcde1ba086d3ce5
MD5 0bd2621d9b7801411dd5c5d7544a56e3
BLAKE2b-256 18ae9c76542bdf538d935574eb667a6c980b3294d47e6fdd0a28346509dd36b2

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