← BACK TO FIELD NOTES
BUILD LOG12 MIN READ

How We Built an MCP Server for Our UI Library

We built a small server that lets AI coding assistants ask our Angular component library about itself. Here's what it does, how it gets its facts, and the two times it gave a confident wrong answer.

PUBLISHED:October 4, 2026
TRACK:MCP
TAGS:
#frontend#agentic-harness#mcp#architecture

Hero

Why good docs still fail an AI assistant

We wanted AI coding assistants to work well with our Angular component library. The obvious plan: write really good docs and point the assistant at them.

Then we watched an assistant write code from a doc that was wrong. Nothing flagged it. No error, no warning. The code just looked fine.

Here’s the difference between a person and an assistant. A person who hits a doc that feels off will go check. Open the component, read the source, grep for the name. An assistant doesn’t have that itch. Ask it “what inputs does this component take?” and it takes whatever it gets back and starts writing code. By the time something breaks, you’re several steps away from the mistake.

There’s a second problem, and it isn’t about accuracy at all. Even a correct doc is just a pile of text. When a model reads a long page, it picks out the bits it thinks matter. Ask the same question twice and it might grab different sentences, or skip a warning three paragraphs down. If a wrong prop name means a broken build, that kind of wobble is worth designing around.

So our goal wasn’t “serve the docs we already have.” It was smaller and harder. Turn each fact the assistant needs into one labeled field it can just read, instead of a sentence it has to find. That’s the whole reason we built a server instead of leaving a folder of markdown files.

This post covers what the server offers, where its facts come from, and the two ways it gave us answers that looked right and weren’t.

What the server offers

The server is called ui-lib-mcp. (MCP is a standard way for AI tools to call small, specific functions on a server. Think of each function as a question the assistant can ask.) It has 14 of these today.

Our first plan had seven: list, get_component, get_examples, get_story, get_rules, get_patterns and search_components. We ended up with more. But one rule held the whole time: each tool answers one question, and always returns the same shape of answer.

Three tools do most of the work.

get_component(name) returns everything about one component: where it lives, how to import it, its inputs, its outputs, and its gotchas (the stuff a type checker can’t catch). list() shows what the library actually contains, so the assistant stops guessing at names. search_components(query) covers the case where the assistant knows roughly what it wants but not the exact name. That’s usually the moment a model makes up a plausible-sounding component that doesn’t exist.

Ask for get_component('select') and you don’t get a paragraph to dig through. You get this:

// Every answer has the same fixed fields, not a free-text blob

interface GetComponentResult {
  name: string;
  module: string;
  import_name: string;
  inputs: { name: string; type: string; required: boolean }[];
  outputs: { name: string; type: string }[];
  gotchas: string[];
  internal: boolean;
}

The fields do two different jobs. inputs and outputs are plain facts: names, types, whether something is required. gotchas is where a human’s judgment goes. Hidden browser quirks. Inputs that only work alongside other inputs. “Never do this” rules. And internal flags components you can’t import directly, so the tool says so instead of handing over an import line that will never work.

The other tools follow the same idea. get_rules() and get_patterns() keep the hard rules apart from the softer suggestions, so the model can treat them differently instead of reading one big mixed list.

Fixed fields cut down a lot of the guessing. But they turned out to promise less than we thought. That’s what the rest of this post is about.

One source of truth, two outputs

The setup fits in a sentence. One YAML file per component, one script that reads them, two things that come out.

A person edits prompts/<component>.prompt.yml. A tool called compodoc, which reads our Angular code, supplies the facts the code already knows for sure: selectors, file paths, input and output names and types. The script, generate-prompts.ts, combines both.

Out come two things. First, generated markdown files for each component, which ui-lib-mcp serves live. Second, a file called components/llms.txt that ships inside the published npm package. So even if someone has the library installed but isn’t running the server, their AI tool still gets useful context with no setup.

Who writes what matters more than the file names. The YAML never repeats anything compodoc already knows. It only holds what a person has to say: gotchas, rules, usage patterns, browser quirks, required companion inputs, and “don’t do this” notes. If the code can answer it, the script answers it. If it can’t, someone writes it down once.

The generated files are gitignored and rebuilt whenever we need them. Edit one by hand and your change vanishes at the next rebuild. A tracked manifest records what the script produced, which is how we can tell when the generated files drift from the YAML. The only way to change what the server says is to change the YAML and regenerate.

The rules for writing that YAML (quoting, negative rules, the internal escape hatch, and the check that compares declared imports against what the package really exports) live in Shipping LLM Prompts as a Build Artifact, Not a Doc. That post covers the pattern. This one covers the server on the other end.

A well-formed answer isn’t always a true one

A fixed structure guarantees the answer will look the same every time. A checker can prove that. It can’t prove the contents are correct. Those are two separate problems, and we ran into both.

The first one: a perfectly valid answer containing junk. One tool result passed every check and still held a string that was useless to anyone reading it. The mistake was sitting in the YAML all along, and no structure check would ever have caught it. The cause and the fix belong to the writing side, and they’re in the post linked above.

The second one was sneakier. get_component('select') told us the component had a [multiple] input for picking several options. It didn’t. On the branch we were working on, select only allowed one choice. Multi-select had moved into its own multi-select component. No error. The answer came back in perfect shape, sounding sure of itself, and it was wrong.

