The high-level API.
FastestMCP is the top of the public surface. Most users start here and stay
here for day-to-day work:
- building a
%FastestMCP.Server{}with the pipeline-style builder API - starting and stopping a running server
- dispatching in-process MCP operations
- exposing HTTP or stdio transports
- working with background tasks
- preparing sampling tools
Under that facade, the runtime is composed of a few lower-level pieces:
FastestMCP.Server- immutable server definitionsFastestMCP.ServerModule- module-owned server API with generated OTP helpersFastestMCP.Context- explicit request, session, auth, and task contextFastestMCP.RequestContext- stable request snapshot derived fromFastestMCP.ContextFastestMCP.Client- connected MCP clientFastestMCP.Tools.Result- explicit tool result helperFastestMCP.Prompts.MessageandFastestMCP.Prompts.Result- explicit prompt result helpersFastestMCP.Resources.Content,FastestMCP.Resources.Result, and theFastestMCP.Resources.*helper modules - explicit resource result helpers, including file, HTTP, and directory-backed resources- the shared operation pipeline used by local dispatch
The design goal is simple: keep the public API small while keeping the runtime explicitly OTP-shaped.
Examples
Build a small server definition:
server =
FastestMCP.server("docs")
|> FastestMCP.add_tool("sum", fn %{"a" => a, "b" => b}, _ctx -> a + b end)Start it and call it in process:
{:ok, _pid} = FastestMCP.start_server(server)
42 = FastestMCP.call_tool("docs", "sum", %{"a" => 20, "b" => 22})
:ok = FastestMCP.stop_server("docs")Expose the same runtime over HTTP:
plug = FastestMCP.http_app("docs", allowed_hosts: :localhost)
child = {Bandit, plug: plug, port: 4100}Prepare local tools for sampling:
tools = FastestMCP.prepare_sampling_tools("docs")Resolve tool-argument completion values:
FastestMCP.complete(
"docs",
%{type: "ref/tool", name: "deploy"},
%{name: "environment", value: "prev"}
)When To Drop Lower
Use this module when you want the shortest path.
Drop to FastestMCP.Server when you need to work with the immutable server
struct directly. Drop to FastestMCP.ServerModule when the server belongs to
your application supervision tree. Drop to FastestMCP.Context when you are
inside a handler and need request or session state. Reach for the tool,
prompt, and resource helper modules when a component needs explicit control
over result envelopes.
Summary
Functions
Adds auth configuration to the current definition.
Registers a dependency resolver on the current definition.
Adds an HTTP route to the current definition.
Adds lifespan hooks to the current definition.
Adds middleware to the current definition.
Adds a prompt component to the current definition.
Adds a provider to the current definition.
Adds a transform to a provider wrapper.
Adds a resource component to the current definition.
Adds a resource-template component to the current definition.
Adds a tool component to the current definition.
Adds a transform to the current definition.
Waits for a background task to finish.
Calls a tool with the given arguments.
Cancels a background task.
Resolves completion values for tool arguments, prompt arguments, or resource-template parameters.
Fetches the live component manager for a running server.
Returns the current MCP protocol version.
Disables matching components for all sessions on the running server.
Enables matching components for all sessions on the running server.
Fetches background-task state.
Builds an OpenAPI-backed provider from a loaded specification.
Builds the main HTTP app for a running server.
Runs the MCP initialize handshake.
Lists visible prompts.
Lists visible resource templates.
Lists visible resources.
Lists background tasks.
Lists visible tools.
Mounts another server or provider-backed definition.
Notifies subscribed sessions that one concrete resource URI changed.
Runs a ping request.
Normalizes sampling-tool definitions for later sampling calls.
Reads a resource by URI.
Renders a prompt with the given arguments.
Clears all server-scoped component visibility rules.
Sends input to a background task waiting for user interaction.
Builds a new server definition.
Starts a server runtime.
Dispatches one stdio request against a running server.
Stops a running server runtime.
Returns a child spec for the streamable HTTP transport.
Starts a subscriber for background-task notifications.
Returns the number of active task-notification subscribers.
Returns the normalized result for a background task.
Returns a child spec for the well-known HTTP transport.
Functions
Adds auth configuration to the current definition.
Registers a dependency resolver on the current definition.
Adds an HTTP route to the current definition.
Adds lifespan hooks to the current definition.
Adds middleware to the current definition.
Adds a prompt component to the current definition.
Adds a provider to the current definition.
Adds a transform to a provider wrapper.
Adds a resource component to the current definition.
Adds a resource-template component to the current definition.
Adds a tool component to the current definition.
Adds a transform to the current definition.
Waits for a background task to finish.
Calls a tool with the given arguments.
Cancels a background task.
Resolves completion values for tool arguments, prompt arguments, or resource-template parameters.
Fetches the live component manager for a running server.
Returns the current MCP protocol version.
Disables matching components for all sessions on the running server.
Enables matching components for all sessions on the running server.
Fetches background-task state.
Builds an OpenAPI-backed provider from a loaded specification.
Builds the main HTTP app for a running server.
Runs the MCP initialize handshake.
Lists visible prompts.
Lists visible resource templates.
Lists visible resources.
Lists background tasks.
Lists visible tools.
Mounts another server or provider-backed definition.
Notifies subscribed sessions that one concrete resource URI changed.
Runs a ping request.
Normalizes sampling-tool definitions for later sampling calls.
Reads a resource by URI.
Renders a prompt with the given arguments.
Clears all server-scoped component visibility rules.
Sends input to a background task waiting for user interaction.
Builds a new server definition.
Starts a server runtime.
Dispatches one stdio request against a running server.
Stops a running server runtime.
Returns a child spec for the streamable HTTP transport.
Starts a subscriber for background-task notifications.
Returns the number of active task-notification subscribers.
Returns the normalized result for a background task.
Returns a child spec for the well-known HTTP transport.