Combine multiple FlashMCP servers into a single, larger application using mounting and importing.
New in version: 2.2.0
As your MCP applications grow, you might want to organize your tools, resources, and prompts into logical modules or reuse existing server components. FlashMCP supports composition through two methods:
import_server
: For a one-time copy of components with prefixing (static composition).mount
: For creating a live link where the main server delegates requests to the subserver (dynamic composition).WeatherServer
, a DatabaseServer
, a CalendarServer
).TextProcessingServer
) and mount them wherever needed.Feature | Importing | Mounting |
---|---|---|
Method | FlashMCP.import_server() | FlashMCP.mount() |
Composition Type | One-time copy (static) | Live link (dynamic) |
Updates | Changes to subserver NOT reflected | Changes to subserver immediately reflected |
Best For | Bundling finalized components | Modular runtime composition |
New in version: 2.3.6
You can also create proxies from configuration dictionaries that follow the MCPConfig schema, which is useful for quickly connecting to one or more remote servers. See the Proxy Servers documentation for details on configuration-based proxying. Note that MCPConfig follows an emerging standard and its format may evolve over time.
import_server()
method copies all components (tools, resources, templates, prompts) from one FlashMCP
instance (the subserver) into another (the main server). A prefix
is added to avoid naming conflicts.
await main_mcp.import_server(prefix, subserver)
:
subserver
are added to main_mcp
with names prefixed using {prefix}_
.
subserver.tool(name="my_tool")
becomes main_mcp.tool(name="{prefix}_my_tool")
.protocol://{prefix}/path
.
subserver.resource(uri="data://info")
becomes main_mcp.resource(uri="data://{prefix}/info")
.subserver.resource(uri="data://{id}")
becomes main_mcp.resource(uri="data://{prefix}/{id}")
.{prefix}_
.
subserver.prompt(name="my_prompt")
becomes main_mcp.prompt(name="{prefix}_my_prompt")
.import_server
performs a one-time copy of components. Changes made to the subserver
after importing will not be reflected in main_mcp
. The subserver
’s lifespan
context is also not executed by the main server.
mount()
method creates a live link between the main_mcp
server and the subserver
. Instead of copying components, requests for components matching the prefix
are delegated to the subserver
at runtime.
import_server
for naming tools, resources, templates, and prompts.
New in version: 2.2.7
FlashMCP supports two mounting modes:
as_proxy
parameter.
FlashMCP.as_proxy()
to create a proxy server, mounting that server will always use proxy mounting:
New in version: 2.4.0
When mounting or importing servers, resource URIs are usually prefixed to avoid naming conflicts. FlashMCP supports two different formats for resource prefixes: