MCP endpoints
Several features on one URL, the identity the app declares once, and the case for more than one endpoint.
Several features on one endpoint
Section titled “Several features on one endpoint”Every shipped MCP client config points at a single URL, so a real product
usually wants all its domains behind one path. It gets that without giving up
one mcp/ adapter per feature: hosts that write the same path aggregate onto
one endpoint, and a bare #[mcp] is how a feature says “the app’s endpoint”
without repeating the URL.
A #[mcp] path is not a namespace the host owns the way a #[controller]’s
is — nothing nests under it. It names the one endpoint the host joins, which is
exactly why peers share it.
use features::audio::AudioMcpModule;use features::users::UsersMcpModule;use nest_rs::core::module;
#[module(imports = [ AudioMcpModule, UsersMcpModule,])]pub struct AssistantModule;One client, one URL, both features’ tools:
INFO nest_rs::routes: mounted endpoint surface="mcp" host="McpModule" path="/mcp"INFO nest_rs::routes: mounted host="AudioTool" method="transcode_status" path="/mcp" tool="transcode_status"INFO nest_rs::routes: mounted host="UsersTool" method="list_people" path="/mcp" tool="list_people"Nothing in a host changes: it stays a plain ServerHandler and never learns
that it shares. tools/list, prompts/list and resources/list are the union
of every host on the path that serves them, and a path where none does answers
Method not found, as each of its hosts does; a tools/call and a
prompts/get are routed to the host that declares the name, and its answer is
the client’s, an error included; the endpoint’s advertised capabilities are the
union of theirs.
Anything else a request addresses — a resource, a task, a method of your own —
is offered to each host in turn, and when every host refuses it, the client
hears the refusal of a host that serves that method, never Method not found
from one that does not.
A single host on a path is served verbatim — but for a name nobody gave
it, which is the binary’s, as below — and the merge only engages beyond one.
The one rule the merge adds: two hosts on one path may not serve the same tool or prompt name, nor read one resource template. MCP addresses a tool and a prompt by bare name inside an endpoint, and the first host to find a row would answer for every URI a shared template writes, so the loser would be unreachable — it is a boot error naming the name and both hosts:
duplicate MCP tool name on "/mcp": search (AudioTool and UsersTool) — a tool isaddressed by bare name within an endpoint, so rename one of them, or give eachhost its own pathName your endpoint
Section titled “Name your endpoint”An MCP endpoint is one server to every client that reaches it. The
protocol carries one serverInfo and one instructions, on initialize
and on server/discover alike — the same shape new McpServer({ name, version }) builds in the TypeScript SDK, and the one a FastMCP parent keeps
when it mounts children. Two declarations answer for it, each owned by whoever can know it.
The app is named after its binary: every endpoint reports the package
name, version and description #[nest_rs::main] reads off the app’s
Cargo.toml, with nothing written. It says how its server is used, once,
for every endpoint it exposes:
use features::audio::AudioMcpModule;use features::posts::PostsMcpModule;use features::users::UsersMcpModule;use nest_rs::core::module;use nest_rs::mcp::{McpIdentity, McpModule};
#[module(imports = [ McpModule::for_root(McpIdentity { title: Some("Acme assistant".into()), instructions: Some("Ask before writing anything. Every result is scoped to your token.".into()), ..Default::default() }), AudioMcpModule, UsersMcpModule, PostsMcpModule,])]pub struct AssistantModule;The instructions have to come from here, because they describe the
server — a client may fold them into the model’s system prompt — and on an
endpoint several features share, no single host can see the whole. The name
and version come from the binary, because env!("CARGO_PKG_VERSION") written
in a shared feature library is the library’s version rather than the
deployment’s; the name and version fields override both when the server
should report another.
Keep them general: what a caller must know to use the surface at all. What each
tool does is already carried by its own #[tool(description = "…")], which is
what the model reads when it chooses between them.
The identity is a declaration, made at one import. A second
McpModule::for_root declaring an McpIdentity fails the boot before anything
is built, naming both imports — even when the two are equal, since two sites
would have to change together. Every other import of the module declares none.
A host says which endpoint stands apart, on the file that serves it:
#[mcp(path = "/mcp/posts", name = "acme-posts")]#[derive(Clone)]pub struct PostsTool { /* … */ }name and title are optional and each overrides the app’s per field, so the
host above renames its endpoint while still inheriting the app’s version, title
and instructions. Two hosts on one path both declaring is a boot error naming
both — otherwise the endpoint’s name would depend on imports = [..] order.
path, name and title are the whole list. Every other identity field —
version, description, website_url, icons, instructions — describes the
server, and writing one on a host is a compile error naming the seam that takes
it. A feature library knows neither the binary’s version nor, on a shared
endpoint, the whole surface, so those have one owner: the binary for its
version, the app’s McpModule::for_root for the rest. To version the address, write it into the path —
#[mcp(path = "/mcp/v1")].
Identity is declared; capabilities are observed. A declaration replaces what
it states and can never claim a capability no host serves. Declare no
instructions at all and the hosts’ own get_info blurbs are joined instead of
dropped — a fallback, not a second way to write them.
Multiple servers on one app
Section titled “Multiple servers on one app”The other direction: a second server is a second path on a host. Each mounts
on the HTTP transport independently — different tools, different injected
dependencies, different authorization policy if you want one.
Namespacing is the URL: /mcp for the app’s own endpoint, whatever you write
for the second. The MCP spec already namespaces tools per endpoint, so a second
endpoint is the namespace — no extra primitive to learn, and no prefix the
second path has to sit under.
Going further
Section titled “Going further”- MCP — the host each of these mounts.
- Authorization — resolved once per path, not per host.