Cssgraph

io.github.mack-peng由 GitHub 账号 mack-peng 发布v0.6.3更新于 Oct 24, 2026

CSS intelligence for AI coding agents — surgical style context, fewer tool calls. 100% local.

已验证STDIO仅桌面知识与记忆开发者工具

概览

AI 生成的概览

为 AI 编程助手提供本地 CSS 知识图谱,一次调用即可查询类定义、层叠覆盖与受影响的文件。

可以做什么
cssgraph 将项目的样式文件(CSS、SCSS、Less、Sass、PostCSS、CSS Modules、Tailwind)以及 JSX/TSX 和视图模板索引到本地 SQLite 图谱中,包含 className、属性、变量、at-rule 以及 contains、nests、overrides、imports、references 等边。它的 13 个 MCP 工具可以回答类在哪里定义、哪些规则层叠覆盖它、哪些组件引用它、修改会影响什么、哪些类未被使用,以及层叠路径如何。文件监听会在代码变化时保持索引同步。
适用场景
适合助手在真实项目中处理前端样式、否则需要逐个 grep 和读取文件来还原层叠的场景。可用于重构、修改类之前的影響评估,以及查找未使用或被覆盖的选择器。它只做静态分析;运行时渲染问题需要另外的浏览器工具。
运行要求
通过 stdio 启动的本地进程,从 npm 包 cssgraph 安装。需要 Node.js >= 22.5.0(用于 node:sqlite)以及一个待索引的项目,先在项目中运行 cssgraph init。未声明账号、API 密钥或环境变量。仅支持桌面端,不提供网页可执行版本。
安装前请注意
它会读取项目源文件,并在项目的 .cssgraph/ 下写入本地索引,同时监听文件变化。README 的安装方式要求代理从某个网址获取安装指南并执行命令,且 cssgraph mcp-install 会改写 MCP 服务器配置并为检测到的代理安装技能文件,请先检查这些改动。不涉及凭据或付款。

安装

在 SourceWeft 中

  1. 打开 控制台中的 Cssgraph,将其添加到工作区。
  2. 为需要使用其工具的对话启用该服务。

Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。

其他 MCP 客户端

参照 仓库 中的启动说明。

README

cssgraph

CSS Intelligence for AI Coding Agents

Surgical style context · fewer tool calls · faster answers · 100% local

[License: MIT] [Node.js] [npm version] [npm downloads] [GitHub stars]

[macOS] [Linux] [Windows]


Why cssgraph?

When an AI agent needs to understand CSS — where is .btn-primary defined, what properties does it have, which selectors cascade over it, which JSX components reference it — it discovers style the slow way: grep, glob, and Read, one file at a time, reconstructing the cascade by hand.

cssgraph hands the agent the exact style context it needs in one call. It's a pre-built knowledge graph of every className, CSS property, variable, and at-rule in your stylesheets — so instead of crawling files, the agent asks one question and gets back the properties, overrides, specificity, callers, and file-level impact in full.


Installation

For Humans

Copy and paste this prompt to your LLM agent (Claude Code, Cursor, Codex, etc.):

text
Install and configure cssgraph by following the instructions here:https://raw.githubusercontent.com/mack-peng/cssgraph/main/docs/guide/installation.md

Or read the Installation Guide, but seriously, let an agent do it. Humans fat-finger configs.

For LLM Agents

Fetch the installation guide and follow it:

bash
curl -s https://raw.githubusercontent.com/mack-peng/cssgraph/main/docs/guide/installation.md

Quick Start

1. Initialize

bash
npm i -g cssgraphcd your-projectcssgraph init --workers 8

Indexes all style files (CSS, SCSS, Less, Sass), JSX/TSX className references, CSS-in-JS, CSS Modules, and view templates (ERB/Haml/HTML) — enabling every MCP tool.

Pass --workers <n> to control parallel parse threads (default: cpu cores - 1).

Requires Node.js >= 22.5.0 (for node:sqlite).

2. Wire up your agent

bash
cssgraph mcp-install

Auto-detects and configures opencode, Claude Code, Cursor, Codex CLI, Gemini CLI, Hermes Agent, Antigravity IDE, and Kiro. Writes MCP server config, instructions block, and an Agent Skill (SKILL.md + references/pitfalls.md) that teaches agents when to use each of the 13 cssgraph tools, how to chain them into workflows, and what pitfalls to avoid.

