Skip to main content

What are Adapters?

Adapters allow you to integrate xmcp into your existing web applications instead of running it as a standalone server. They provide a seamless way to add MCP capabilities to Next.js, Express, or NestJS applications.

Standalone vs Adapter Mode

xmcp can run in two modes:

Standalone Mode

Run xmcp as an independent HTTP server:
xmcp dev
This creates a dedicated MCP server on a separate port, ideal for:
  • Quick prototyping and testing
  • Microservice architectures
  • When you want MCP isolated from your main application

Adapter Mode

Integrate xmcp directly into your existing web framework:
xmcp.config.ts
export default {
  http: true,
  experimental: {
    adapter: "nextjs" // or "express" or "nestjs"
  }
}
Adapters are ideal for:
  • Adding MCP to existing applications
  • Sharing authentication and middleware
  • Unified deployment and monitoring
  • Leveraging framework-specific features

Available Adapters

Next.js Adapter

Next.js

Integrate xmcp into Next.js App Router with native support for API routes and authentication
Best for:
  • Full-stack React applications
  • Edge runtime support
  • OAuth 2.0 Bearer token authentication
  • Server components and API routes
Key Features:
  • Drop-in API route handler
  • Built-in OAuth authentication
  • Web standards (Request/Response)
  • Protected resource metadata endpoints

Express Adapter

Express

Add xmcp to your Express.js server with minimal configuration
Best for:
  • Traditional Node.js REST APIs
  • Existing Express applications
  • Custom middleware integration
  • Simple, straightforward setup
Key Features:
  • Single-function integration
  • CORS support out of the box
  • Works with existing Express middleware
  • Lightweight and performant

NestJS Adapter

NestJS

Bring xmcp into your NestJS application with full dependency injection support
Best for:
  • Enterprise applications
  • TypeScript-first architecture
  • Dependency injection patterns
  • Advanced guards and interceptors
Key Features:
  • Module, controller, and service structure
  • NestJS dependency injection
  • Guards for authentication
  • OAuth module for protected resources
  • Exception filters for error handling

Choosing an Adapter

Use the Next.js adapter. It integrates seamlessly with App Router and supports modern authentication patterns.
Use the Express adapter. It’s the simplest integration with minimal overhead.
Use the NestJS adapter. It follows NestJS patterns and supports dependency injection.
Use Next.js or NestJS adapters. Both provide built-in OAuth 2.0 support with protected resource metadata.
Consider standalone mode first for simplicity, or choose Next.js for a full-stack framework.

Configuration

All adapters are configured through xmcp.config.ts:
xmcp.config.ts
import { XmcpConfig } from "xmcp";

const config: XmcpConfig = {
  http: true, // Enable HTTP transport
  experimental: {
    adapter: "nextjs" // or "express" or "nestjs"
  },
  paths: {
    tools: "src/tools",
    prompts: "src/prompts",
    resources: "src/resources"
  }
};

export default config;

Build Process

With adapters, you typically run two processes during development:
xmcp dev & next dev
For production builds:
xmcp build && next build
The xmcp CLI compiles your tools, prompts, and resources into optimized code that the adapter can use at runtime.

Next Steps

Next.js Setup

Configure the Next.js adapter

Express Setup

Configure the Express adapter

NestJS Setup

Configure the NestJS adapter

Build docs developers (and LLMs) love