Nanostores MCP
The MCP server for Nanostores that scans your codebase with AST analysis to find stores, subscribers, and dependency chains, and can ingest live events to spot noisy, error-prone, or unused stores.
README
Nano Stores MCP
<img align="right" width="92" height="92" title="Nano Stores logo" src="https://nanostores.github.io/nanostores/logo.svg">
Model Context Protocol server for Nanostores β analyze, debug and monitor your nanostores in AI assistants like Claude Desktop.
- π Static Analysis: AST-based project scanning, dependency graphs, store inspection
- π₯ Runtime Monitoring: Live events from
@nanostores/logger, performance metrics, activity tracking - π Documentation: Search and browse Nanostores docs by topic or store kind
- π― Zero Config: Works out of the box β auto-detects project roots and nanostores docs
- π Framework-Agnostic: Works with React, Vue, Svelte, Angular, Solid, Preact, Lit β any framework that uses Nanostores
npx nanostores-mcp
Ask your AI: "Analyze my store architecture" or "Which stores update most frequently?"
<img src="https://cdn.evilmartians.com/badges/logo-no-label.svg" alt="" width="22" height="16" /> Made at <b><a href="https://evilmartians.com/devtools?utm_source=nanostores-mcp&utm_campaign=devtools-button&utm_medium=github">Evil Martians</a></b>, product consulting for <b>developer tools</b>.
Table of Contents
- Features
- Requirements
- Installation
- Configuration
- Quick Start
- MCP Interface
- Runtime Monitoring
- Example Queries
- Architecture
- Limitations & Caveats
- Development
- Troubleshooting
Features
π Static Analysis (AST-based)
Understand your nanostores architecture without running your app:
- Project scanning β find all stores, subscribers, and import/export relationships
- Dependency graph β visualize how stores depend on each other (Mermaid diagrams)
- Store inspection β type (atom/map/computed/batched/persistentAtom/persistentMap/router), location, usage patterns, related files
- Framework-aware subscriber detection β recognizes
.subscribe()/.listen()calls and component bindings across React, Vue, Svelte, and Angular - Vue SFC support β parses both
<script>and<script setup>blocks in.vuefiles (requires@vue/compiler-sfc) - Svelte support β parses
<script context="module">and instance<script>blocks, auto-subscriptions ($storeNamein templates), and filters out Svelte 5 runes ($state,$derived,$effect, etc.) so they are not mistaken for store references (requiressvelte) - Angular DI support β resolves
@nanostores/angularNanostoresServiceconstructor injections and detectsthis.nanostores.useStore(...)call patterns in TypeScript component files
π₯ Runtime Monitoring (Logger Integration)
Real-time insights into your running application:
- Live event capture β mount/unmount, value changes, action calls from
@nanostores/logger - Performance analysis β find noisy stores, high error rates, performance bottlenecks
- Activity metrics β change frequency, action success/failure rates, action duration
- Combined analysis β merge static structure with runtime behavior for deep debugging
π Documentation Search
Search and browse Nanostores documentation directly from your AI assistant:
- Full-text search β find guides, API references, and best practices by query
- Store-kind lookup β get docs relevant to a specific store type (atom, map, computed, etc.)
- Auto-detection β picks up docs from
nanostoresin yournode_modulesautomatically
Requirements
| Requirement | Version |
|---|---|
| Node.js | ^20.0.0 || >=22.0.0 |
Required peer dependency (for static analysis):
npm install nanostores
Optional peer dependencies β install only if you use the corresponding file format:
| Package | When needed |
|---|---|
@vue/compiler-sfc |
Vue SFC (.vue) file scanning |
svelte |
Svelte (.svelte) file scanning |
@nanostores/logger |
Runtime monitoring (attachMcpLogger) |
Without these optional packages the server still works β it silently skips unsupported file types.
Installation
npm install -g nanostores-mcp
# or
pnpm add -g nanostores-mcp
Or run directly without installation:
npx nanostores-mcp
Configuration
Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"nanostores": {
"command": "npx",
"args": ["-y", "nanostores-mcp"],
"env": {
"NANOSTORES_MCP_ROOT": "/path/to/your/project"
}
}
}
}
VS Code
Requires GitHub Copilot extension (VS Code 1.99+). Create .vscode/mcp.json in your project:
{
"servers": {
"nanostores": {
"type": "stdio",
"command": "npx",
"args": ["-y", "nanostores-mcp"]
}
}
}
Tools are available in Copilot's Agent mode (select "Agent" in the Copilot Chat dropdown).
Cursor
Create .cursor/mcp.json in your project root (or ~/.cursor/mcp.json for global):
{
"mcpServers": {
"nanostores": {
"command": "npx",
"args": ["-y", "nanostores-mcp"]
}
}
}
Zed
Add to your Zed settings.json:
{
"context_servers": {
"nanostores": {
"command": "npx",
"args": ["-y", "nanostores-mcp"],
"env": {
"NANOSTORES_MCP_ROOT": "/path/to/your/project"
}
}
}
}
The server appears in Zed's Agent Panel settings.
Windsurf
Add to ~/.codeium/windsurf/mcp_config.json:
{
"mcpServers": {
"nanostores": {
"command": "npx",
"args": ["-y", "nanostores-mcp"],
"env": {
"NANOSTORES_MCP_ROOT": "/path/to/your/project"
}
}
}
}
You can also open this file from the MCP icon in the Cascade panel β "Configure".
Claude Code
Add via CLI:
claude mcp add --transport stdio nanostores -- npx -y nanostores-mcp
Or create .mcp.json in your project root (shared with the team):
{
"mcpServers": {
"nanostores": {
"command": "npx",
"args": ["-y", "nanostores-mcp"],
"env": {
"NANOSTORES_MCP_ROOT": "/path/to/your/project"
}
}
}
}
Environment Variables
| Variable | Default | Description |
|---|---|---|
NANOSTORES_MCP_ROOT |
cwd | Project root path |
NANOSTORES_MCP_ROOTS |
β | Platform-delimited roots (: on Unix, ; on Windows) for multi-project setup |
WORKSPACE_FOLDER |
β | Alias for NANOSTORES_MCP_ROOT β set automatically by VS Code and some editors |
WORKSPACE_FOLDER_PATHS |
β | Alias for NANOSTORES_MCP_ROOTS β set automatically by some editors |
NANOSTORES_MCP_LOGGER_ENABLED |
true |
Set to false or 0 to disable runtime event collection and the logger bridge |
NANOSTORES_MCP_LOGGER_PORT |
3999 |
HTTP port for logger bridge |
NANOSTORES_MCP_LOGGER_HOST |
127.0.0.1 |
Host to bind. Allowed values: 127.0.0.1, localhost, ::1 |
NANOSTORES_DOCS_ROOT |
auto-detect | Path to documentation directory |
NANOSTORES_DOCS_PATTERNS |
**/*.md |
Comma-separated glob patterns for docs |
How the Project Root Is Resolved
The server picks workspace roots in priority order:
- Environment variables (highest priority) β
NANOSTORES_MCP_ROOTS/NANOSTORES_MCP_ROOT/WORKSPACE_FOLDER_PATHS/WORKSPACE_FOLDER - Client roots β roots reported by the MCP client via the
roots/listcapability (set automatically by some editors) - Current working directory β
process.cwd()used as fallback when neither env nor client roots are configured
When a tool is called without an explicit projectRoot argument the server uses the first configured root. In a multi-root setup always pass projectRoot to avoid ambiguity.
Quick Start
1. Static Analysis
Works out of the box β just point at your project and ask:
- "Analyze my store architecture"
- "Explain how nanostores is used in this project"
- "Give me a summary of the $cart store"
- "My stores changed β re-scan the project" β the AI will force a fresh scan
2. Documentation Search
Auto-detected from nanostores in your node_modules:
- "How do I use computed stores?"
- "Show me the docs for persistentAtom"
3. Runtime Monitoring (Optional)
Requires logger integration in your app. See Runtime Monitoring below.
- "Which stores update most frequently?"
- "Show me recent activity for $user"
- "Give me an overall health report"
Verify Your Setup
Run these four tools in order to confirm everything is working:
nanostores_ping β should return server status and logger bridge state
nanostores_scan_project β should list your stores and subscribers
nanostores_docs_search β should return documentation results (requires nanostores in node_modules)
nanostores_runtime_overview β should return overview (or "no runtime data" if logger is disabled β that's fine)
If nanostores_scan_project returns zero stores, check that NANOSTORES_MCP_ROOT points to the correct project directory.
MCP Interface
MCP Resources
| Resource | Description |
|---|---|
nanostores://graph |
Full dependency graph (text + Mermaid) |
nanostores://store/{key} |
Store details by name or id |
nanostores://docs |
Documentation index β all pages and tags |
nanostores://docs/page/{id} |
Full content of a documentation page |
MCP Tools
Static Analysis
| Tool | Description |
|---|---|
nanostores_scan_project |
Scan project for all stores, subscribers, and dependencies |
nanostores_store_summary |
Detailed summary of a specific store |
nanostores_project_outline |
High-level overview: store kinds, top directories, hub stores |
nanostores_store_subgraph |
BFS-expanded dependency neighborhood of a store |
nanostores_store_impact |
Downstream causal chain β what recomputes/re-renders if X changes |
Runtime Monitoring
| Tool | Description |
|---|---|
nanostores_runtime_overview |
Overall health report with statistics for all stores |
nanostores_store_activity |
Activity timeline for a specific store (filterable by kind/action) |
nanostores_find_noisy_stores |
Identify stores with high change frequency or error rates |
nanostores_runtime_coverage |
Compare static graph with runtime events to find coverage gaps |
Documentation
| Tool | Description |
|---|---|
nanostores_docs_search |
Search docs by query (full-text), storeKind (atom, map, computed, persistentAtom, etc.), or both. Optional: limit (default 10), tags |
Use nanostores://docs/page/{id} resource to read the full content of pages returned by search.
Utilities
| Tool | Description |
|---|---|
nanostores_ping |
Server health check and logger bridge status |
nanostores_clear_cache |
Clear project index cache to force rescan |
MCP Prompts
| Prompt | Parameters | Description |
|---|---|---|
explain-project |
focus (optional) |
AI-guided explanation of your project's store architecture. focus narrows to a feature/domain (e.g. "cart", "auth") |
explain-store |
store_name (required) |
Deep dive into a specific store's implementation and usage |
debug-store |
store_name (required) |
Comprehensive analysis combining static + runtime data |
debug-project-activity |
β | Project-wide performance analysis and optimization |
docs-how-to |
task (required) |
Step-by-step guidance for a Nanostores task, backed by docs (e.g. "How do I sync a map store to localStorage?") |
Advanced Tool Arguments
Most tools accept these optional arguments that significantly change their behavior:
| Argument | Type | Used in | Description |
|---|---|---|---|
storeId |
string |
store_summary, store_subgraph, store_impact |
Exact store identifier β format: store:src/stores.ts#$counterName. Takes priority over name when both are provided. |
name |
string |
store_summary, store_subgraph, store_impact |
Store name (e.g. "$user"). Used when storeId is not provided. |
radius |
number (0β10, default 2) |
nanostores_store_subgraph |
BFS hops around the store. 1 = direct deps only; 2 = deps of deps. Warning: on highly-connected hub stores (hub score > 5) radius β₯ 2 may return most of the project β start with 1. |
projectRoot |
string |
most tools | Which project root to analyze in multi-root setups. Omit to use the first configured root. Always specify this in multi-root projects. |
windowMs |
number |
store_activity, find_noisy_stores, runtime_overview |
Look-back window in milliseconds (e.g. 60000 = last 60 s). Filters events to that time range. |
kinds |
string[] |
nanostores_store_activity |
Filter events by type. Values: "mount", "unmount", "change", "action-start", "action-end", "action-error". |
actionName |
string |
nanostores_store_activity |
Filter events to a specific action (e.g. "increment"). |
compact |
boolean |
scan_project, find_noisy_stores, runtime_overview |
Return a compressed token-efficient table instead of full text. Useful for large projects to reduce context usage. |
Runtime Monitoring
For runtime analysis, integrate the MCP Logger client into your application.
1. Install in your app and enable the logger bridge:
npm install nanostores-mcp
The logger bridge starts automatically β no extra config needed. To disable it, set NANOSTORES_MCP_LOGGER_ENABLED=false in your MCP server config.
2. Define stores with logger attached (src/stores.ts):
import { atom, map, computed } from "nanostores";
import { initMcpLogger, attachMcpLogger } from "nanostores-mcp/mcpLogger";
// Automatically disabled in production (checks NODE_ENV / import.meta.env.DEV)
initMcpLogger();
// Stores
export const $count = atom(0);
export const $user = map({ name: "", role: "guest" });
export const $greeting = computed($user, user => `Hello, ${user.name}`);
// Attach logger β each call returns a cleanup function
attachMcpLogger($count, "$count");
attachMcpLogger($user, "$user");
attachMcpLogger($greeting, "$greeting");
3. Use stores normally β events (mount, unmount, change, actions) are captured automatically and batched to the MCP server every second.
4. Ask your AI assistant:
- "Which stores change most frequently?" β
nanostores_find_noisy_stores - "Show me recent activity for $user" β
nanostores_store_activity - "Give me an overall health report" β
nanostores_runtime_overview
Logger Options
initMcpLogger({
url: "http://127.0.0.1:3999/nanostores-logger", // default; change if using a custom port
batchMs: 1000, // default; lower for faster delivery (e.g. 200)
projectRoot: "/absolute/path/to/project", // link runtime events with static analysis
// Mask sensitive data β return null to skip event entirely
maskEvent: event => {
if (event.storeName === "authToken") return null;
return event;
},
});
Flush Before Shutdown
import { getMcpLogger } from "nanostores-mcp/mcpLogger";
window.addEventListener("beforeunload", async () => {
await getMcpLogger()?.forceFlush();
});
Reading Results
nanostores_runtime_overview health summary
The overview groups stores into three categories:
- Top active stores β sorted by total event count (changes + actions). A store that appears here with hundreds of changes in seconds may be a performance concern.
- Error-prone stores β stores with
action-errorevents. High error counts indicate failing async actions. - Unmounted stores β stores seen at mount but never unmounted. May indicate memory leaks.
nanostores_runtime_coverage
Compares your static store graph against observed runtime events:
| Term | Meaning |
|---|---|
| static-only | Store found by AST scan but no runtime events observed. Possible dead code, deferred initialization, or missing attachMcpLogger call. |
| runtime-only | Events received for a store not found by the scanner. Common for dynamically-created stores, factory patterns, or stores in node_modules. |
| Coverage by kind | E.g. atom: 3/5 (60%) β 3 out of 5 atom stores received runtime events. 0% for a kind usually means attachMcpLogger was not called for those stores. |
nanostores_find_noisy_stores
Returns stores ranked by total activity (changes + actions combined) within the windowMs period. A store is considered "noisy" when its change frequency is disproportionately high relative to visible UI updates β use this to find re-render hotspots or thrashing computed chains.
Privacy & Security
The runtime logger is designed to stay on your local machine:
- Loopback-only binding β the HTTP bridge accepts connections exclusively from
127.0.0.1,localhost, or::1. Binding to0.0.0.0is explicitly blocked. Data never leaves your machine. - What is transmitted β from your app to the MCP server over localhost: store name, timestamp, event kind, and optionally value snapshots (truncated to 200 characters). Nothing is sent to Anthropic or any third party.
- Nothing is persisted β events are held in a ring buffer (5 000 events max) in process memory and discarded when the server restarts.
- Mask sensitive data β use
maskEventto filter or redact events client-side before they are batched and sent:
initMcpLogger({
maskEvent: event => {
if (event.storeName === "$authToken") return null; // drop entirely
if (event.storeName === "$paymentInfo") return { ...event, newValue: undefined }; // strip value
return event;
},
});
- CORS β the bridge rejects cross-origin requests from non-loopback origins.
Example Queries
Ask your AI assistant natural language questions:
Static Analysis:
- "Analyze my store architecture for potential issues"
- "What happens when $user changes? Show subscribers and derived stores"
Runtime Debugging:
- "Which stores update most frequently?"
- "Are there stores declared in code but never used at runtime?"
- "Debug the $user store β combine static analysis with runtime behavior"
With Playwright MCP:
- "Open my app in the browser, interact with it, and analyze which stores cause the most recalculations"
Documentation:
- "How do I use computed stores?"
- "Show me best practices for persistent stores"
Architecture
ββββββββββββββββββββββββ
β Your Application β
β β
β @nanostores/logger β
β events β
ββββββββββββ¬ββββββββββββ
β HTTP POST (localhost:3999)
βΌ
ββββββββββββββββββββββββ
β nanostores-mcp β
β β
β ββββββββββββββββ β
β β Logger Bridge β β β HTTP server for runtime events
β ββββββββ¬ββββββββ β
β βΌ β
β ββββββββββββββββ β
β β Event Store β β β Ring buffer (5000 events) + stats
β ββββββββ¬ββββββββ β
β β β
β ββββββββ΄ββββββββ β
β β AST Scanner β β β ts-morph static analysis
β ββββββββ¬ββββββββ β
β β β
β ββββββββ΄ββββββββ β
β β Docs Index β β β Auto-detected from node_modules
β ββββββββ¬ββββββββ β
β β β
β ββββββββ΄ββββββββ β
β β MCP Interfaceβ β β Resources, Tools, Prompts
β ββββββββββββββββ β
ββββββββββββ¬ββββββββββββ
β MCP Protocol (stdio)
βΌ
ββββββββββββββββββββββββ
β LLM Client β
β (Claude, VS Code, β¦) β
ββββββββββββββββββββββββ
Limitations & Caveats
Multi-root: same store name in multiple projects
In multi-root mode a store named $user can exist in two different projects. The runtime event store uses a composite key (projectRoot + storeName) to keep them separate, but summary views may show the same name twice with no project label. Always specify projectRoot when querying tools in a multi-root setup to get unambiguous results.
Static analysis only covers discovered files
The AST scanner follows TypeScript/JavaScript imports from your project root. Stores created dynamically at runtime, generated by factories, or living in node_modules will not appear in static results β they may show up as "runtime-only" in coverage reports.
Vue and Svelte parsing requires optional dependencies
If @vue/compiler-sfc or svelte are not installed, .vue / .svelte files are silently skipped during scanning. Install them as dev dependencies if you want full coverage for those file types.
Event ring buffer is capped at 5 000 events
Older events are dropped when the buffer is full. For high-frequency stores use windowMs to narrow your queries to recent data, or lower batchMs in initMcpLogger to deliver events more frequently and reduce the chance of buffer overflow during bursts.
radius on hub stores can be very large
Stores with many dependencies (hub score > 5) can return most of the project graph at radius=2. Start with radius=1 and increase only if you need broader context.
Development
git clone https://github.com/Valyay/nanostores-mcp.git
cd nanostores-mcp
pnpm install
pnpm dev # Run dev server
pnpm build # TypeScript compile
pnpm test # Run vitest
pnpm lint # ESLint
pnpm check # All checks: lint + format + test + build
# Test with MCP Inspector
npx @modelcontextprotocol/inspector pnpm run dev
Troubleshooting
Logger not receiving events:
- Use the
pingtool to verify logger bridge is enabled and running - Check browser console for
[nanostores-mcp]warnings about connection issues - Confirm the port matches between server (
NANOSTORES_MCP_LOGGER_PORT) and client URL - Test with a simple atom store to verify events flow
Port conflicts:
# Change server port
NANOSTORES_MCP_LOGGER_PORT=4000 npx nanostores-mcp
# Update client
initMcpLogger({ url: "http://127.0.0.1:4000/nanostores-logger" });
TypeScript errors:
// Import from the mcpLogger subpath export
import { initMcpLogger, attachMcpLogger } from "nanostores-mcp/mcpLogger";
Documentation not found:
- The server auto-detects docs from
nanostoresin yournode_modules - Make sure
nanostoresis installed:npm install nanostores - Or set
NANOSTORES_DOCS_ROOTto point at a docs directory manually
Related Projects
Nanostores ecosystem:
- nanostores β Tiny state manager (atom, map, computed, batched, deepMap)
- @nanostores/logger β Logger and action system
- @nanostores/persistent β Persistent stores (localStorage, sessionStorage)
- @nanostores/router β SPA router
- @nanostores/i18n β Internationalization
- @nanostores/react, @nanostores/vue, @nanostores/preact, @nanostores/solid, @nanostores/lit β Framework bindings
MCP:
- Model Context Protocol β MCP specification
- Playwright MCP β Browser automation (works with nanostores-mcp for runtime analysis)
License
MIT
Contributing
Contributions are welcome! Please open an issue or PR.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.