One is a bad-content bug. The other is an out-of-date bug. Same lesson, though. A fixed structure controls what an answer looks like. It says nothing about whether the answer is true right now. Good schema design fixes the first problem. For the second you need something else: refreshing the data, tracking versions carefully, or a plain rule that says “check the source when it matters.”

The mistake is treating them as one problem and calling it done once the structure checks pass. “The tool answered” and “the tool answered correctly, today” are different claims. Keep them apart.

The stale-install trap

The second incident had nothing to do with the docs. It was about when they were built.

The running server doesn’t read your branch. It answers from a snapshot, frozen at whatever version was last installed globally:

npm install -g ui-lib-mcp@latest

That’s the whole mechanism. What the server says is only as fresh as your last global install.

On our branch, select had already lost its [multiple] input. The installed server still listed it, because it was serving an older build. That older build was perfectly accurate for its own time. And the YAML on our branch was right the whole time. The server just wasn’t reading from it.

Old versions causing trouble is nothing new. What changes is who’s reading. A person with a stale doc usually gets a gut feeling and checks. An assistant has no memory of last month’s version, no idea a component was renamed, and no reason to doubt an answer that arrives neatly formatted. Unless it’s told to double-check, it won’t.

So we landed on a blunt rule. Any claim about the API that’s going into real work gets checked against the source or the current YAML. A live server call alone isn’t enough. The server is there to make life easier. The source is still the source.

Making the extraction repeatable

Everything the server says is derived from something else, so the step that pulls out those facts really matters. Compodoc covers the structural facts, as described above. A second pipeline, extract-api.ts, uses the TypeScript Compiler API to build the model the tool answers come from. We built and tested it on a feature branch that isn’t merged or pushed yet. The debugging was real, but the changes aren’t in the main code. Three things we learned apply to anyone building a server like this.

Order matters, even for calls that look harmless. ts.getPreEmitDiagnostics(program) sounds like a read-only question: what errors does the compiler see? It isn’t. Running a full type check changes the compiler’s internal state, and that changes how union types (like A | B) get written out as text. When we ran the check before extracting, the output shifted on every run, even though nothing in the code had changed. The fix was just reordering. Extract first, then run the check. The safety check still stops everything before any file is written. It just no longer disturbs the thing it’s supposed to be checking.

const extracted = extractFromProgram(program); // extract first, so the compiler works the natural way
const diagnostics = ts.getPreEmitDiagnostics(program).filter(isRealPhantomDep);

if (extracted.componentCount === 0)
  throw new Error("extraction floor breached");

Our error filter was too broad. The first idea was to fail the build on any “can’t find this module” error, to catch dependencies that aren’t actually installed. It broke the build. One of our migration files imports Node’s built-in path module, and our setup doesn’t include the Node type definitions. The compiler reports that exactly the same way as a truly missing npm package. We could have excluded that one file by name. That would have worked until the next legitimate built-in import showed up somewhere else. So we filter by the import’s name instead, skipping anything on Node’s own builtinModules list. That fixes the whole category, and we still catch real missing packages.

A canary test tells you less than it feels like. Ours asks one thing: does ButtonComponent still come out with more than zero inputs? That catches a total collapse. It won’t notice one component quietly losing a single field while everything else looks fine. A single “still basically works” test is comforting and not enough. Add a narrower check next to it. Here, that means the filtered diagnostics working properly before you call the extraction repeatable.

Notice what all three have in common. None of them crashed. They were all quiet. Valid-looking results with junk inside. A passing run with one field missing. A live server serving last month’s API.

What we’d do differently

Starting over, the code would barely change. The order we did things in would.

Freshness would be part of the design from day one. We designed the shape carefully, with a spec, seven named tools and a reviewed result type. Freshness we discovered one incident at a time, which is backwards. If every answer carried the version it was built from, you could tell whether it’s current just by looking at it, instead of trying to remember when you last ran a global install. Stale snapshots aren’t exotic. They’re what you get by default when you serve derived content.

Stale answers would be loud. Right now an old snapshot looks identical to a fresh one. The only clue is a bug in generated code later on. Something that says which build answered, or fails visibly when the snapshot and the working branch disagree, costs far less than the debugging session it prevents.

The canary and the narrower check would be written together. The canary came first because it was the obvious test, and it did its job. But we only found out it misses single-component damage by watching one component lose a field while every check stayed green. Write the narrow check the same afternoon, not after the first quiet failure.

Shape and truth would be reviewed separately. A checker can prove shape, so we check it. Truth needs a different habit: verify API claims headed for real work against the source or the current YAML, and never treat a live tool call as the final word. It’s one rule, it costs nothing in CI, and it would have caught the [multiple] mistake before it reached a generated file.

We’d stop assuming our checking tools are neutral. The compiler API has side effects. An error filter can be right in spirit and too wide in practice. A YAML parser follows its own syntax rules, whatever the author meant. Every green result in this project came from one of those tools, and the interesting failures all hid behind that trust.

The design stayed simple from the start. YAML is the only thing a person edits. Compodoc supplies the code facts. One script produces the output, and that same output feeds both the live server and the npm package. The hard part was never the shape of it. It was getting every layer around it to respect the source, and remembering that “the tool answered” and “the tool answered correctly” are different things.

If you want the writing rules behind the YAML, they’re in Shipping LLM Prompts as a Build Artifact, Not a Doc. Checking that an assistant actually uses all of this correctly is its own problem which I’ll cover in a future post.

Flow diagram

References & Sources