### Quick Start: Setup FastMCP Server and Documentation Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md This Python script demonstrates the basic setup for FastMCP Docs. It initializes a FastMCP server, registers a simple tool, sets up the documentation generator with a title, and then runs the server. The documentation will be accessible via specified URLs. ```python from fastmcp import FastMCP from fastmcp_docs import FastMCPDocs import asyncio # Create your FastMCP server mcp = FastMCP("My MCP Server") # Register your tools @mcp.tool(tags=["example"]) def hello_world(name: str = "World"): """Say hello to someone""" return f"Hello, {name}!" # Setup documentation (3 lines!) docs = FastMCPDocs(mcp, title="My MCP Tools") asyncio.run(docs.setup()) # Run server mcp.run() ``` -------------------------------- ### Development Setup for FastMCP Docs Source: https://github.com/orco82/fastmcp-docs/blob/main/CLAUDE.md Commands to set up a Python virtual environment and install the FastMCP Docs package in development mode. This includes creating and activating the environment, then installing the package with development dependencies. ```bash # Create and activate virtual environment python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate # Install package in development mode pip install -e ".[dev]" ``` -------------------------------- ### Local Installation Commands Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md Provides the necessary bash commands to clone the fastmcp-docs repository and install it in development mode using pip. This setup is crucial for contributing to or modifying the project. ```bash # Clone repository git clone https://github.com/orco82/fastmcp-docs.git cd fastmcp-docs # Install in development mode pip install -e ".[dev]" ``` -------------------------------- ### Complete FastMCP Server Example with Tools and Documentation Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md A full example of setting up a `FastMCP` server, defining tools with `Annotated` parameters and docstrings, and integrating `FastMCPDocs` for interactive documentation. It includes server startup and asynchronous execution. ```python from fastmcp import FastMCP from fastmcp_docs import FastMCPDocs from typing import Annotated import asyncio # Create server mcp = FastMCP("My MCP Server") @mcp.tool(tags=["deployment"], annotations={"title": "Deploy Application"}) def deploy( environment: Annotated[str, "Target environment (dev, staging, prod)"], version: Annotated[str, "Version to deploy"], dry_run: Annotated[bool = "Perform dry run without actual deployment"] = False ) -> str: """Deploy application to specified environment This tool deploys the application to the target environment with the specified version. Use dry_run to test without deploying. """ if dry_run: return f"DRY RUN: Would deploy v{version} to {environment}" return f"Deployed v{version} to {environment}" # Setup documentation docs = FastMCPDocs( mcp=mcp, title="My FastMCP Tools", version="1.0.0", description="This is my FastMCP Tools Documention", base_url="https://mcp.example.com", page_title_emoji="🛠️", docs_links=[ {"text": "Tools Guide", "url": "https://docs.example.com/tools-guide"} ] ) # Run setup asyncio.run(docs.setup()) # Start server if __name__ == "__main__": mcp.run(transport="sse", host="0.0.0.0", port=8000) ``` -------------------------------- ### Running FastMCP Docs Examples Source: https://github.com/orco82/fastmcp-docs/blob/main/CLAUDE.md Command to execute a basic usage example script for the FastMCP Docs library. This helps demonstrate the library's functionality in a practical scenario. ```bash # Run basic usage example python examples/basic_usage.py ``` -------------------------------- ### FastMCPDocs Class Initialization and Setup Source: https://context7.com/orco82/fastmcp-docs/llms.txt Demonstrates how to initialize the FastMCPDocs class with basic configuration and set up the documentation for a FastMCP server. ```APIDOC ## FastMCPDocs Class ### Description The main class that initializes and configures the documentation generator for your FastMCP server. It accepts the MCP server instance along with configuration options for title, version, description, documentation links, UI customization, and CORS settings. ### Method ```python from fastmcp import FastMCP from fastmcp_docs import FastMCPDocs from typing import Annotated import asyncio # Create FastMCP server mcp = FastMCP("My MCP Server") # Define tools with typed parameters and descriptions @mcp.tool(tags=["greetings"]) def hello_world(name: str = "World") -> str: """Say hello to someone""" return f"Hello, {name}!" @mcp.tool(tags=["math"], annotations={"title": "Add Two Numbers"}) def add_numbers( a: Annotated[float, "First number"], b: Annotated[float, "Second number"] ) -> str: """Add two numbers together""" return f"{a} + {b} = {a + b}" # Initialize documentation with basic configuration docs = FastMCPDocs( mcp=mcp, title="My MCP Tools", version="1.0.0", description="API documentation for my awesome MCP server", base_url="http://localhost:8000", page_title_emoji="🚀", docs_links=[ {"text": "GitHub Repository", "url": "https://github.com/example/repo"}, {"text": "User Guide", "url": "https://docs.example.com"} ], enable_cors=True, verbose=True ) # Setup documentation (async - extracts tools and registers routes) asyncio.run(docs.setup()) # Run the server mcp.run(transport="sse", host="0.0.0.0", port=8000) # Output: # Found 2 tools to document (fastmcp v3) # ✓ Documented tool: hello_world # ✓ Documented tool: add_numbers # ✓ Documentation setup complete # - Documented 2 tools # - Docs UI: http://localhost:8000/docs # - OpenAPI: http://localhost:8000/openapi.json # - API: http://localhost:8000/api/tools ``` ``` -------------------------------- ### Install fastmcp-docs using pip Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md This command installs the fastmcp-docs library using pip, making it available for use in your Python projects. Ensure you have pip installed and configured correctly. ```bash pip install fastmcp-docs ``` -------------------------------- ### Testing FastMCP Version Compatibility with Bash Source: https://github.com/orco82/fastmcp-docs/blob/main/FASTMCP_V3_SUPPORT.md Provides bash commands to test the compatibility of the application with FastMCP v2 and v3. It includes instructions for installing specific versions of the 'fastmcp' package and running a Python example script. ```bash pip install "fastmcp>=2.0.0,<3.0.0" python examples/basic_usage.py # Should print: "Found X tools to document (fastmcp v2)" ``` ```bash pip install "fastmcp>=3.0.0" python examples/basic_usage.py # Should print: "Found X tools to document (fastmcp v3)" ``` -------------------------------- ### Building and Distributing FastMCP Docs Source: https://github.com/orco82/fastmcp-docs/blob/main/CLAUDE.md Commands for cleaning previous builds, building the package, checking the distribution files, and uploading to PyPI. It also includes installing the package from a local build. ```bash # Clean previous builds rm -rf dist/ fastmcp_docs.egg-info/ # Build package uv run python -m build # Check distribution uv run python -m twine check dist/* # Upload to PyPI uv run python -m twine upload dist/* # Install from local build pip install -e . ``` -------------------------------- ### Initialize FastMCPDocs with Basic Configuration (Python) Source: https://context7.com/orco82/fastmcp-docs/llms.txt Demonstrates how to initialize the FastMCPDocs class with basic configuration options for title, version, description, and UI elements. It also shows how to define FastMCP tools and run the documentation setup and server. ```python from fastmcp import FastMCP from fastmcp_docs import FastMCPDocs from typing import Annotated import asyncio # Create FastMCP server mcp = FastMCP("My MCP Server") # Define tools with typed parameters and descriptions @mcp.tool(tags=["greetings"]) def hello_world(name: str = "World") -> str: """Say hello to someone""" return f"Hello, {name}!" @mcp.tool(tags=["math"], annotations={"title": "Add Two Numbers"}) def add_numbers( a: Annotated[float, "First number"], b: Annotated[float, "Second number"] ) -> str: """Add two numbers together""" return f"{a} + {b} = {a + b}" # Initialize documentation with basic configuration docs = FastMCPDocs( mcp=mcp, title="My MCP Tools", version="1.0.0", description="API documentation for my awesome MCP server", base_url="http://localhost:8000", page_title_emoji="🚀", docs_links=[ {"text": "GitHub Repository", "url": "https://github.com/example/repo"}, {"text": "User Guide", "url": "https://docs.example.com"} ], enable_cors=True, verbose=True ) # Setup documentation (async - extracts tools and registers routes) asyncio.run(docs.setup()) # Run the server mcp.run(transport="sse", host="0.0.0.0", port=8000) # Output: # Found 2 tools to document (fastmcp v3) # ✓ Documented tool: hello_world # ✓ Documented tool: add_numbers # ✓ Documentation setup complete # - Documented 2 tools # - Docs UI: http://localhost:8000/docs # - OpenAPI: http://localhost:8000/openapi.json # - API: http://localhost:8000/api/tools ``` -------------------------------- ### Access Tools Registry Programmatically with FastMCPDocs in Python Source: https://context7.com/orco82/fastmcp-docs/llms.txt Shows how to obtain the complete tools registry dictionary after setting up `FastMCPDocs`. This allows for programmatic access to all documented tool information, including their descriptions, tags, and parameters. The example defines two simple tools, `echo` and `reverse`, and then iterates through the registry to print their details. ```python from fastmcp import FastMCP from fastmcp_docs import FastMCPDocs import asyncio mcp = FastMCP("Registry Example") @mcp.tool(tags=["utilities"]) def echo(message: str) -> str: """Echo back the input message""" return message @mcp.tool(tags=["utilities"]) def reverse(text: str) -> str: """Reverse the input text""" return text[::-1] docs = FastMCPDocs(mcp, title="Registry Demo", verbose=False) asyncio.run(docs.setup()) # Access the tools registry programmatically registry = docs.get_tools_registry() # Print tool information for tool_name, tool_info in registry.items(): print(f"Tool: {tool_name}") print(f" Description: {tool_info['description']}") print(f" Tags: {tool_info['tags']}") print(f" Parameters: {list(tool_info['parameters'].keys())}") # Output: # Tool: echo # Description: Echo back the input message # Tags: ['utilities'] # Parameters: ['message'] # Tool: reverse # Description: Reverse the input text # Tags: ['utilities'] ``` -------------------------------- ### List All Registered MCP Tools (Bash) Source: https://context7.com/orco82/fastmcp-docs/llms.txt Demonstrates how to use `curl` to make a GET request to the `/api/tools` endpoint. This endpoint lists all registered MCP tools, providing their metadata such as name, title, description, parameters, and tags in JSON format. ```bash # List all tools curl http://localhost:8000/api/tools ``` -------------------------------- ### Get Specific Tool Details (Bash) Source: https://context7.com/orco82/fastmcp-docs/llms.txt Retrieves detailed information about a specific tool by its name. If the tool is not found, a 404 error is returned. The response includes the tool's name, title, description, parameters, and tags. ```bash # Get specific tool details curl http://localhost:8000/api/tools/add_numbers # Response: { "name": "add_numbers", "title": "Add Two Numbers", "description": "Add two numbers together\n\nThis tool takes two numbers and returns their sum.", "parameters": { "a": { "type": "number", "description": "First number", "default": null, "required": true }, "b": { "type": "number", "description": "Second number", "default": null, "required": true } }, "tags": ["math"] } # Tool not found curl http://localhost:8000/api/tools/nonexistent # Response (404): { "error": "Tool 'nonexistent' not found" } ``` -------------------------------- ### Get All MCP Tools (Bash) Source: https://context7.com/orco82/fastmcp-docs/llms.txt Retrieves a list of all available MCP tools from the server. This endpoint returns server information, the total count of tools, and a detailed object of each tool. ```bash curl http://localhost:8000/api/tools ``` -------------------------------- ### Python Type Hinting for Descriptions Source: https://github.com/orco82/fastmcp-docs/blob/main/CLAUDE.md Example demonstrating the use of Python's `typing.Annotated` to provide descriptions for function parameters. This is a key pattern used by FastMCP Docs to extract metadata for documentation. ```python from typing import Annotated def my_function(param: Annotated[str, "This is a description for the parameter"]): pass ``` -------------------------------- ### GET /openapi.json Source: https://context7.com/orco82/fastmcp-docs/llms.txt Generates an OpenAPI 3.1.0 compliant schema for all registered tools, including server definitions, tag definitions, and path specifications for each tool endpoint. ```APIDOC ## GET /openapi.json ### Description Generates an OpenAPI 3.1.0 compliant schema for all registered tools. Includes server definitions, tag definitions, and path specifications for each tool endpoint. ### Method GET ### Endpoint /openapi.json ### Parameters None ### Request Example ```bash curl http://localhost:8000/openapi.json ``` ### Response #### Success Response (200) - **openapi** (string) - The OpenAPI version. - **info** (object) - General information about the API. - **servers** (array) - An array of server objects. - **tags** (array) - An array of tag objects. - **paths** (object) - An object containing the API paths. - **components** (object) - An object for reusable components. #### Response Example ```json { "openapi": "3.1.0", "info": { "title": "Example MCP Tools", "description": "Example API documentation showing fastmcp-docs capabilities", "version": "1.0.0" }, "servers": [ {"url": "http://localhost:8000", "description": "MCP Server"} ], "tags": [ {"name": "greetings", "description": "Greetings related tools"}, {"name": "math", "description": "Math related tools"} ], "paths": { "/api/tools": { "get": { "summary": "List all MCP tools", "operationId": "list_all_mcp_tools", "tags": ["MCP Tools"], "responses": { "200": { "description": "Successful response", "content": { "application/json": { "schema": { "type": "object", "properties": { "server": {"type": "string"}, "total_tools": {"type": "integer"}, "tools": {"type": "object"} } } } } } } } }, "/api/tools/add_numbers": { "get": { "summary": "Add Two Numbers", "description": "Add two numbers together", "operationId": "get_tool_add_numbers", "tags": ["math"], "responses": {"200": {"description": "Tool information"}} } } }, "components": {"schemas": {}} } ``` ``` -------------------------------- ### GET /api/tools/{tool_name} Source: https://context7.com/orco82/fastmcp-docs/llms.txt Retrieves detailed information about a specific tool by its name. Returns a 404 error if the tool is not found. ```APIDOC ## GET /api/tools/{tool_name} ### Description Retrieves detailed information about a specific tool by name. Returns 404 error if the tool is not found. ### Method GET ### Endpoint /api/tools/{tool_name} ### Parameters #### Path Parameters - **tool_name** (string) - Required - The name of the tool to retrieve information for. ### Request Example ```bash curl http://localhost:8000/api/tools/add_numbers ``` ### Response #### Success Response (200) - **name** (string) - The name of the tool. - **title** (string) - The title of the tool. - **description** (string) - A description of what the tool does. - **parameters** (object) - An object detailing the parameters the tool accepts. - **tags** (array) - An array of tags associated with the tool. #### Response Example ```json { "name": "add_numbers", "title": "Add Two Numbers", "description": "Add two numbers together\n\nThis tool takes two numbers and returns their sum.", "parameters": { "a": { "type": "number", "description": "First number", "default": null, "required": true }, "b": { "type": "number", "description": "Second number", "default": null, "required": true } }, "tags": ["math"] } ``` #### Error Response (404) - **error** (string) - A message indicating the tool was not found. #### Error Response Example ```json { "error": "Tool 'nonexistent' not found" } ``` ``` -------------------------------- ### Get OpenAPI Schema (Bash) Source: https://context7.com/orco82/fastmcp-docs/llms.txt Generates an OpenAPI 3.1.0 compliant schema for all registered tools. This schema includes server definitions, tag definitions, and path specifications for each tool endpoint, providing a comprehensive API description. ```bash # Get OpenAPI schema curl http://localhost:8000/openapi.json ``` -------------------------------- ### Customizing Favicon in FastMCPDocs Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md These Python examples demonstrate how to set a custom favicon for the FastMCP Docs UI. You can use a URL for an online favicon, or a path to a local file within your project. ```python # Use default favicon (green circle with M) docs = FastMCPDocs(mcp, title="My Tools") # Use custom favicon URL docs = FastMCPDocs( mcp, title="My Tools", favicon_url="https://example.com/my-icon.ico" ) # Use local favicon file docs = FastMCPDocs( mcp, title="My Tools", favicon_url="/static/favicon.png" ) ``` -------------------------------- ### GET /api/tools Endpoint Source: https://context7.com/orco82/fastmcp-docs/llms.txt Retrieves a list of all registered MCP tools, including their metadata such as name, title, description, parameters, and tags. The response is a JSON object containing server name, total tool count, and detailed information for each tool. ```APIDOC ## GET /api/tools Endpoint ### Description Lists all registered MCP tools with their complete metadata including name, title, description, parameters, and tags. Returns JSON with server name, total tool count, and detailed tool information. ### Method GET ### Endpoint /api/tools ### Parameters #### Query Parameters None ### Request Example ```bash # List all tools curl http://localhost:8000/api/tools ``` ### Response #### Success Response (200) - **server_name** (string) - The name of the MCP server. - **total_tools** (integer) - The total number of registered tools. - **tools** (array) - An array of tool objects, each containing: - **name** (string) - The name of the tool. - **title** (string) - The title of the tool. - **description** (string) - The description of the tool. - **tags** (array of strings) - Tags associated with the tool. - **parameters** (array of objects) - Details about the tool's parameters. #### Response Example ```json { "server_name": "My MCP Server", "total_tools": 2, "tools": [ { "name": "hello_world", "title": "hello_world", "description": "Say hello to someone", "tags": ["greetings"], "parameters": [ { "name": "name", "in": "query", "required": false, "schema": { "type": "string", "default": "World" }, "description": "" } ] }, { "name": "add_numbers", "title": "Add Two Numbers", "description": "Add two numbers together", "tags": ["math"], "parameters": [ { "name": "a", "in": "query", "required": true, "schema": { "type": "number" }, "description": "First number" }, { "name": "b", "in": "query", "required": true, "schema": { "type": "number" }, "description": "Second number" } ] } ] } ``` ``` -------------------------------- ### Initialize FastMCPDocs with Advanced Configuration (Python) Source: https://context7.com/orco82/fastmcp-docs/llms.txt Illustrates using the FastMCPDocsConfig dataclass for advanced configuration, including custom route paths, OpenAPI server definitions, and detailed UI customization. This allows for fine-grained control over the documentation's appearance and behavior. ```python from fastmcp import FastMCP from fastmcp_docs import FastMCPDocs, FastMCPDocsConfig, DocsLink import asyncio mcp = FastMCP("Advanced Server") @mcp.tool(tags=["deployment"]) def deploy(environment: str, version: str, dry_run: bool = False) -> str: """Deploy application to specified environment""" if dry_run: return f"DRY RUN: Would deploy v{version} to {environment}" return f"Deployed v{version} to {environment}" # Create advanced configuration config = FastMCPDocsConfig( # Basic information title="Production API Tools", version="2.0.0", description="Advanced API documentation with custom configuration", base_url="https://api.example.com", # Documentation links using DocsLink dataclass docs_links=[ DocsLink(text="GitHub", url="https://github.com/example/repo"), DocsLink(text="Docs", url="https://docs.example.com") ], # Customize route paths api_tools_route="/api/v2/tools", api_tool_detail_route="/api/v2/tools/{tool_name}", openapi_route="/api/v2/openapi.json", docs_ui_route="/api/v2/docs", # OpenAPI settings openapi_version="3.1.0", openapi_servers=[ {"url": "https://api.example.com", "description": "Production"}, {"url": "https://staging.example.com", "description": "Staging"}, {"url": "http://localhost:8000", "description": "Development"} ], # UI customization page_title_emoji="🛠️", favicon_url="https://example.com/favicon.ico", enable_cors=True, verbose=True ) # Use custom config docs = FastMCPDocs(mcp, config=config) asyncio.run(docs.setup()) mcp.run(transport="sse", host="0.0.0.0", port=8000) # Documentation available at: https://api.example.com/api/v2/docs ``` -------------------------------- ### Accessing Tools: FastMCP v2 vs v3 API Comparison Source: https://github.com/orco82/fastmcp-docs/blob/main/FASTMCP_V3_SUPPORT.md Compares the 'get_tools()' method in FastMCP v2, which returns a dictionary, with the 'list_tools()' method in FastMCP v3, which returns a list. Demonstrates the different access patterns for retrieving a specific tool by name. ```python tools = await server.get_tools() tool = tools["my_tool"] # Dict access by name ``` ```python tools = await server.list_tools() tool = next((t for t in tools if t.name == "my_tool"), None) # List iteration ``` -------------------------------- ### Testing FastMCP Docs with Pytest Source: https://github.com/orco82/fastmcp-docs/blob/main/CLAUDE.md Instructions for running tests for the FastMCP Docs library using pytest. It covers running all tests, enabling verbose output, and executing tests from a specific file. ```bash # Run all tests pytest # Run with verbose output pytest -v # Run specific test file pytest tests/test_extractor.py ``` -------------------------------- ### Tool: deploy Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md Deploys an application to a specified environment with a given version. Supports dry run functionality. ```APIDOC ## POST /api/tools/deploy ### Description Deploys application to specified environment with the specified version. Use dry_run to test without deploying. ### Method POST ### Endpoint /api/tools/deploy ### Parameters #### Request Body - **environment** (string) - Required - Target environment (dev, staging, prod) - **version** (string) - Required - Version to deploy - **dry_run** (boolean) - Optional - Perform dry run without actual deployment (default: false) ### Request Example ```json { "environment": "staging", "version": "1.2.3", "dry_run": true } ``` ### Response #### Success Response (200) - **result** (string) - The deployment status message #### Response Example ```json { "result": "DRY RUN: Would deploy v1.2.3 to staging" } ``` ``` -------------------------------- ### Version Bumping and Git Tagging Source: https://github.com/orco82/fastmcp-docs/blob/main/CLAUDE.md Steps to update the project version, perform a full build and distribution, and then commit the changes with a new Git tag for release. This includes adding all changes, committing, tagging, and pushing to the remote repository. ```bash git add -A git commit -m "Release v1.0.0: Add FastMCP v3 support" git tag -a v1.0.0 -m "Version 1.0.0" git push && git push --tags ``` -------------------------------- ### Tool: greet Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md Greets a person with a custom message. It accepts a name and an optional greeting. ```APIDOC ## POST /api/tools/greet ### Description Greets a person with a custom message. ### Method POST ### Endpoint /api/tools/greet ### Parameters #### Request Body - **name** (string) - Required - Name of the person to greet - **greeting** (string) - Optional - Greeting to use (default: "Hello") ### Request Example ```json { "name": "Alice", "greeting": "Hi" } ``` ### Response #### Success Response (200) - **result** (string) - The greeting message #### Response Example ```json { "result": "Hi, Alice!" } ``` ``` -------------------------------- ### Basic Configuration for FastMCPDocs Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md This Python snippet shows how to configure FastMCPDocs with basic options like title, version, description, and base URL. These parameters customize the appearance and behavior of the generated API documentation. ```python from fastmcp_docs import FastMCPDocs docs = FastMCPDocs( mcp=mcp, title="My MCP Tools", version="1.0.0", description="API documentation for my awesome MCP server", base_url="https://api.example.com", ) ``` -------------------------------- ### Running Tests with Pytest Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md This command executes the test suite for the fastmcp-docs project using the `pytest` framework. Running tests ensures the project's integrity and helps catch regressions during development. ```bash pytest ``` -------------------------------- ### Updating Project Dependencies in pyproject.toml Source: https://github.com/orco82/fastmcp-docs/blob/main/FASTMCP_V3_SUPPORT.md Shows an excerpt from a 'pyproject.toml' file, illustrating the update of the 'fastmcp' dependency from '>=0.1.0' to '>=2.0.0' to ensure support for both FastMCP v2 and v3. Also lists the 'starlette' dependency. ```toml dependencies = [ "fastmcp>=2.0.0", # Changed from >=0.1.0 to support both v2 and v3 "starlette>=0.27.0", ] ``` -------------------------------- ### Add Descriptions to Tool Parameters with Annotated Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md Demonstrates how to add descriptions to tool parameters using Python's `typing.Annotated`. This enhances documentation by providing clear explanations for each parameter, improving tool discoverability and usability. ```python from typing import Annotated @mcp.tool(tags=["greetings"]) def greet( name: Annotated[str, "Name of the person to greet"], greeting: Annotated[str, "Greeting to use"] = "Hello" ) -> str: """Greet someone with a custom message""" return f"{greeting}, {name}!" ``` -------------------------------- ### FastMCPDocsConfig Class for Advanced Configuration Source: https://context7.com/orco82/fastmcp-docs/llms.txt Illustrates how to use the FastMCPDocsConfig dataclass for fine-grained control over documentation settings, including custom routes, OpenAPI definitions, and UI customization. ```APIDOC ## FastMCPDocsConfig Class ### Description A dataclass for advanced configuration that provides fine-grained control over all documentation settings including custom route paths, OpenAPI server definitions, and UI customization options. ### Method ```python from fastmcp import FastMCP from fastmcp_docs import FastMCPDocs, FastMCPDocsConfig, DocsLink import asyncio mcp = FastMCP("Advanced Server") @mcp.tool(tags=["deployment"]) def deploy(environment: str, version: str, dry_run: bool = False) -> str: """Deploy application to specified environment""" if dry_run: return f"DRY RUN: Would deploy v{version} to {environment}" return f"Deployed v{version} to {environment}" # Create advanced configuration config = FastMCPDocsConfig( # Basic information title="Production API Tools", version="2.0.0", description="Advanced API documentation with custom configuration", base_url="https://api.example.com", # Documentation links using DocsLink dataclass docs_links=[ DocsLink(text="GitHub", url="https://github.com/example/repo"), DocsLink(text="Docs", url="https://docs.example.com") ], # Customize route paths api_tools_route="/api/v2/tools", api_tool_detail_route="/api/v2/tools/{tool_name}", openapi_route="/api/v2/openapi.json", docs_ui_route="/api/v2/docs", # OpenAPI settings openapi_version="3.1.0", openapi_servers=[ {"url": "https://api.example.com", "description": "Production"}, {"url": "https://staging.example.com", "description": "Staging"}, {"url": "http://localhost:8000", "description": "Development"} ], # UI customization page_title_emoji="🛠️", favicon_url="https://example.com/favicon.ico", enable_cors=True, verbose=True ) # Use custom config docs = FastMCPDocs(mcp, config=config) asyncio.run(docs.setup()) mcp.run(transport="sse", host="0.0.0.0", port=8000) # Documentation available at: https://api.example.com/api/v2/docs ``` ``` -------------------------------- ### API Routes Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md Provides access to the interactive Swagger UI, OpenAPI schema, and tool metadata. ```APIDOC ## API Routes ### Description FastMCP Docs automatically creates the following routes: ### Method GET ### Endpoint - `/docs`: Interactive Swagger-style UI - `/openapi.json`: OpenAPI 3.1.0 schema - `/api/tools`: List all tools with metadata - `/api/tools/{tool_name}`: Get specific tool details ``` -------------------------------- ### Extract Tool Metadata with ToolExtractor in Python Source: https://context7.com/orco82/fastmcp-docs/llms.txt Illustrates the use of the `ToolExtractor` class to programmatically extract documentation metadata from FastMCP tools. It supports both FastMCP v2 and v3 APIs and automatically detects the version. The extractor can be configured with verbose logging for detailed output during the extraction process. ```python from fastmcp_docs.extractor import ToolExtractor from fastmcp import FastMCP import asyncio mcp = FastMCP("Extractor Example") @mcp.tool(tags=["example"]) def sample_tool(value: str) -> str: """A sample tool for extraction demo""" return value # Create extractor with verbose logging extractor = ToolExtractor(verbose=True) # Extract tools asynchronously async def extract(): tools_registry = await extractor.extract_tools(mcp) return tools_registry tools = asyncio.run(extract()) # Output (verbose=True): # Found 1 tools to document (fastmcp v3) # Processing tool: sample_tool # Description: A sample tool for extraction demo # Tags: ['example'] # Found input_schema with 1 properties # ✓ Documented tool: sample_tool # tools_registry contains: # { # "sample_tool": { # "name": "sample_tool", # "title": "sample_tool", # "description": "A sample tool for extraction demo", # "parameters": { # "value": {"type": "string", "description": "", "default": null, "required": true} # }, # "tags": ["example"] # } # } ``` -------------------------------- ### Code Formatting with Black Source: https://github.com/orco82/fastmcp-docs/blob/main/CLAUDE.md Command to format all Python code within the fastmcp_docs/ directory using the Black code formatter. This ensures consistent code style across the project. ```bash # Format all code black fastmcp_docs/ ``` -------------------------------- ### Automatic Tool Extraction with Version Detection in Python Source: https://github.com/orco82/fastmcp-docs/blob/main/FASTMCP_V3_SUPPORT.md Implements a Python function to automatically detect and use either the FastMCP v3 'list_tools()' API (returning a list) or the v2 'get_tools()' API (returning a dict). It converts the list from v3 to a dictionary for uniform processing. ```python async def extract_tools(self, mcp) -> Dict[str, Any]: try: # Try v3 API first (list_tools returns list) if hasattr(mcp, 'list_tools'): tools = await mcp.list_tools() # Convert list to dict for uniform processing tools_dict = {tool.name: tool for tool in tools} if self.verbose: print(f"\nFound {len(tools_dict)} tools to document (fastmcp v3)") # Fall back to v2 API (get_tools returns dict) elif hasattr(mcp, 'get_tools'): tools_dict = await mcp.get_tools() if self.verbose: print(f"\nFound {len(tools_dict)} tools to document (fastmcp v2)") else: raise AttributeError("MCP server has neither list_tools() nor get_tools() methods") except Exception as e: # Handle errors... ``` -------------------------------- ### Advanced Configuration for FastMCPDocs Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md This advanced Python configuration for FastMCPDocs allows for detailed customization. It includes setting OpenAPI details, custom route paths, server information, and enabling/disabling features like CORS and verbose logging. ```python from fastmcp_docs import FastMCPDocs, FastMCPDocsConfig, DocsLink # Create custom configuration config = FastMCPDocsConfig( title="My MCP Tools", version="2.0.0", description="Advanced API documentation", base_url="https://api.example.com", docs_links=[ DocsLink(text="GitHub", url="https://github.com/..."), DocsLink(text="Docs", url="https://docs.example.com") ], page_title_emoji="🤖", favicon_url="https://example.com/favicon.ico", # Customize route paths api_tools_route="/api/tools", openapi_route="/openapi.json", docs_ui_route="/docs", # OpenAPI settings openapi_version="3.1.0", openapi_servers=[ {"url": "https://api.example.com", "description": "Production"}, {"url": "https://staging.example.com", "description": "Staging"} ], # Options enable_cors=True, verbose=True ) # Use custom config docs = FastMCPDocs(mcp, config=config) ``` -------------------------------- ### Adding Documentation Links to FastMCPDocs Source: https://github.com/orco82/fastmcp-docs/blob/main/README.md This Python code illustrates how to add external links to the FastMCP documentation UI. The `docs_links` parameter accepts a list of dictionaries, where each dictionary specifies the text and URL for a link. ```python docs = FastMCPDocs( mcp=mcp, title="My MCP Tools", docs_links=[ {"text": "GitHub Repository", "url": "https://github.com/..."}, {"text": "User Guide", "url": "https://docs.example.com"}, {"text": "API Reference", "url": "https://api.example.com/reference"} ] ) ``` -------------------------------- ### Type Checking with Mypy Source: https://github.com/orco82/fastmcp-docs/blob/main/CLAUDE.md Command to perform static type checking on the fastmcp_docs/ directory using Mypy. This helps catch type-related errors before runtime. ```bash # Type check with mypy mypy fastmcp_docs/ ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.