Skip to content
Back to the Lab

Model Context Protocol for Frontend Developers

Learn how frontend developers can integrate the Model Context Protocol (MCP) into AI-powered applications. Covers MCP architecture, building a client, rendering tool calls, multi-server connections, and OAuth authentication.

Model Context Protocol for Frontend Developers

Introduction#

Before late 2024, every integration between an AI model and an external tool was custom built. Want an AI assistant to query a PostgreSQL database, search a company’s Notion workspace, or create a ticket in Jira? Each connection required its own bespoke adapter, its own authentication handling, and its own maintenance burden. Multiply that across a dozen tools and a handful of AI providers, and the integration surface became unmanageable.

The Model Context Protocol (MCP), introduced by Anthropic in late 2024 and now governed by the Linux Foundation’s Agentic AI Foundation, solved this by defining a single open standard for how AI applications connect to external data sources and tools. By March 2026, MCP had surpassed 97 million monthly SDK downloads and is now supported natively by OpenAI, Google, Microsoft, and AWS.

For frontend developers, MCP is no longer a backend concern to delegate and forget. As AI features move from simple chat completions to genuinely agentic experiences embedded in product interfaces, understanding how MCP works and how to build against it is becoming core frontend knowledge. This guide explains what MCP actually is, how to build an MCP client into a frontend application, and the patterns that matter for production use.

What MCP Actually Solves#

The clearest way to understand MCP is the analogy most of the ecosystem has settled on: it is the USB C of AI applications. Before USB C, every device needed its own proprietary cable and port. USB C standardized the physical and electrical interface, so any compliant device works with any compliant cable.

MCP does the same thing for AI tool integration. Instead of an AI application writing custom code to talk to GitHub, Slack, and a company’s internal CRM, each of those services exposes an MCP server. The AI application implements an MCP client once, and that single client can connect to any MCP server, regardless of which company built it.

This standardization has produced a genuinely large ecosystem in a short period. As of early 2026, more than 10,000 public MCP servers exist across various registries, covering tools like GitHub, Slack, PostgreSQL, Figma, Stripe, and Docker.

Core Architecture#

MCP defines three architectural roles:

Host the AI application itself (a chat interface, an IDE, a custom product feature)

Client the component within the host that maintains a connection to an MCP server

Server the program that exposes tools, resources, and prompts from a specific data source or service

Communication happens over JSON RPC 2.0, using one of two transport mechanisms. stdio is used for local connections, where the server runs as a subprocess on the same machine. HTTP with Server Sent Events is used for remote connections, which is the transport relevant to most frontend integrations since the MCP server is typically running on a separate service.

An MCP server can expose three categories of capability:

Tools functions the AI model can call, such as search_database or create_ticket

Resources data the AI model can read, such as file contents or database records

Prompts reusable instruction templates that guide the model through specific multi step workflows

Building a Frontend MCP Client#

For frontend developers, the most common integration pattern is connecting a chat or agent interface to one or more MCP servers via a backend proxy, since exposing server credentials directly to the browser is a security risk.

Here is a minimal example using the official TypeScript SDK on the server side, with a Next.js API route acting as the bridge:

// app/api/chat/route.ts
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
import { streamText } from "ai";
import { anthropic } from "@ai-sdk/anthropic";

export async function POST(req: Request) {
  const { messages } = await req.json();

  // Connect to an MCP server (e.g. a company's internal tools server)
  const transport = new SSEClientTransport(
    new URL(process.env.MCP_SERVER_URL!)
  );
  const mcpClient = new Client({ name: "frontend-client", version: "1.0.0" });
  await mcpClient.connect(transport);

  // Discover available tools from the server
  const { tools } = await mcpClient.listTools();

  const result = streamText({
    model: anthropic("claude-sonnet-4-6"),
    messages,
    tools: convertMcpToolsToAiSdkFormat(tools),
  });

  return result.toDataStreamResponse();
}

The frontend chat component itself does not need to know anything about MCP. It sends messages and receives a stream, the same as any other AI SDK integration. The MCP layer lives entirely in the API route, which keeps credentials server side and the client code simple.

Rendering Tool Calls in the UI#

Where MCP becomes a genuinely frontend concern is in how tool calls and their results are surfaced to the user. A well designed interface does not just show a loading spinner while an MCP tool executes. It communicates what is happening.

