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

Uploaded Python 3

File details

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

File metadata

  • Download URL: code_knowledge_graph_tool-0.1.13.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.13.tar.gz
Algorithm Hash digest
SHA256 bfd492dabb110b6dde36db9256eb8cab7a11a6722a9bad45f1b3133361becc58
MD5 a5428709b563afc92ad6dda713b70af1
BLAKE2b-256 a6d586e82cd3c4fec012cacccc0a4f0d161b35b9a307ffde1a3a0e5d28830366

See more details on using hashes here.

File details

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

File metadata

  • Download URL: code_knowledge_graph_tool-0.1.13-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.13-py3-none-any.whl
Algorithm Hash digest
SHA256 a902c4d7667bb63516c44144725d2e0cad8c80183941d2ee2fb83d7260698ee9
MD5 66fab3b70687ff478f6de1585e4f349e
BLAKE2b-256 86888db4c0ea287a131106797ea18ea0522e9e35a0c0a16c51569559c8531e55

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