Module-based API for application-owned MCP servers.
Use this module when the server is part of your application and should behave like the rest of your OTP infrastructure. It keeps the existing builder API, but adds:
- module-owned server identity
- generated
child_spec/1andstart_link/1 - config resolution from
:otp_app - transport defaults for streamable HTTP and well-known HTTP endpoints
A server module still returns a normal %FastestMCP.Server{}. The difference
is that the module now owns startup, supervision, and config merging.
Example
defmodule MyApp.MCPServer do
use FastestMCP.ServerModule,
otp_app: :my_app,
http: [port: 4100, allowed_hosts: :localhost]
def server(opts) do
base_server(opts)
|> FastestMCP.add_tool("ping", fn _args, _ctx -> %{ok: true} end)
end
endAfter that, MyApp.MCPServer can sit directly in your supervision tree:
children = [
MyApp.MCPServer
]Required Callback
A server module must implement server/1 and return a
%FastestMCP.Server{} whose name matches the module name. base_server/1
exists to make that the default instead of something you have to remember.
Summary
Functions
Installs the server-module DSL and default helpers.
Builds the runtime definition for the given server module.
Builds a child specification for supervising this module.
Resolves server-module defaults and runtime overrides.
Returns whether the given module implements the server-module contract.
Starts the process owned by this module.
Callbacks
@callback server(keyword()) :: FastestMCP.Server.t()
Functions
Installs the server-module DSL and default helpers.
Builds the runtime definition for the given server module.
Builds a child specification for supervising this module.
Resolves server-module defaults and runtime overrides.
Returns whether the given module implements the server-module contract.
Starts the process owned by this module.