Or add to any MCP agent manually:

json
{  "mcpServers": {    "cssgraph": {      "type": "stdio",      "command": "cssgraph",      "args": ["serve", "--mcp"]    }  }}

3. No more syncing

Auto-sync is enabled by default. The MCP server watches your project and updates the graph on every file change — while your agent edits code, or you add/modify/delete CSS files. The index is never stale.


How It Works

┌───────────────────────────────────────────────────────────┐│                      AI Agent                              ││                                                           ││  "What code files use .btn-primary?"                      ││      calls cssgraph_rule — one tool call                  ││                             │                             │└─────────────────────────────┬─────────────────────────────┘                              │                              ▼┌───────────────────────────────────────────────────────────┐│                  cssgraph MCP Server                       ││                                                           ││ rule · O(1) exact selector lookup · loose/strict impact   ││ explore · properties + overrides + specificity + callers  ││                             │                             ││                             ▼                             ││               SQLite knowledge graph                      ││     classNames · properties · variables · at-rules        ││            edges · FTS5 full-text search                  │└───────────────────────────────────────────────────────────┘
  1. Extraction — PostCSS parses CSS/SCSS/Less/Sass into ASTs. CSS-in-JS (styled.div), JSX className references, and template class attributes extracted from .jsx/.tsx/.erb/.haml files.
  2. Storage — Everything goes into a local SQLite database (.cssgraph/cssgraph.db) with FTS5 full-text search. WAL-mode + batch commits for write performance. FTS triggers and unique indexes are deferred during bulk load for speed.
  3. Graph — Edges connect related nodes: contains (selector→property), nests (parent→child selector), overrides (higher specificity selector overrides lower), imports (file→imported file), references (JSX/view file→className, property→CSS variable).
  4. Git-first scanning — git ls-files for instant file discovery. Falls back to filesystem walk on non-git projects.
  5. Parallel parsing — Files dispatched in batches to worker threads via Promise.all. Parses complete concurrently; results flushed in file order for correctness.
  6. Auto-Sync — Native OS file events, debounced, incrementally synced.

CLI Reference

bash
cssgraph init [path] [-w, --workers <n>]  # Initialize + build graphcssgraph index [path] [-w, --workers <n>]  # Rebuild from scratchcssgraph query <className>                 # Search for className selectorscssgraph explore <query...>                # Full style context for a classNamecssgraph details <selector>                # O(1) exact selector → file:line lookupcssgraph rule <selector> [--strict]        # Selector impact: exact + loose/strict filescssgraph impact-selector <selector>       # Code files affected by a selectorcssgraph impact <className>                # Blast radius of changing a classNamecssgraph unused                            # Find unreferenced class selectorscssgraph cascade <className>               # Visualize cascade pathcssgraph diagnose <className> [chain...]   # Static anchor diagnosis (height/scroll)cssgraph property <query...>               # Search by CSS property valuecssgraph files [path]                      # Project style file treecssgraph status [path]                     # Index statisticscssgraph sync [path]                       # Incremental updatecssgraph serve --mcp                       # Start MCP servercssgraph mcp-install                       # Auto-wire to your AI agent (alias: install)cssgraph skill-install                     # Install/update SKILL.md only (no MCP config changes)cssgraph skill-uninstall                   # Remove SKILL.md only (no MCP config changes)cssgraph mcp-uninstall                     # Remove from your AI agent (alias: uninstall)cssgraph version                           # Print installed version

JSX and View File Scanning (default)

cssgraph always scans:

  • JSX/TSX/JS/TS/ES6 — className references, CSS-in-JS, CSS Modules
  • View templates — .erb, .haml, .html files for class="..." attributes and Haml .classname shorthand

This enables cssgraph_impact, cssgraph_callers, and cssgraph_rule to track both component files AND template files that reference each className.

ProjectTotal filesFirst indexNodesEdges
Small~50~15s~16K~50K
Production monorepo~11K~3-5m~780K~22M

MCP Tools

