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

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 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.11.tar.gz (1.4 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.11-py3-none-any.whl (1.1 MB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: code_knowledge_graph_tool-0.1.11.tar.gz
  • Upload date:
  • Size: 1.4 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.11.tar.gz
Algorithm Hash digest
SHA256 4d57c3742b3a5de341df522b2e7a23c93eb052758ded157cb04d6aaa6f873d9c
MD5 a0ef033863697c589ea0aacaa3bdd20c
BLAKE2b-256 5100352923c82bf0afba59b951e96c397a3c06ba41dd0f61c14a6feac4c37b7c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: code_knowledge_graph_tool-0.1.11-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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 e5ad6ff9e7ad85549ff1fe83a6a2ec6582c7f3379cff73ac5159af86e3027703
MD5 965652fea284ba2713d492d7ac8cd70d
BLAKE2b-256 9a3525844788269eca367c6cc9bc8c4d1d058f93b26d348b30c37bff15577499

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