function ToolCallDisplay({ toolCall }: { toolCall: ToolCall }) {
  const statusLabel = {
    pending: "Calling " + toolCall.toolName,
    success: "Completed " + toolCall.toolName,
    error: "Failed: " + toolCall.toolName,
  }[toolCall.status];

  return (
    <div className="tool-call-card">
      <ToolIcon name={toolCall.toolName} />
      <span>{statusLabel}</span>
      {toolCall.status === "success" && (
        <ToolResultPreview result={toolCall.result} />
      )}
    </div>
  );
}

Since MCP tools are dynamically discovered at connection time rather than hardcoded, the UI layer benefits from a registry pattern that maps tool names to specific render components, with a generic fallback for tools that do not have a custom view:

const toolRenderers: Record<string, React.ComponentType<{ result: unknown }>> = {
  search_database: DatabaseResultsTable,
  create_ticket: TicketConfirmationCard,
  fetch_document: DocumentPreview,
};

function ToolResultPreview({ toolName, result }: { toolName: string; result: unknown }) {
  const Renderer = toolRenderers[toolName] ?? GenericJsonViewer;
  return <Renderer result={result} />;
}

Handling Multiple MCP Servers#

Production AI features frequently need to connect to more than one MCP server simultaneously. A customer support assistant might need access to a CRM server, a knowledge base server, and a ticketing server at the same time. The host application aggregates tools from all connected servers into a single namespace presented to the model.

async function connectAllServers(serverConfigs: McpServerConfig[]) {
  const clients = await Promise.all(
    serverConfigs.map(async (config) => {
      const transport = new SSEClientTransport(new URL(config.url));
      const client = new Client({ name: config.name, version: "1.0.0" });
      await client.connect(transport);
      return { name: config.name, client };
    })
  );

  const allTools = await Promise.all(
    clients.map(async ({ name, client }) => {
      const { tools } = await client.listTools();
      // Prefix tool names to avoid collisions across servers
      return tools.map((tool) => ({ ...tool, name: `${name}__${tool.name}` }));
    })
  );

  return { clients, tools: allTools.flat() };
}

Namespacing tool names by server origin prevents collisions when two servers happen to expose a tool with the same name, and makes debugging easier when tracing which server handled a given call.

Authentication Considerations#

MCP servers that expose sensitive data or actions need proper authentication. The MCP specification supports OAuth 2.1 for remote server authentication, and most production MCP servers in 2026 implement it. For a frontend application, this typically means the OAuth flow happens during account connection, with the resulting access token stored server side and associated with the user’s session, never exposed to the browser.

A frontend “Connect your tools” settings page is a common pattern: the user clicks “Connect Slack,” is redirected through an OAuth flow, and the resulting token is stored against their account. The chat interface then transparently has access to that MCP server’s tools in future sessions without the user needing to reconnect each time.

Companion Protocol: AG UI#

While MCP standardizes how an agent talks to tools and data, a related but distinct protocol called AG UI standardizes how an agent communicates state and events back to the frontend interface itself. AG UI has been adopted by Google, AWS, Microsoft, and LangChain as an open event protocol for agent user interaction.

The distinction matters: MCP is about the agent’s connection to its capabilities. AG UI is about the agent’s connection to the interface the user is looking at. Teams building genuinely agentic frontend experiences, where the user can see an agent’s reasoning steps, intermediate tool calls, and live state updates, often use MCP and AG UI together: MCP on the backend connecting the agent to its tools, AG UI on the frontend streaming the agent’s activity into the UI in a standardized way.

Practical Adoption Guidance#

For frontend teams evaluating whether to invest in MCP integration now, the calculus is straightforward. If your product already has, or plans to have, an AI assistant or agent feature that needs to interact with more than one or two external tools or data sources, MCP eliminates a meaningful amount of custom integration code and keeps you compatible with a rapidly growing ecosystem of pre built servers.

If your AI feature is a single, narrowly scoped integration, such as a chatbot that only ever calls one internal API, a direct function calling implementation without the MCP layer may still be the simpler and faster choice. MCP earns its complexity when the number of integrated tools or the need for interoperability across AI providers grows.

References#

Model Context Protocol Official Documentation

What Is MCP The 2026 Developer Guide

Complete Guide to MCP Architecture, Implementation, and Enterprise Roadmap

The Complete Guide to Model Context Protocol Building AI-Native Applications

Top AI Agent Protocols to Know

Open Source Toolkit for Building AI Agents