Blog
  • AI Gateway
  • AI Security
  • AIOps
  • API Security
  • API Gateway
|
    • API Management
    • API Development
    • API Design
    • Automation
    • Service Mesh
    • Insomnia
    • View All Blogs
  1. Home
  2. Blog
  3. Engineering
  4. A Developer's Guide to MCP Servers: Bridging AI's Knowledge Gaps
Engineering
January 26, 2026
14 min read

A Developer's Guide to MCP Servers: Bridging AI's Knowledge Gaps

Adam DeHaven
Senior Staff Software Engineer, Kong

Have you ever asked an AI assistant to generate code for a framework it doesn't quite understand? Maybe it produces something that looks right, but the syntax is slightly off, or it uses deprecated patterns. The AI is working hard, but it lacks the specific context it needs to truly help you.

The Model Context Protocol (MCP) was designed to bridge this knowledge gap by giving AI assistants access to domain-specific knowledge and capabilities they don't have built in.

What is MCP?

MCP is an open standard that defines how AI clients communicate with remote servers. It provides a standardized protocol for clients like Claude, Cursor, or VS Code to access tools, resources, and capabilities from external systems.

Currently, MCP servers can expose several types of capabilities to AI clients:

  1. Resources: Data that can be read by clients, such as documentation, configuration files, or API responses
  2. Tools: Functions that the AI can call to perform actions, fetch data, or validate content
  3. Prompts: Pre-built structured message templates and instructions that help users accomplish specific tasks

The protocol continues to evolve, with multiple specification versions released in 2025 and a draft spec for future capabilities. The three core primitives above form the foundation, but expect the ecosystem to grow over time.

Why build your own MCP server?

MCP works best when you build servers tailored to your specific domain. While the ecosystem includes servers for many common integrations and data sources, you or your organization likely has unique requirements that may warrant a custom implementation.

Consider these scenarios:

  • Your team needs AI to access company-specific data or internal tools
  • You want to automate workflows that span multiple systems (CI/CD, issue tracking, deployments)
  • You have domain expertise or specialized knowledge that AI assistants lack
  • Your organization uses internal APIs or services that need to be integrated with AI workflows

For each of these, you could build an MCP server that teaches AI assistants exactly what they need to know.

A real-world example: The MDC syntax helper

Let's walk through a real example: an MCP server we are building for the Kong Developer Portal.

Kong's Dev Portal allows customers to create custom pages using MDC Syntax to supercharge Markdown and give customers the ability to integrate Vue components with slots and props inside their Markdown. Users can build hierarchical page structures with rich components, custom metadata, and styled content blocks to create a fully branded developer experience.

The problem? AI assistants don't inherently understand MDC syntax or know what components are available. When users ask their AI assistant or MCP client for help creating portal content, client might generate invalid syntax or suggest components that don't exist.

This matters because MDC isn't just about formatting text. Customers use it to create professional branded pages with full-width hero sections, responsive feature grids, stylized cards, and more.

Here's what a simple hero section looks like in MDC:

And here's how the same hero section renders in the portal:

Without understanding MDC syntax and the available components, AI assistants can't help users build these content sections or full pages effectively.

The MCP server we are building bridges this knowledge gap by exposing tools that teach AI clients about MDC syntax, provide component examples and metadata, bundle resources for offline reference, and validate syntax to catch errors before they reach users.

Tools that teach AI assistants about MDC

  • A syntax guide that returns the complete MDC documentation
  • A component listing that fetches all available components from the portal's API
  • Component metadata retrieval for props, slots, and type information
  • Usage examples for each component showing real-world patterns
  • A syntax validator that checks generated MDC and reports errors with line numbers and detailed messages

Static resources for offline reference

  • Bundled markdown documentation for offline access
  • Design token reference for consistent styling

Putting it all together: The AI client workflow

When a user asks for help creating portal content, the AI client will follow a natural workflow:

  1. Calls the syntax guide to understand MDC rules and structure
  2. Discovers available components and fetches their metadata (props, slots, interfaces)
  3. Reviews real usage examples to see patterns in action
  4. Generates the content and runs it through the validator to catch syntax errors

