FastMCP Extensions Library

0.3.0 · active · verified Mon Apr 13

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

Install

Imports

Quickstart

This quickstart demonstrates how to initialize a FastMCP server and conceptually integrate features provided by `fastmcp-extensions`, such as the `mcp_server` helper for server setup and credential resolution, and a placeholder for dynamic tool filtering. Due to the lack of specific examples in public documentation, some imports and usages are illustrative based on the library's stated features. Users should consult the library's source for precise API details.

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()

view raw JSON →