Middlewares

Middlewares intercept HTTP requests and responses, enabling authentication, rate limiting, and other processing tasks.

Create a src/middleware.ts file to define your middleware:

src/middleware.ts

xmcp provides built-in middlewares for common tasks like API key authentication and JSON web token authentication.

Chaining middlewares

Define multiple middlewares as an array to chain them in sequence:

src/middleware.ts

Accessing headers

Use the xmcp/headers module to read request headers in your tools, prompts, or resources—useful for API keys, authentication tokens, and other custom headers.

src/tools/search.ts

On this page

One framework to rule them all

    Middlewares | xmcp Documentation