The end result is validated MDC content using real portal components with proper syntax, branded styling, and ready to publish.

You can use this same pattern whenever you have a custom syntax, component library, or API that AI needs to understand. An MCP server helps AI assistants work with your specific tools and formats.

Building an MCP server

Let's build an MCP server from scratch. We'll use TypeScript and deploy to Cloudflare Workers using their Agents SDK, which works well for remote MCP servers.

Project setup

First, create a new project and install dependencies:

Install the required dependencies:

And the dev dependencies:

Here's what each package does:

  • @modelcontextprotocol/sdk: The official MCP SDK for building servers
  • agents: Cloudflare's Agents SDK for building MCP servers on Workers
  • zod: Schema validation for tool input parameters
  • wrangler: Cloudflare's CLI for local development and deployment

TypeScript configuration

Create a tsconfig.json:

Wrangler configuration

Create a wrangler.toml file to configure your Cloudflare Worker:

A few things to note:

  • The rules section above tells Wrangler to bundle any .md files as text, which is useful if you want to include documentation directly in your server
  • The Durable Objects configuration gives each MCP server instance its own persistent state
  • You can define separate environments (e.g., [env.dev] and [env.prod]) if you want isolated deployments for development versus production

The MCP server

Now let's create the server. Create src/index.ts and we'll build it step by step.

Imports and types

Start with the imports and a state interface for your server:

The Agent class provides the foundation for stateful Workers. The createMcpHandler function generates an HTTP handler that speaks the MCP protocol. If you need to persist data across requests, you can add properties to the State interface.

The Agent class

Next, create your server class that extends Agent:

The McpServer instance holds your server's metadata and handles tool and resource registration. Clients see this name and description when they connect.

Important: The description field should guide AI clients on how to use your server effectively. Include which tools to call first, any prerequisites, and the typical workflow sequence. AI clients use this to understand the intended usage pattern, so prioritize the most important information at the beginning.

Registering tools

The onStart() lifecycle method is where you register all your tools and resources.

Here's an example of a tool that fetches component metadata from our API.

First, define the tool metadata with input and output schemas:

Then implement the handler that fetches and returns the metadata:

Tools have three parts: a name, metadata with input/output schemas, and an async handler. The outputSchema defines the structure of structuredContent, which AI clients can parse programmatically alongside the human-readable content.

This example demonstrates the basic pattern for tools that fetch external data: validate input, make the API request, handle errors with isError: true, and return both human-readable text and structured data.

Tool description best practices: Keep descriptions concise (1-2 sentences) and prioritize the most important information first. Specify when/why to use the tool, any prerequisites, and its place in the workflow. This helps AI clients understand the intended usage pattern.

Registering resources

Resources expose data that clients can read on demand. Extend the onStart() method to also register resources:

