Skip to content

About the Project ​

This page explains the logic of the two servers in detail: why they are split, how indexing works, how documentation is linked to code, how search ranks results, and how the live preview reuses everything the indexer already knows.

The idea: one index, two consumers ​

An AI assistant and a human need different answers about the same codebase. The assistant needs structured, typed facts delivered over MCP; the human needs to see the component working. Both answers come from one index — that is why the project is two packages, not two products:

  • vue-codebase-mcp builds and serves the index: components with props/emits/slots/exposed, composables, Pinia stores, routes, utilities, markdown documentation and the relations between all of it.
  • vue-codebase-view-mcp takes the same index and renders the project's real components in a browser through a live Vite dev server.

The split follows the “one server — one question” rule: the indexer never starts a browser-facing service, and the view server never re-implements indexing.

Why not one merged server? The two halves disagree on every axis that matters:

Axisvue-codebase-mcpvue-codebase-view-mcp
Consumeran AI agent over MCPa human in a browser
Lifecyclespawned per client session, exits with ita long-lived dev server
DependenciesTypeScript, vue-component-meta, MiniSearchVite, the Vue runtime, a UI shell
Failure modea wrong answer costs the model a bad edita broken render costs a developer an afternoon

Merging them would install Vite and a component-rendering runtime into every AI assistant's MCP configuration — including for users who only ever want the index. The part worth sharing is the index itself, and that is exactly what the indexer's library API exposes, so the split costs one dependency edge and no duplicated logic. The same comparison, plus the other rejected alternatives (Storybook, embeddings, a Vite plugin), lives in ARCHITECTURE.md §7 “Why not the alternatives”.

Two indexing modes ​

Resolving Vue component types properly means running vue-component-meta — the same engine that powers Volar — over a TypeScript program. That takes seconds, which is too slow every time a server starts. So indexing is split into two modes:

  • full — the index command. vue-component-meta for .vue files, a TS program and type checker for .ts files. The result is a snapshot on disk (.vue-codebase-mcp.cache/index.json, plain JSON, versioned by a format counter). On a real UI library: ~3 s for 125 components, 1.2 MB snapshot.
  • light — at server start when there is no snapshot. @vue/compiler-sfc plus the TypeScript AST, no type resolution: a fraction of a second on any project.

Honesty is part of the design. Every entity records where its API came from (apiSource: vue-component-meta, typescript, sfc-lite, syntax), light-mode answers explicitly say that types are unresolved and suggest the exact index command, and files edited after the snapshot was built are marked stale. That mark is set by the file watcher: it re-reads an edited file with the syntactic parser, so the data stays fresh but the entity's apiSource drops to sfc-lite until a rebuild with index --mode full resolves the types again. Parse diagnostics (broken SFC syntax, external prop types that light mode cannot resolve, failed store parsing) flow into the build report in both modes.

Documentation: four levels and seven linking rules ​

Markdown is indexed as a first-class citizen. Every document gets a level — component, workspace, collection, project — which determines its URI (doc://component/UiButton, doc://workspace/ui-kit/getting-started, …) and its linking priority: a file is registered once, so a component page found early is never downgraded by a broader glob later.

The rules that link a document to an entity (indexer/docLinker.ts), in priority order:

  1. explicit docs.componentDocs from the configuration;
  2. components.docMapping patterns with {name} / {dir} placeholders;
  3. a sibling file — Button.vue → Button.md, Button.vue.md;
  4. README.md / index.md in the entity's own directory;
  5. a docs/ directory in any ancestor, up to four levels — for modular layouts like src/components/ui-button/ui/UiButton.vue + src/components/ui-button/docs/ui-button.md (this is exactly how playground/ui-library in this repository is laid out);
  6. the project documentation directory: docs/components/<Name>.md, docs/<Name>.md, documentation/…;
  7. a JSDoc @docs ./file.md reference in the source.

Candidate names include the kebab-case form, because file names and document names diverge in case regularly. Linking returns all matches, not the first: a component may legitimately have both a module page and a mention in a general guide.

Links come in two kinds, and the tools distinguish them: strong (entity.docIds — the document was found from the file or the configuration) and weak (doc.entityRefs — the document merely mentions the entity). Without that split, a general guide was served as a component's documentation just because the component happened to be mentioned in it.

Two independent mechanisms:

  • Ranked search (indexer/search.ts) behind the search tool. Signals and scores: exact name +1000, dictionary concept matched an alias +700, alias prefix +520, phrase in description +300, exact alias token +200, stemmed token +120, category/tag +100, API member +80, description token +60, fuzzy similarity ×300 above the threshold, deprecated −40, internal −60. Every result carries the reason it matched (up to four signals) — selection is automatic, so the model must see what a result hung on.
  • Full-text (MiniSearch) behind search_docs, with snippets.

Name resolution accepts any shape — entity id, exact name, name with the design-system prefix stripped, a single unambiguous prefix — and on failure returns similar names ranked by Levenshtein distance instead of an empty result.

Russian↔English correspondence («кнопка» → UiButton) is a curated dictionary with word-form awareness: a common prefix of at least four characters and no shorter than “key length minus two” matches «кнопкой» → «кнопка», but not «около» → «окно». The dictionary extends via search.synonyms. Two traps found against a real project are now closed by tests: substring matching requires a minimum token length (otherwise a short design-system prefix token — the single-letter x of x-accordion — matched button), and name normalisation must not strip Cyrillic (otherwise «Размеры» became an empty string).

How the view server reuses the indexer ​

The view package imports the indexer as a library instead of forking it: one implementation of configuration loading, index building, language resolution, logging, pluralisation and name resolution serves both servers. The public API of the indexer was widened specifically for this — including an EntityOfKind<K> type fix that made byKind("composable") typed instead of never[]. The module boundaries (what is wrapped, what is imported as types only, why the UI ships as source) are described in Architecture → How the view server reuses the indexer.

i18n architecture ​

The rule is: never store a rendered string. A diagnostic is { code, params }, and the text is born only at the boundary — a tool answer, a CLI message, the preview manifest. That is what keeps the snapshot language-neutral (switching the language never forces a re-index), lets one code render correctly in every language, and makes a missing translation a compile error rather than a runtime surprise. The structural side (which file defines the dictionary shape, how parity is tested, what the view server reuses) is in Architecture; what is and is not translated today is in Language.

Security ​

  • File reads are confined to the project roots; .. and symlink escapes are rejected.
  • Never served: .env*, .npmrc, .git/, node_modules/, .ssh/, .aws/, private keys, files with secret/credentials in the name.
  • Absolute machine paths are stripped from entity payloads and from the preview HTTP API. Two answers still carry them on purpose, because they are debugging output about the host itself: get_project_overview (configuration path, workspace roots, tsconfig) and the index://overview resource.
  • HTTP mode validates Host/Origin and Authorization (when a token is set); the view server binds localhost and sets server.fs.allow explicitly.

The full list, including exactly what resources.exposeSourceCode closes, is in Deployment → Security.

Visual language ​

The interface and this site use the visual language of the Vue ecosystem: the #42b883 / #35495e palette and tokens from vuejs.org, the Vue logomark, a dark theme driven by the system preference. The preview UI is deliberately built without external libraries (no Pinia, no vue-router, no d3) so it works inside any target project — only Vue itself, resolved to the single instance shared with the rendered components.

MIT Licensed