Immutable server definition.
A %FastestMCP.Server{} is the declarative description of everything the
runtime should expose:
- tools
- resources
- resource templates
- prompts
- middleware
- transforms
- providers
- auth configuration
- dependency resolvers
- extra HTTP routes
This module is intentionally pure. Every builder returns a new struct instead
of mutating a running process. The runtime only starts later, through
FastestMCP.start_server/2 or FastestMCP.ServerModule.
Typical Flow
Most code builds a server in a pipeline:
server =
FastestMCP.Server.new("docs")
|> FastestMCP.Server.add_tool("sum", fn %{"a" => a, "b" => b}, _ctx -> a + b end)
|> FastestMCP.Server.add_dependency(:repo, fn -> MyApp.Repo end)The same shape is usually reached through the facade:
server =
FastestMCP.server("docs")
|> FastestMCP.add_tool("sum", fn %{"a" => a, "b" => b}, _ctx -> a + b end)Relationship To The Runtime
FastestMCP.Server is the build-time object.
The server runtime is the running process tree built from that object. That split is deliberate: the public builder stays simple, testable, and easy to compose, while runtime concerns stay inside OTP processes.
Duplicate Registration Policy
on_duplicate: controls what happens when the same local component name or
URI is registered twice in the same server definition:
:error- raise immediately:warn- log a warning and replace the existing definition:ignore- keep the existing definition:replace- replace the existing definition silently
This policy only applies to the local server definition. Provider precedence and mount ordering remain separate runtime concerns.
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 resource component to the current definition.
Adds a resource-template component to the current value.
Adds a tool component to the current definition.
Adds a transform to the current definition.
Returns all components attached to the server definition.
Mounts another server or provider-backed definition.
Builds a new value for this module from the supplied options.
Types
@type middleware() :: (FastestMCP.Operation.t(), (FastestMCP.Operation.t() -> any()) -> any())
@type middleware_entry() :: middleware() | %{middleware: middleware()}
@type t() :: %FastestMCP.Server{ auth: FastestMCP.Auth.t() | nil, dependencies: %{optional(String.t()) => function()}, http_routes: [tuple()], lifespans: [FastestMCP.Lifespan.t()], mask_error_details: boolean(), metadata: map(), middleware: [middleware_entry()], name: String.t(), on_duplicate: :error | :warn | :ignore | :replace, prompts: [struct()], providers: [FastestMCP.Provider.t()], resource_templates: [struct()], resources: [struct()], strict_input_validation: boolean(), tasks: struct(), tools: [struct()], transforms: [transform()] }
@type transform() :: (struct(), FastestMCP.Operation.t() -> struct() | nil)
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 resource component to the current definition.
Adds a resource-template component to the current value.
Adds a tool component to the current definition.
Adds a transform to the current definition.
Returns all components attached to the server definition.
Mounts another server or provider-backed definition.
Builds a new value for this module from the supplied options.