docs/python-sdk/fastmcp-utilities-mcp_server_config-v1-mcp_server_config.mdx
fastmcp.utilities.mcp_server_config.v1.mcp_server_configFastMCP Configuration File Support.
This module provides support for fastmcp.json configuration files that allow users to specify server settings in a declarative format instead of using command-line arguments.
generate_schema <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L416" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>generate_schema(output_path: Path | str | None = None) -> dict[str, Any] | None
Generate JSON schema for fastmcp.json files.
This is used to create the schema file that IDEs can use for validation and auto-completion.
Args:
output_path: Optional path to write the schema to. If provided,
writes the schema and returns None. If not provided,
returns the schema as a dictionary.Returns:
Deployment <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L36" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>Configuration for server deployment and runtime settings.
Methods:
apply_runtime_settings <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L85" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>apply_runtime_settings(self, config_path: Path | None = None) -> None
Apply runtime settings like environment variables and working directory.
Args:
config_path: Path to config file for resolving relative pathsEnvironment variables support interpolation with ${VAR_NAME} syntax. For example: "API_URL": "https://api.${ENVIRONMENT}.example.com" will substitute the value of the ENVIRONMENT variable at runtime.
MCPServerConfig <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L134" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>Configuration for a FastMCP server.
This configuration file allows you to specify all settings needed to run a FastMCP server in a declarative format.
Methods:
validate_source <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L183" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>validate_source(cls, v: dict | Source) -> SourceType
Validate and convert source to proper format.
Supports:
{"path": "server.py", "entrypoint": "app"}No string parsing happens here - that's only at CLI boundaries. MCPServerConfig works only with properly typed objects.
validate_environment <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L199" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>validate_environment(cls, v: dict | Any) -> EnvironmentType
Ensure environment has a type field for discrimination.
For backward compatibility, if no type is specified, default to "uv".
validate_deployment <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L210" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>validate_deployment(cls, v: dict | Deployment) -> Deployment
Validate and convert deployment to Deployment.
Accepts:
from_file <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L223" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>from_file(cls, file_path: Path) -> MCPServerConfig
Load configuration from a JSON file.
Args:
file_path: Path to the configuration fileReturns:
Raises:
FileNotFoundError: If the file doesn't existjson.JSONDecodeError: If the file is not valid JSONpydantic.ValidationError: If the configuration is invalidfrom_cli_args <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L246" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>from_cli_args(cls, source: FileSystemSource, transport: Literal['stdio', 'http', 'sse', 'streamable-http'] | None = None, host: str | None = None, port: int | None = None, path: str | None = None, log_level: Literal['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] | None = None, python: str | None = None, dependencies: list[str] | None = None, requirements: str | None = None, project: str | None = None, editable: str | None = None, env: dict[str, str] | None = None, cwd: str | None = None, args: list[str] | None = None) -> MCPServerConfig
Create a config from CLI arguments.
This allows us to have a single code path where everything goes through a config object.
Args:
source: Server source (FileSystemSource instance)transport: Transport protocolhost: Host for HTTP transportport: Port for HTTP transportpath: URL path for serverlog_level: Logging levelpython: Python versiondependencies: Python packages to installrequirements: Path to requirements fileproject: Path to project directoryeditable: Path to install in editable modeenv: Environment variablescwd: Working directoryargs: Server argumentsReturns:
find_config <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L323" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>find_config(cls, start_path: Path | None = None) -> Path | None
Find a fastmcp.json file in the specified directory.
Args:
start_path: Directory to look in (defaults to current directory)Returns:
prepare <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L342" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>prepare(self, skip_source: bool = False, output_dir: Path | None = None) -> None
Prepare environment and source for execution.
When output_dir is provided, creates a persistent uv project. When output_dir is None, does ephemeral caching (for backwards compatibility).
Args:
skip_source: Skip source preparation if Trueoutput_dir: Directory to create the persistent uv project in (optional)prepare_environment <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L363" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>prepare_environment(self, output_dir: Path | None = None) -> None
Prepare the Python environment.
Args:
output_dir: If provided, creates a persistent uv project in this directory.
If None, just populates uv's cache for ephemeral use.Delegates to the environment's prepare() method
prepare_source <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L374" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>prepare_source(self) -> None
Prepare the source for loading.
Delegates to the source's prepare() method.
run_server <sup><a href="https://github.com/PrefectHQ/fastmcp/blob/main/src/fastmcp/utilities/mcp_server_config/v1/mcp_server_config.py#L381" target="_blank"><Icon icon="github" style="width: 14px; height: 14px;" /></a></sup>run_server(self, **kwargs: Any) -> None
Load and run the server with this configuration.
Args:
**kwargs: Additional arguments to pass to server.run_async()
These override config settings