Skip to content

Building an MCP Server for AI-Powered UX Knowledge Retrieval

I started UX-KB with a collection of Markdown documents, but storing UX knowledge was only half the problem. I needed a way for AI coding agents to discover and retrieve the right guidance at the right time. In this article, I share how I built UX-KB as an MCP server, using tools, resources, and session-aware retrieval to make structured UX knowledge accessible within AI development workflows.

MCPModel Context ProtocolAI Coding Agents

Building an MCP Server for AI-Powered UX Knowledge Retrieval

When I started building UX-KB, I had a simple idea: create a structured collection of UX knowledge that AI coding agents could use while building interfaces.

I started with Markdown documents.

The documents covered topics such as accessibility, forms, navigation, feedback, loading states, empty states, error handling, and other interface design decisions.

That was a good starting point. But as the knowledge base grew, I started thinking about a different problem.

How would an AI coding agent know which document to read, when to read it, and how to use that knowledge during a development workflow?

Asking an agent to read a large collection of Markdown files wasn't a practical solution. I needed a more structured way to expose that knowledge.

That led me to build UX-KB as an MCP server.

Why Markdown files alone weren't enough

Markdown is a great format for storing knowledge.

It is readable, easy to maintain, version-friendly, and works well with Git. But storing knowledge and making it accessible to an AI agent at the right time are two different problems.

Imagine asking an AI coding agent to build a registration form.

The agent might need guidance about:

  • Form structure and field grouping.
  • Labels and accessible input descriptions.
  • Required and optional fields.
  • Validation timing and error messages.
  • Keyboard navigation.
  • Loading and submission feedback.
  • Success and failure states.

All this information might exist in separate documents.

Without a retrieval mechanism, the agent has to rely on its existing context, manually supplied instructions, or broad document access.

I wanted something different: an agent should be able to request the relevant knowledge as it works.

Why I chose MCP

I chose the Model Context Protocol (MCP) because it provides a standard way for AI applications to interact with external tools and resources.

Instead of building a custom integration for every AI coding agent, I could expose UX-KB through an MCP server.

The server could provide two important capabilities:

Tools

Tools let an agent perform specific actions, such as searching the knowledge base, retrieving a document, or checking a citation.

Resources

Resources expose structured information through stable URIs, allowing an MCP client to access knowledge in a predictable way.

This gave me a clear separation between storing UX knowledge and making it available to AI agents.

UX-KB architecture

I designed the architecture around a shared core rather than putting all the business logic directly inside the MCP handlers.

The shared core is responsible for knowledge retrieval, document access, workflow stage packs, routing, sessions, and citation handling.

The MCP layer exposes those capabilities to connected clients.

The project uses TypeScript, Next.js, Prisma, and PostgreSQL, with separate entry points for local and hosted usage.

Architecture overview

The important design decision was keeping the knowledge and retrieval logic in the shared core.

That means the local and hosted MCP entry points can use the same underlying capabilities instead of maintaining separate implementations.

Seven tools for accessing UX knowledge

I exposed seven tools through the MCP server.

Each tool has a specific responsibility.

1. start_session

Starts a knowledge session for the agent.

A session establishes the context needed for subsequent retrieval and pins the knowledge base version used during that session.

This helps keep document references consistent while the agent is working.

2. get_stage_pack

Retrieves the guidance associated with a particular workflow stage.

Instead of giving the agent every UX guideline at once, the server can provide a focused collection of relevant guidance.

3. get_doc

Retrieves a specific UX knowledge document.

This is useful when the agent already knows which topic it needs.

4. search_kb

Searches the knowledge base for relevant UX topics.

The retrieval process uses keyword-based scoring to help identify relevant documents without requiring the agent to browse the entire repository.

5. get_checklist

Returns a checklist for a particular UX task.

For example, an agent working on a form can use a checklist to review important implementation considerations.

6. verify_citations

Checks whether document references used by the agent are known, fetched within the relevant history, or deprecated.

An important distinction: this validates citation references and their history. It does not prove that a cited document semantically supports every statement made by the agent.

7. report_gap

Allows the agent to report missing or insufficient UX knowledge.

This creates a feedback path for identifying areas where the knowledge base needs improvement.

Together, these tools allow agents to search, retrieve, apply, and reference UX knowledge through a consistent interface.

Three resources for structured access

Alongside tools, I exposed three MCP resources.

Resource URIPurpose
kb://doc/{id}Access an individual knowledge document
kb://pack/{stage}Access a workflow stage pack
kb://coreAccess core UX knowledge and guidance

I kept the resource structure predictable so clients can access documents and workflow guidance through stable identifiers.

Tools and resources serve different purposes: tools perform actions, while resources expose information.

Local and remote MCP connections

I wanted UX-KB to support more than one connection method.

Local connection — STDIO

The local STDIO entry point allows an MCP client to launch and communicate with the server through standard input and output.

This is useful for developers who want to run UX-KB locally and connect it to a compatible AI coding tool.

Remote connection — Streamable HTTP

I also implemented a hosted MCP entry point using Streamable HTTP.

This allows compatible clients to connect to a remotely hosted server instead of running the server process locally.

Supporting both approaches makes the same knowledge capabilities available across different development environments.

What does retrieval look like in practice?

Let's return to the registration form example.

An agent begins working on a registration page.

Instead of loading all 73 knowledge documents, the interaction can follow a more focused process:

  1. The agent starts a session using start_session.
  2. It identifies the current workflow stage.
  3. It requests relevant guidance using get_stage_pack.
  4. It searches for specific topics using search_kb.
  5. It retrieves detailed guidance using get_doc.
  6. It uses get_checklist to review the implementation.
  7. It checks document references using verify_citations.

If the agent discovers that an important topic is missing, it can use report_gap.

The goal is not to make the agent blindly follow a large set of instructions. It is to give it access to relevant UX knowledge when that knowledge is needed.

A few engineering decisions that mattered

Building the MCP server involved more than exposing a few functions.

Some of the decisions I made were:

1. Keep the core independent of the transport

The shared core owns the retrieval and knowledge logic. MCP entry points handle how clients communicate with it.

2. Use workflow-specific guidance

The knowledge base is organized around six stages: need check, research, audit, proposal, critique, and implement.

This gives the agent a more relevant starting point depending on the work it is doing.

3. Keep sessions version-aware

A session pins a knowledge base version. This helps prevent a single workflow from unexpectedly mixing document versions.

4. Make citations checkable

Document references should not simply be accepted without validation. The citation verification tool checks whether references are known and whether they appear in the relevant retrieval history.

5. Treat missing knowledge as useful feedback

The report_gap tool provides a way to identify missing guidance rather than silently relying on incomplete knowledge.

What this approach does not solve

I also want to be clear about the limitations.

  • Keyword-based retrieval is not the same as perfect semantic understanding.
  • Citation validation does not guarantee that the cited content supports an agent's conclusion.
  • An MCP server can provide useful guidance, but it cannot guarantee that an agent will follow every recommendation correctly.
  • The quality of the output still depends on the quality of the underlying knowledge and how the agent uses it.

These are important distinctions. I see UX-KB as a way to make UX knowledge more accessible and structured, not as a replacement for design judgment or human review.

What's next?

Building the MCP server changed how I think about AI-assisted development.

I initially focused on writing UX documentation. But the bigger challenge was making that documentation accessible at the right point in an agent's workflow.

That is what UX-KB is trying to solve.

The next part of this series will explore the six-stage workflow: why I organized UX knowledge around the stages of a task instead of exposing one large collection of guidelines.

If you're building AI coding agents or working with MCP, I'd be interested to hear how you're handling external knowledge retrieval in your own projects.

Explore UX-KB:


This is part of my UX-KB build series, where I share the engineering decisions, architecture, and lessons behind building a structured UX knowledge system for AI coding agents.

Was this post helpful?

Comments

Be the first to comment

Be the first to share your thoughts.