Install
Minimal example
What the middleware handles
When you callkontext.middleware(), it mounts an Express router that handles:
- OAuth metadata —
GET /.well-known/oauth-authorization-serverresponds with authorization server metadata, andGET /.well-known/oauth-protected-resource{mcpPath}(default/.well-known/oauth-protected-resource/mcp) responds with protected resource metadata (RFC 9728). MCP clients use both for discovery. - MCP transport —
POST /mcphandles the Streamable HTTP MCP transport. Configurable via themcpPathoption. - Bearer auth — Every request is verified against the authorization server’s JWKS. Pass a custom
verifierto override. - CORS — Pre-configured for browser-based MCP clients like the MCP Inspector.
- Session management — Each session gets tracked, with auto-cleanup after 1 hour of inactivity.
Getting integration credentials
Inside your tool handlers, callkontext.require() with an integration name and either the current user’s Kontext token or a known external end-user ID:
userId mode.
Next steps
- Middleware — Configure the Express middleware, session hooks, and custom verifiers.
- Credentials — Deep dive on
require(), error handling, and the elicitation flow. - Production — Deployment checklist for running in production.
- Server Types — Full type reference for
Kontext,MiddlewareOptions, andIntegrationCredential.