npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ui-hierarchy-mcp

v0.2.1

Published

MCP server that returns a Next.js App Router project's UI component hierarchy as a structured tree (markdown + JSON) so AI coding agents can ground image/description-based UI edits in exact file/component locations.

Readme

ui-hierarchy-mcp

npm version

MCP (Model Context Protocol) server that parses a Next.js App Router project and returns its UI component hierarchy as structured output (markdown tree + JSON), so AI coding agents can ground image/description-based UI edits in exact file/component locations.

When an AI agent cannot confidently act on a screenshot or vague description ("make the card next to the avatar wider"), it can call this MCP to get a precise, structured map of the live component tree — with file:line, layout hints, text content, and conditional branches — so the agent edits the right component in the right file instead of guessing.

Status

Targets Next.js App Router. Static analysis only — no runtime execution, no DOM, no rendering.

Requirements

  • Node.js >=20
  • An MCP-capable client (Claude Code, Claude Desktop, Cursor, or MCP Inspector)

Run

No install step is needed when used as an MCP server — clients spawn the binary on demand via npx. The three common ways to run it:

1. Via an MCP client (normal usage)

Add the server to your client config (see Use with an MCP client below). The client launches npx -y ui-hierarchy-mcp for you and speaks JSON-RPC over stdio.

2. Standalone for debugging

npx -y ui-hierarchy-mcp

The process speaks JSON-RPC on stdio, so it will sit idle waiting for a client. Useful only to confirm the binary downloads and launches; press Ctrl+C to exit.

3. Interactive UI (MCP Inspector)

npx @modelcontextprotocol/inspector npx -y ui-hierarchy-mcp

Opens a local web UI where you can list and invoke each tool against a real project — the fastest way to explore the output format without wiring up an AI client.

Pointing at a project

Every tool accepts a projectRoot argument (absolute path). To set a default for all calls, export UI_TO_HIERARCH_ROOT before launching the client:

export UI_TO_HIERARCH_ROOT=/abs/path/to/your/nextjs/project

If neither is set, the server falls back to process.cwd() — usually the directory the MCP client was launched from.

Use with an MCP client

Claude Code / Claude Desktop

Add to ~/.claude.json (or per-project .mcp.json):

{
  "mcpServers": {
    "ui-hierarchy": {
      "command": "npx",
      "args": ["-y", "ui-hierarchy-mcp"]
    }
  }
}

Cursor

Add to ~/.cursor/mcp.json (or .cursor/mcp.json per project):

{
  "mcpServers": {
    "ui-hierarchy": {
      "command": "npx",
      "args": ["-y", "ui-hierarchy-mcp"]
    }
  }
}

Onboard your agent (--init)

Inject a usage guide for ui-hierarchy-mcp into your project's agent instruction files in one command:

npx -y ui-hierarchy-mcp --init

By default this writes a marker block into CLAUDE.md (created if absent) containing the four tool descriptions, a registration snippet, and example calls. Re-running the command is a no-op when the block is already current — safe to wire into CI or repo bootstrap scripts.

Targets

Pick one or more agent instruction surfaces via --target (comma-separated):

| Target | File written | |---|---| | claude (default) | CLAUDE.md | | codex | AGENTS.md | | cursor | .cursor/rules/ui-hierarchy-mcp.mdc (with YAML frontmatter) | | copilot | .github/copilot-instructions.md |

# Onboard all four agents at once
npx -y ui-hierarchy-mcp --init --target claude,codex,cursor,copilot

Missing parent directories are created automatically.

Flags

  • --dry-run — print a per-target plan (would create / would update / would skip) to stderr, write nothing.
  • --force — overwrite the marker block even if it has been hand-edited (otherwise the target is skipped with a warning).

--init is fully argv-driven (no prompts) and safe in CI. Running npx ui-hierarchy-mcp without --init still starts the MCP stdio server unchanged.

Tools

All tools accept an optional projectRoot (absolute path) — defaults to UI_TO_HIERARCH_ROOT env var, then process.cwd().

| Tool | Purpose | |---|---| | get_full_hierarchy | Returns the ordered layout chain and page component subtree for a Next.js App Router route. | | focus_on | Returns the component subtree rooted at a named JSX component, optionally including ancestors. | | find_by_text | Finds component nodes whose rendered text content matches a query string. Returns nodes with file:line location. | | find_by_style | Finds component nodes that use a given CSS class name or style prop. Returns nodes with file:line location. |

Example — get_full_hierarchy

{
  "route": "/dashboard/123",
  "format": "json",
  "projectRoot": "/abs/path/to/your/nextjs/project"
}

route must be a valid Next.js App Router path (start with /, no trailing slash except root). Dynamic segments like [slug], [...rest], [[...optional]] are supported.

Example — focus_on

{
  "component": "DashboardDetail",
  "scope": "full",
  "projectRoot": "/abs/path/to/your/nextjs/project"
}

scope: "up" (ancestors only), "full" (ancestors + subtree, default), or "down" (subtree only).

Example — find_by_text

{
  "query": "Sidebar slot",
  "projectRoot": "/abs/path/to/your/nextjs/project"
}

Example — find_by_style

{
  "class_or_prop": "grid-cols-3",
  "projectRoot": "/abs/path/to/your/nextjs/project"
}

Tech

  • TypeScript + @modelcontextprotocol/sdk v1.29
  • @babel/parser + @babel/traverse for JSX/TSX AST analysis
  • get-tsconfig for tsconfig path-alias resolution
  • tinyglobby for file discovery
  • ESM-only, Node >=20

Development

Clone and work on the server itself:

git clone https://github.com/dovanhuy2298/ui-to-hierarchy.git
cd ui-to-hierarchy
pnpm install

Common scripts:

| Script | Purpose | |---|---| | pnpm dev | Run the CLI directly from TypeScript source (tsx src/cli.ts). Pass args after --, e.g. pnpm dev -- --init --dry-run. | | pnpm build | Bundle to dist/ via tsup (ESM, with shebang). | | pnpm test | Run the full Vitest suite. | | pnpm test:watch | Watch mode. | | pnpm test:smoke | Spawn-the-binary smoke test against the MCP stdio contract. | | pnpm test:integration | Integration suite against fixture Next.js projects. | | pnpm typecheck | tsc --noEmit. | | pnpm lint | biome check .. |

To test a local build against an MCP client, point its command at the built binary:

{
  "mcpServers": {
    "ui-hierarchy": {
      "command": "node",
      "args": ["/abs/path/to/ui-to-hierarchy/dist/cli.js"]
    }
  }
}

Roadmap

V1 covers Next.js App Router. Internal architecture is pluggable so additional framework parsers (React Native, Vue, Svelte) can be added later without rewriting the core. Caching, watch mode, and HTTP transport are explicitly deferred.

License

MIT © huydv98