Skip to main content
The FastMCP class is the core of FastMCP for Node.js environments. It provides a fluent API for building Model Context Protocol servers with tools, resources, prompts, and OAuth support.

Constructor

Create a new FastMCP server instance.
string
required
Server name identifier
string
required
Semantic version string (e.g., “1.0.0”)
string
Server-level instructions or description
Logger
Custom logger instance (defaults to console)
AuthProvider
Authentication provider for OAuth flows. When provided, automatically configures authentication and OAuth endpoints.
(request: IncomingMessage) => Promise<T>
Custom authentication function. Takes precedence over auth provider if both are specified.
object
Health check endpoint configuration (HTTP Stream transport only)
object
OAuth discovery endpoint configuration (HTTP-based transports only)
object
Server ping configuration
object
Roots capability configuration

Methods

addTool()

Register a tool that can be called by the MCP client.
Tool
required
Tool configuration object

addResource()

Register a static resource that can be read by the MCP client.
Resource
required
Resource configuration object

addResourceTemplate()

Register a dynamic resource template with URI parameters.
ResourceTemplate
required
Resource template configuration

addPrompt()

Register a prompt template.
Prompt
required
Prompt configuration object

addRoute()

Register a custom HTTP route (HTTP Stream transport only).
HTTPMethod
required
HTTP method: “GET”, “POST”, “PUT”, “PATCH”, “DELETE”, “OPTIONS”
string
required
URL path for the route
RouteHandler
required
Request handler function
RouteOptions
Route configuration options

start()

Start the MCP server with the specified transport.
object
Transport configuration
SSEServer
Server instance with close() method (httpStream only)

embedded()

Create an embedded MCP server instance for programmatic use.
object
FastMCPSession
Embedded session instance with direct API access

Context Object

The context object is passed to tool execute functions and provides access to session information and client capabilities.
T | undefined
Authentication session data (if authenticated)
string | undefined
Session ID from Mcp-Session-Id header (HTTP transports only)
string | undefined
Request ID from current MCP request
object
Client information
object
Logging functions
(progress: Progress) => Promise<void>
Report tool execution progress
(content: Content | Content[]) => Promise<void>
Stream content to the client (for streaming tools)