FastMCP Extensions Library
fastmcp-extensions is an unofficial extension library for FastMCP, providing patterns, practices, and utilities to enhance FastMCP server development. It currently supports FastMCP v3 and includes features like dynamic tool filtering and a helper for MCP server credential resolution. The library is actively maintained by AirbyteHQ and undergoes periodic releases.
Warnings
- breaking Version 0.3.0 of `fastmcp-extensions` upgrades its core dependency `fastmcp` from v2 to v3. Projects upgrading to `fastmcp-extensions` v0.3.0 must also ensure their `fastmcp` installation is v3 or higher and that their server code is compatible with `FastMCP` v3's API changes.
- gotcha `fastmcp-extensions` is described as an 'unofficial extension library'. This may imply potential for API instability, differing design philosophies, or slower updates compared to official `FastMCP` core developments. Relying heavily on specific extension implementations may introduce tighter coupling.
- gotcha The `mcp_server()` helper includes 'built-in server info and credential resolution'. Incorrect configuration or missing environment variables for credentials can lead to authentication failures or security vulnerabilities if defaults are inadvertently used.
- gotcha The 'dynamic tool filtering with intelligent default filtering policy' feature can unexpectedly hide or expose tools if the filtering logic is not fully understood. This could lead to functional gaps for LLM agents or unintended access to sensitive tools.
Install
-
pip install fastmcp-extensions
Imports
- mcp_server
from fastmcp_extensions.server import mcp_server
- FastMCP
from fastmcp import FastMCP
Quickstart
import os
from fastmcp import FastMCP
# Assuming mcp_server helper is directly exposed in a 'server' module
# Exact import path for specific extensions may vary based on internal structure.
try:
from fastmcp_extensions.server import mcp_server
from fastmcp_extensions.filters import dynamic_filter_policy # Hypothetical import
except ImportError:
print("Warning: fastmcp-extensions specific imports not found. Using FastMCP core only.")
mcp_server = None # Placeholder
dynamic_filter_policy = None # Placeholder
def run_extended_mcp_server():
mcp = FastMCP(name="MyExtendedMCPServer")
@mcp.tool
def hello(name: str = "World") -> str:
"""Greets the given name."""
return f"Hello, {name}! This is an extended FastMCP server."
# Example of integrating an extension, if 'mcp_server' exists
if mcp_server:
# The mcp_server helper likely takes a FastMCP instance and applies configurations.
# This is a hypothetical usage based on 'built-in server info and credential resolution'.
print("Applying fastmcp-extensions mcp_server helper...")
# mcp_server might take parameters for credential resolution, e.g., via env vars.
# For example, os.environ.get('MCP_SERVER_SECRET_KEY', 'default_key')
configured_mcp = mcp_server(mcp, credentials_env_var='FASTMCP_API_KEY')
else:
configured_mcp = mcp
# If dynamic_filter_policy exists, it would likely be applied to the server
if dynamic_filter_policy:
print("Applying dynamic tool filtering policy...")
# configured_mcp.add_filter(dynamic_filter_policy())
print(f"Running {configured_mcp.name} with stdio transport...")
# In a real scenario, you'd run the server (e.g., in a __main__ block)
# configured_mcp.run(transport="stdio")
print("Server setup complete (not actually running in this snippet).")
print("Available tools on the server:")
for tool_name, tool_obj in configured_mcp._tools.items():
print(f"- {tool_name}: {tool_obj.description}")
if __name__ == "__main__":
# Set a dummy environment variable if needed for hypothetical credential resolution
os.environ['FASTMCP_API_KEY'] = 'fake_api_key_123'
run_extended_mcp_server()