Skip to content
FEATURED

Building UX-KB: A Workflow-Aware MCP Knowledge Base for AI Agents

MCPAI EngineeringDeveloper Tools

Building UX-KB: A Workflow-Aware MCP Knowledge Base for AI Agents

Building an MCP-powered knowledge service that helps AI coding agents retrieve structured UI/UX guidance, follow design workflows and check whether their cited documents were actually retrieved.


The Problem with AI-Generated Interfaces

AI coding agents can generate React components, write CSS and build complete pages from a prompt.

But generating an interface does not automatically mean making good design decisions.

Ask an agent to build a dashboard and you may get a familiar result: a few cards, a gradient background, generic typography and a standard layout. The page might work, but important questions can remain unanswered.

  • Is the information hierarchy clear?
  • Have accessibility requirements been considered?
  • Does the interface handle loading, empty and error states?
  • Is the mobile experience planned?
  • Can the agent explain why it chose a particular design?

I wanted to address this problem by giving coding agents access to structured design knowledge instead of expecting them to rely entirely on their existing model knowledge.

That led me to build UX-KB, an MCP-powered UI/UX knowledge base for AI coding agents.

The project is available at ux-kb-site.vercel.app.


A normal documentation website helps developers find information, but an AI coding agent needs a structured way to retrieve the right guidance while performing a task.

For example, an agent auditing an existing checkout page needs different guidance from an agent implementing a new navigation system.

Sending the entire knowledge base to every request would also introduce unnecessary context.

I wanted a system where:

  1. Knowledge could be retrieved through MCP tools.
  2. The retrieved documents could depend on the current workflow stage.
  3. Feature-specific guidance could be included when needed.
  4. The agent could check whether its cited document IDs were actually retrieved.
  5. Missing knowledge could be reported instead of silently invented.

This is why I chose the Model Context Protocol as the connection layer.


The Architecture: MCP Server + Core Services + Knowledge Repository

I separated the MCP delivery layer from the core knowledge services.

The MCP server exposes tools and resources, while the core handles document retrieval, stage packs, sessions, citations, authentication and storage.

The architecture has a few important parts:

  • MCP server: Exposes tools and resources to compatible AI clients.
  • Core services: Own retrieval, workflow packs, sessions and validation.
  • Content repository: Stores structured Markdown knowledge documents.
  • KbStore: Provides a storage boundary with in-memory and Prisma-backed implementations.
  • PostgreSQL: Persists application data such as users, keys, usage and knowledge gaps.

The MCP layer is the delivery mechanism; the core owns the application logic.

This makes it possible to reuse the same services across the local MCP server and hosted Next.js application.


Building the Knowledge Structure

The first version of the knowledge base needed a structure that an agent could understand and retrieve efficiently.

UX-KB currently contains:

ComponentCount
Topic documents73
Workflow stage packs6
Feature routes10
MCP tools7
MCP resources3

Instead of organizing everything as one large document collection, I divided the knowledge into six workflow stages.

StagePurpose
need_checkUnderstand the problem and decide whether the feature is needed
researchResearch users, patterns, competitors and evidence
auditReview the existing interface and identify problems
proposalPrepare the design direction and recommendations
critiqueIndependently evaluate the proposed solution
implementPrepare the implementation after approval

Each stage pack provides guidance relevant to that part of the workflow.

Feature routing can bring in additional documents depending on what the agent is designing.

The stage packs also estimate token usage and flag packs that exceed their configured budget. These are approximate estimates, not model-specific token counts.


The MCP Tools: Giving Agents a Structured Workflow

The next step was exposing the knowledge base through MCP tools.

UX-KB provides seven tools.

ToolResponsibility
start_sessionStart a task-specific knowledge session
get_stage_packRetrieve documents for a workflow stage
get_docRetrieve an individual topic document
search_kbSearch available knowledge
get_checklistRetrieve checklist items from selected documents
verify_citationsCheck cited document IDs against session retrieval history
report_gapRecord missing knowledge topics

