Overview
The optionalsrc/server.ts file configures authentication and server metadata. When present, the framework calls auth() on every MCP request and populates extra.authInfo in tool handlers.
Under the hood, the returned AuthInfo is set as req.auth on the HTTP request — the same mechanism the MCP SDK uses. This gives you the same flexibility as using the SDK directly.
File Convention
Example
Exports
auth (function, optional)
Called on every MCP request. Return AuthInfo to authenticate, or null to reject the request with 401.
The incoming HTTP request from Node’s
http module. Access headers, cookies, query params, etc.AuthInfo | null (sync or async):
null to reject the request — Sunpeak responds with 401 Unauthorized and a WWW-Authenticate: Bearer header.
server (object, optional)
Server metadata reported to hosts during the MCP handshake.
Server name displayed in the host.
Server version.
Using Auth in Tool Handlers
TheauthInfo from the server entry is available in every tool handler:
Custom Server
If you need middleware, custom routes, or full control over the HTTP server, usecreateMcpHandler (Node.js) or createHandler (Web Standard) to mount the MCP protocol on your own server:
dist/. See the Production Server API for config types and the Deployment Guide for complete examples.
See Also
Tool File
Define tool metadata, schemas, and handlers.
Deployment Guide
Production server setup and custom server integration.