Resources are identified by a custom URI scheme (like mdc://docs/components). Unlike tools which AI calls on demand, resources are typically read once when the client needs reference material. Resource descriptions work the same way: be concise, specify when to use the resource, and mention any prerequisites or workflow context.

Handling MCP requests

Add a method to your MyMcpServer class to handle incoming MCP protocol requests:

The createMcpHandler function takes your McpServer instance and returns an HTTP handler that implements the MCP protocol. This handles the bidirectional messaging between clients and your server.

The fetch handler

Finally, export a default handler that routes requests to your MCP server:

The getAgentByName function retrieves (or creates) a Durable Object instance for each session. This gives each connected client its own isolated state. The session ID is in the mcp-session-id header, or you can generate one for new connections.

What's happening under the hood

To summarize the architecture:

  1. Agent class: Extends Agent from the Cloudflare Agents SDK, giving you access to Durable Object state and lifecycle hooks
  2. McpServer instance: Holds your server metadata and registered tools/resources
  3. onStart() lifecycle: Called when the Agent initializes, perfect for registering capabilities
  4. createMcpHandler(): Generates an HTTP handler that implements the MCP protocol
  5. getAgentByName(): Retrieves the Agent instance by session ID, enabling per-client state

Adding persistent session state

The basic example above works well for stateless servers, but production MCP servers often need to persist session state across requests. For this, you can add a WorkerTransport with Durable Object storage.

First, update your imports:

Then add a transport instance to your Agent class:

Finally, update your onMcpRequest() method to pass the transport to createMcpHandler:

The WorkerTransport uses your Durable Object's storage to persist session state between requests. This enables advanced MCP features like elicitation (asking the user for input) and sampling (requesting AI completions from the client). For most servers, the basic stateless approach is sufficient, but adding WorkerTransport gives you the full capabilities of the MCP protocol.

Adding more sophisticated tools

Tools can also perform complex operations like parsing and validation. Here's a MDC validator that checks for syntax errors, validates component structures, and ensures nested components are properly formed.

First, define the tool metadata with schemas for validation results:

Then implement the validation logic using a stack to track nested components:

This validator demonstrates more sophisticated tool logic:

  • Uses a stack to track nested components and ensure proper nesting
  • Validates that opening and closing tags have matching colon counts
  • Returns structured error data with specific line numbers
  • Provides both human-readable summaries and programmatic access via structuredContent

Organizing tools and resources

As your MCP server grows, you'll want to organize tools and resources into separate files. A pattern that works well is creating a Registrable interface:

Then each tool or resource becomes its own class:

And in your main file:

This keeps your code organized and makes it easy to add or remove functionality.

Seeing it in action

Once your MCP server is connected to a client like Claude or Cursor, here's what happens. A user might ask:

The AI client automatically reads your component_docs resource to learn about page-hero and card components, generates the MDC content, and then calls your validate_mdc_syntax tool to ensure the syntax is correct before presenting it to the user. The user never needs to know which tools were called or how the MCP protocol works behind the scenes.

Local development and deployment

Running locally

Add scripts to your package.json:

Start the local development server:

Your MCP server is now running at http://localhost:8787. You can test it by:

  1. Pointing an MCP client to http://localhost:8787/mcp
  2. Using the MCP Inspector to explore your server's capabilities
  3. Making direct HTTP requests to test specific endpoints

To get up and running right away with the MCP Inspector UI, just execute the following:

The server will start up and the UI will be accessible at http://localhost:6274.

Deploying to Cloudflare

When you're ready to deploy:

Wrangler will deploy your Worker and provide you with a workers URL like: https://my-mcp-server.your-account.workers.dev. You can then configure your MCP clients to connect to this URL, or map the Worker to a custom hostname or even a path on your existing domain.

Connecting MCP clients

Remote MCP servers use Streamable HTTP for communication. This transport uses a single /mcp endpoint for bidirectional messaging between clients and your server.

Most MCP clients can be configured to connect to remote servers by providing your server's URL with the /mcp path:

https://my-mcp-server-prod.workers.dev/mcp

The specific configuration steps vary by client. For detailed setup instructions, consult the documentation for your MCP client.

How clients discover capabilities

When a client connects to your MCP server, it requests the available tools and resources. This means you don't need to manually configure what capabilities are available. The client will:

  1. Connect to the server and complete the protocol handshake
  2. Request the list of available tools with their schemas
  3. Request the list of available resources
  4. Make these capabilities available to the AI model

The AI can then decide when to use each tool based on the user's request and the tool's description.

Other MCP server use cases

The MDC syntax helper is just one example. Developers are building MCP servers to solve real problems across their organizations.

For internal development:

  • Company design system documentation and code generation
  • Internal API usage guides and validation
  • Coding standards and architecture pattern enforcement
  • Private library and tooling documentation

For developer workflows:

  • CI/CD pipeline integration and deployment automation
  • Issue tracking and project management (Jira, Linear, GitHub)
  • Error tracking and debugging tools (Sentry, Rollbar)
  • Code review and repository management

For business operations:

  • Internal knowledge base and documentation search
  • Customer data and CRM integration
  • Analytics dashboard and data warehouse queries
  • Company-specific workflow and process automation

You can browse available servers at the MCP Servers repository.

Wrapping up

Building an MCP server lets you extend AI capabilities with domain-specific knowledge. By deploying to Cloudflare Workers, you get a globally distributed, low-latency server that scales automatically.

The key steps are:

  1. Identify the domain knowledge AI assistants are missing
  2. Set up a Cloudflare Worker project with the Agents SDK and MCP SDK
  3. Create an Agent class with tools (using Zod schemas) and resources
  4. Test locally with wrangler dev and the MCP Inspector
  5. Deploy to Cloudflare and configure your MCP clients to connect via the /mcp endpoint

For more information, check out:

  • Model Context Protocol documentation
  • Cloudflare Agents SDK documentation
  • MCP specification

If you have questions or want to share what you've built, feel free to reach out on Bluesky or X.

MCPAIDeveloper PortalLLM

Table of Contents

  • What is MCP?
  • Why build your own MCP server?
  • A real-world example: The MDC syntax helper
  • Building an MCP server
  • Local development and deployment
  • Connecting MCP clients
  • Other MCP server use cases
  • Wrapping up

More on this topic

Videos

From APIs to AI Agents: Building Real AI Workflows with Kong

Videos

Context‑Aware LLM Traffic Management with RAG and AI Gateway

See Kong in action

Accelerate deployments, reduce vulnerabilities, and gain real-time visibility. 

Get a Demo
Topics
MCPAIDeveloper PortalLLM
Share on Social
Adam DeHaven
Senior Staff Software Engineer, Kong

Recommended posts

AI Voice Agents with Kong AI Gateway and Cerebras

EngineeringNovember 24, 2025

Kong Gateway is an API gateway and a core component of the Kong Konnect platform . Built on a plugin-based extensibility model, it centralizes essential functions such as proxying, routing, load balancing, and health checking, efficiently manag

Claudio Acquaviva

AI Guardrails: Ensure Safe, Responsible, Cost-Effective AI Integration

EngineeringAugust 25, 2025

Why AI guardrails matter It's natural to consider the necessity of guardrails for your sophisticated AI implementations. The truth is, much like any powerful technology, AI requires a set of protective measures to ensure its reliability and integrit

Jason Matis

Move More Agentic Workloads to Production with AI Gateway 3.13

Product ReleasesDecember 18, 2025

MCP ACLs, Claude Code Support, and New Guardrails New providers, smarter routing, stronger guardrails — because AI infrastructure should be as robust as APIs We know that successful AI connectivity programs often start with an intense focus on how

Greg Peranich

Securing Enterprise AI: OWASP Top 10 LLM Vulnerabilities Guide

EngineeringJuly 31, 2025

Introduction to OWASP Top 10 for LLM Applications 2025 The OWASP Top 10 for LLM Applications 2025 represents a significant evolution in AI security guidance, reflecting the rapid maturation of enterprise AI deployments over the past year. The key up

Michael Field

Build Your Own Internal RAG Agent with Kong AI Gateway

EngineeringJuly 9, 2025

What Is RAG, and Why Should You Use It? RAG (Retrieval-Augmented Generation) is not a new concept in AI, and unsurprisingly, when talking to companies, everyone seems to have their own interpretation of how to implement it. So, let’s start with a r

Antoine Jacquemin

Training AI Models to Invoke APIs: The Gorilla Project Offers Next Evolution of Language Models

EngineeringDecember 13, 2023

The Gorilla Project is innovating how LLMs interact AI has been taking the world by storm. The innovative technology is responsible for revolutionizing the way users can synthesize information through Large Language Models (or LLMs) and interact w

Peter Barnard

Insights from eBay: How API Ecosystems Are Ushering In the Agentic Era

EngineeringDecember 15, 2025

APIs have quietly powered the global shift to an interconnected economy. They’ve served as the data exchange highways behind the seamless experiences we now take for granted — booking a ride, paying a vendor, sending a message, syncing financial rec

Amit Dey

Ready to see Kong in action?

Get a personalized walkthrough of Kong's platform tailored to your architecture, use cases, and scale requirements.

Get a Demo
  • Terms
  • Privacy
  • Trust and Compliance
  • © Kong Inc. 2026