It also exposes three MCP resources:

kb://doc/{id}
kb://pack/{stage}
kb://core

These provide access to individual documents, workflow packs and the core agent rules.

How an agent uses UX-KB

The intended workflow is:

  1. Start a session.
  2. Retrieve the stage pack before working on that stage.
  3. Fetch additional topic documents when necessary.
  4. Use the retrieved guidance to prepare recommendations.
  5. Verify citations before submitting the result.
  6. Report missing topics when the knowledge base does not cover something.

The important part is that the agent does not have to receive all 73 documents for every task.


The Citation Problem: How Do We Know the Agent Retrieved Its Sources?

One of the important features I wanted was citation traceability.

An AI agent can write a document ID in its response, but that does not prove that it actually retrieved the corresponding document.

UX-KB handles this through session-based retrieval tracking.

When an agent retrieves a document using get_doc or get_stage_pack, the retrieved document IDs are recorded against the session.

Before submitting its recommendations, the agent can call:

verify_citations

The tool compares the cited IDs against the session's fetch history.

It can identify:

  • Documents that were retrieved during the session.
  • Cited IDs that were never fetched.
  • Unknown document IDs.
  • Deprecated document IDs.

This creates a traceable relationship between the knowledge retrieved by the agent and the references included in its response.

An important limitation

Citation verification does not prove that a document semantically supports the statement being made.

It verifies retrieval history, not the correctness of the AI-generated recommendation.

I consider that distinction important. A valid citation should not be presented as proof that a design decision is correct.


Making the Workflow More Than a Collection of Tools

I also added core agent rules to define how the knowledge should be used.

The core workflow requires the agent to:

  1. Understand the user problem and decide whether the feature should be built.
  2. Research the relevant users, patterns and evidence.
  3. Audit the interface against applicable UX and accessibility guidance.
  4. Prepare a design proposal with flows, components, states and responsive behavior.
  5. Perform an independent critique using the EVAL-009 rubric.
  6. Present the proposal and wait for explicit approval.
  7. Prepare implementation work only after approval.

The independent critic rubric uses an 85/100 readiness threshold, with critical defects overriding the numerical score.

This is an important design choice: the agent should not jump straight from a short prompt to implementation without first considering whether the proposed experience is appropriate.

The rules also require uncertainty to be stated and missing evidence to be identified rather than invented.


The Next Challenge: Hosting an MCP Server Securely

Running an MCP server locally is relatively straightforward.

Hosting one for multiple users introduces a different set of engineering concerns.

The server needs to identify callers, manage API keys, enforce access permissions and prevent uncontrolled resource consumption.

I added user accounts and scoped API keys with the following controls:

  • User-owned API keys.
  • API key expiry, rotation and revocation.
  • Request scopes.
  • Per-key rate limits.
  • Daily usage quotas.
  • Anonymous per-IP rate limits.
  • Request body and batch size limits.
  • Concurrency protection.
  • Usage and audit logging.

API keys use 192 bits of random data and are stored as HMAC-SHA256 hashes.

The plaintext key is shown only when it is created or rotated.

The hosted MCP endpoint also applies request restrictions, including:

POST only
Maximum request body: 256 KB
Maximum JSON-RPC batch size: 20

The service checks authorization and quotas before allowing MCP requests to proceed.

These controls are important because a remotely accessible MCP server is still an API. It needs proper authentication and resource protection.


Adding OAuth 2.1 for MCP Connectors

API keys work well when an MCP client supports a static authorization header.

However, some connectors use browser-based authorization instead.

To support that integration model, I added OAuth 2.1 and Dynamic Client Registration.

The implementation includes:

  • Authorization-server metadata discovery.
  • Protected-resource metadata.
  • Dynamic client registration.
  • Authorization and consent screens.
  • Authorization-code exchange.
  • PKCE using S256.
  • Refresh-token rotation.
  • Token revocation.