ToolPurpose
cssgraph_explorePRIMARY: Full style context for a className — properties, overrides, specificity, callers
cssgraph_searchSearch for className selectors by name
cssgraph_callersFind JSX components referencing a className
cssgraph_impactBlast radius of changing a className
cssgraph_ruleBlast radius of a full CSS selector (exact match + loose/strict file impact)
cssgraph_impact_selectorFind code files (JS/TS/JSX/TSX) affected by a CSS selector
cssgraph_detailsO(1) exact selector lookup (no edges, lightweight)
cssgraph_unusedFind class selectors with no incoming references
cssgraph_cascadeVisualize the cascade path for a className
cssgraph_diagnoseStatic anchor diagnosis for scroll/height issues — classifies height declarations as DEFINITE / INDEFINITE / UNVERIFIABLE along the ancestor chain
cssgraph_propertySearch selectors by CSS property value
cssgraph_filesIndexed style file tree
cssgraph_statusIndex health check

Complementary Tool: cssprobe-cli

cssgraph is a static analysis tool — it reads your source code and answers where a class is defined, what cascades over it, and what a change would affect. For runtime questions — what a page actually renders in a browser (overflow, scroll chains, computed height chains, containing block hijacks) — use cssprobe-cli, which opens a real browser and reads computed styles plus DOM metrics. The two tools complement each other:

cssgraph (static)cssprobe-cli (runtime)
Analyzessource code (CSS/SCSS/Less + JSX/TSX + templates)live browser (computed styles + DOM)
Answerswhere a class is defined, cascade, impact, unused CSSactual rendered layout, overflow, scroll, height chains
Whenbefore/without a browserafter static analysis, to verify at runtime
Usagecssgraph init + explore/rule/impactopen + inspect/layout/findings

Recommended workflow for a style problem — go static first, then verify at runtime:

bash
# 1. Static: find the definitions, cascade, and blast radius (cssgraph)cssgraph explore .btn-primarycssgraph cascade .btn-primary
# 2. Runtime: confirm what actually renders (cssprobe-cli)npm i -g cssprobe-clicssprobe-cli open https://example.comcssprobe-cli inspect .btn-primarycssprobe-cli findings .btn-primary

Install: npm install -g cssprobe-cli (requires Node.js >= 22.5.0). See npm / GitHub.


Supported Languages

LanguageExtensionExtraction
CSS.cssPostCSS standard
SCSS.scsspostcss-scss plugin
Less.lesspostcss-less plugin
Sass (indented).sassCompile → PostCSS
PostCSS custom.pcssPostCSS standard
JSX / TSX.jsx .tsxclassName + CSS-in-JS
JavaScript / TypeScript.js .ts .es6className + CSS Modules
ERB (Rails).erbclass="..." extraction
Haml (Rails).haml.classname + {:class =>} extraction
HTML.htmlclass="..." extraction
CSS Modules.module.css .module.scss .module.lessDynamic import resolution
Tailwindtailwind.config.js + CSS @themev3 JS config + v4 CSS config

Production Scale

ProjectTotal filesFirst indexNodesEdges
Small~50~15s~16K~50K
Production monorepo~11K~3-5m~780K~22M

Project Configuration

Zero-config by default. Optional .cssgraph.json at your project root:

json
{  "exclude": ["static/vendor/", "**/legacy/**"],  "extensions": {    ".pcss": "css"  }}

Built-in default excludes (always applied): **/*.test.*, **/*.stories.*, **/*.spec.*, **/*.min.*, **/__tests__/**, **/__snapshots__/**, **/__mocks__/**, **/generated/**, **/spec/**, **/vendor/**.


Supported Platforms

PlatformArchitecturesInstall
macOSx64, arm64npm
Linuxx64, arm64npm
Windowsx64, arm64npm

If cssgraph is useful

A ⭐ star helps other developers discover it — and tells us to keep shipping.


License

MIT

来源:README.md,提交 6f8726d

工具

0
SourceWeft 尚未在沙箱中启动过该软件包,因此其工具未知。

版本历史

1
  1. v0.6.3最新Sep 16, 2026

评分

已满足适用检查项的 50%

该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。

  • 近 30 天内可连通25 分

    请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。

  • 已声明认证方式10 分

    请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。

  • 已列出工具15 分

    请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。

  • 描述必需15 分
  • 图标10 分
  • 文档15 分
  • 许可证10 分