The implementation uses Prisma models for OAuth clients, authorization codes, grants and access tokens.

I also connected OAuth access to the existing API-key model through a hidden per-client key. This allows the existing session, usage and quota systems to remain consistent.

The relevant implementation work is recorded in:

OAuth 2.1 + DCR for MCP connectors


Improving the Knowledge Base: The 73-Document Audit

Building retrieval tools is only part of the problem.

If the documents contain repeated, vague or incomplete guidance, retrieving them correctly will not improve the agent's recommendations.

During the content audit, I worked through the knowledge documents and identified areas that needed more specific guidance.

The changes included:

  • Replacing repeated generic failure modes and decision sections with topic-specific content.
  • Adding document-level sources and related links.
  • Resolving overlapping rules through clearer ownership.
  • Filling accessibility documentation gaps.
  • Updating relevant WCAG 2.2 guidance.
  • Adding concrete values and good/bad examples.
  • Improving ARIA and WCAG terminology in component guidance.
  • Adding an independently retrievable critic rubric.

I also added EVAL-009 Independent Critic Rubric and updated the core knowledge reference.

The changes were applied across all 73 topic documents.

View the 73-document content audit commit

This was one of the most important parts of the project for me.

A larger knowledge base is not automatically a better knowledge base. The content needs to be specific, maintainable and useful to the agent retrieving it.


Testing the MCP Server

I wanted the project to be testable without requiring a full database setup for every local development task.

The repository includes separate checks for knowledge quality, TypeScript, core services, MCP transports and the web application.

The main commands are:

# Validate all knowledge documents
pnpm lint:kb:strict

# TypeScript checks across packages
pnpm typecheck

# Core unit tests
pnpm test

# MCP stdio smoke tests
pnpm smoke

# HTTP authentication and endpoint smoke tests
pnpm smoke:http

# Production build
pnpm --filter @ux-kb/web build

The documented testing guide covers session retrieval, citation verification, invalid API keys, rate limiting, revocation and the dashboard authentication flow.

The test commands are part of the repository's development workflow rather than relying only on manual checks.


What I Learned While Building UX-KB

There were a few lessons that stood out during development.

1. More context does not always mean better output.

Agents need relevant information at the right stage, not every available document in every request.

2. Retrieval and verification are different problems.

Finding a document is one thing. Checking whether it was actually retrieved during a session is another. Neither alone guarantees that a generated recommendation is correct.

3. Knowledge quality needs its own engineering process.

Documents require validation, source references, clear ownership and regular audits.

4. MCP authentication becomes important when moving beyond local development.

A hosted service needs key management, quotas, revocation and protection against resource abuse.

5. The agent needs a process, not just a list of tools.

The six workflow stages and approval gate help define how the knowledge should be used, rather than leaving every decision to an unstructured prompt.


What I Would Improve Next

There are still areas I want to develop further.

  • Add semantic evaluation to measure whether retrieved documents actually support generated recommendations.
  • Expand automated knowledge-quality checks.
  • Improve retrieval-quality observability.
  • Add more repeatable evaluation scenarios.
  • Integrate automated accessibility testing to complement written guidance.
  • Continue expanding the knowledge base based on reported gaps.

These are future improvements, not features I am claiming are already complete.


Final Thoughts

UX-KB started with a simple question: what if AI coding agents could consult structured UX knowledge instead of relying entirely on what they already know?

The result is an MCP-powered knowledge service with stage-based retrieval, session tracking, citation-history verification, local and remote transports, API-key authentication and OAuth 2.1.

The biggest lesson was that connecting an AI agent to documentation is only the beginning.

The real work is making that knowledge relevant, traceable, maintainable and safe to access.

If you are building MCP servers or AI coding tools, these are the problems worth thinking about early.

Explore UX-KB: Live website · GitHub repository


Technical References

Live ProjectSource Code

Was this case study helpful?

Comments

Be the first to comment

Be the first to share your thoughts.