diff --git a/examples/01_basic_usage_example.py b/examples/01_basic_usage_example.py index 470dab9..d387458 100644 --- a/examples/01_basic_usage_example.py +++ b/examples/01_basic_usage_example.py @@ -1,4 +1,4 @@ -from examples.shared.apps.items import app # The FastAPI app +from examples.shared.apps.items import app # The FastAPI app from examples.shared.setup import setup_logging from fastapi_mcp import FastApiMCP @@ -15,4 +15,4 @@ if __name__ == "__main__": import uvicorn - uvicorn.run(app, host="0.0.0.0", port=8000) \ No newline at end of file + uvicorn.run(app, host="0.0.0.0", port=8000) diff --git a/examples/02_full_schema_description_example.py b/examples/02_full_schema_description_example.py index 9750c33..9210e18 100644 --- a/examples/02_full_schema_description_example.py +++ b/examples/02_full_schema_description_example.py @@ -1,8 +1,8 @@ - """ This example shows how to describe the full response schema instead of just a response example. """ -from examples.shared.apps.items import app # The FastAPI app + +from examples.shared.apps.items import app # The FastAPI app from examples.shared.setup import setup_logging from fastapi_mcp import FastApiMCP @@ -22,5 +22,5 @@ if __name__ == "__main__": import uvicorn - + uvicorn.run(app, host="0.0.0.0", port=8000) diff --git a/examples/03_custom_exposed_endpoints_example.py b/examples/03_custom_exposed_endpoints_example.py index 59e46e6..8d21ed8 100644 --- a/examples/03_custom_exposed_endpoints_example.py +++ b/examples/03_custom_exposed_endpoints_example.py @@ -6,7 +6,8 @@ - You can combine operation filtering with tag filtering (e.g., use `include_operations` with `include_tags`) - When combining filters, a greedy approach will be taken. Endpoints matching either criteria will be included """ -from examples.shared.apps.items import app # The FastAPI app + +from examples.shared.apps.items import app # The FastAPI app from examples.shared.setup import setup_logging from fastapi_mcp import FastApiMCP @@ -24,7 +25,7 @@ # Filter by excluding specific operation IDs exclude_operations_mcp = FastApiMCP( - app, + app, name="Item API MCP - Excluded Operations", exclude_operations=["create_item", "update_item", "delete_item"], ) diff --git a/examples/04_separate_server_example.py b/examples/04_separate_server_example.py index e468557..80f10da 100644 --- a/examples/04_separate_server_example.py +++ b/examples/04_separate_server_example.py @@ -2,6 +2,7 @@ This example shows how to run the MCP server and the FastAPI app separately. You can create an MCP server from one FastAPI app, and mount it to a different app. """ + from fastapi import FastAPI from examples.shared.apps.items import app @@ -30,4 +31,4 @@ if __name__ == "__main__": import uvicorn - uvicorn.run(mcp_app, host="0.0.0.0", port=8000) \ No newline at end of file + uvicorn.run(mcp_app, host="0.0.0.0", port=8000) diff --git a/examples/05_reregister_tools_example.py b/examples/05_reregister_tools_example.py index d30ce49..14e6f41 100644 --- a/examples/05_reregister_tools_example.py +++ b/examples/05_reregister_tools_example.py @@ -1,15 +1,16 @@ """ This example shows how to re-register tools if you add endpoints after the MCP server was created. """ -from examples.shared.apps.items import app # The FastAPI app + +from examples.shared.apps.items import app # The FastAPI app from examples.shared.setup import setup_logging from fastapi_mcp import FastApiMCP setup_logging() -mcp = FastApiMCP(app) # Add MCP server to the FastAPI app -mcp.mount() # MCP server +mcp = FastApiMCP(app) # Add MCP server to the FastAPI app +mcp.mount() # MCP server # This endpoint will not be registered as a tool, since it was added after the MCP instance was created @@ -24,5 +25,5 @@ async def new_endpoint(): if __name__ == "__main__": import uvicorn - + uvicorn.run(app, host="0.0.0.0", port=8000) diff --git a/examples/06_custom_mcp_router_example.py b/examples/06_custom_mcp_router_example.py index 83ea6ad..b69ac09 100644 --- a/examples/06_custom_mcp_router_example.py +++ b/examples/06_custom_mcp_router_example.py @@ -1,7 +1,8 @@ """ This example shows how to mount the MCP server to a specific APIRouter, giving a custom mount path. """ -from examples.shared.apps.items import app # The FastAPI app + +from examples.shared.apps.items import app # The FastAPI app from examples.shared.setup import setup_logging from fastapi import APIRouter @@ -9,7 +10,7 @@ setup_logging() -other_router = APIRouter(prefix="/other/route") +other_router = APIRouter(prefix="/other/route") app.include_router(other_router) mcp = FastApiMCP(app) @@ -21,5 +22,5 @@ if __name__ == "__main__": import uvicorn - + uvicorn.run(app, host="0.0.0.0", port=8000) diff --git a/examples/07_configure_http_timeout_example.py b/examples/07_configure_http_timeout_example.py index eaab570..036c103 100644 --- a/examples/07_configure_http_timeout_example.py +++ b/examples/07_configure_http_timeout_example.py @@ -2,7 +2,8 @@ This example shows how to configure the HTTP client timeout for the MCP server. In case you have API endpoints that take longer than 5 seconds to respond, you can increase the timeout. """ -from examples.shared.apps.items import app # The FastAPI app + +from examples.shared.apps.items import app # The FastAPI app from examples.shared.setup import setup_logging import httpx @@ -12,14 +13,11 @@ setup_logging() -mcp = FastApiMCP( - app, - http_client=httpx.AsyncClient(timeout=20) -) +mcp = FastApiMCP(app, http_client=httpx.AsyncClient(timeout=20)) mcp.mount() if __name__ == "__main__": import uvicorn - + uvicorn.run(app, host="0.0.0.0", port=8000) diff --git a/fastapi_mcp/openapi/convert.py b/fastapi_mcp/openapi/convert.py index 439d9a0..8e1716f 100644 --- a/fastapi_mcp/openapi/convert.py +++ b/fastapi_mcp/openapi/convert.py @@ -200,7 +200,8 @@ def convert_openapi_to_mcp_tools( for param_name, param in path_params: param_schema = param.get("schema", {}) param_desc = param.get("description", "") - param_required = param.get("required", True) # Path params are usually required + # Path params are usually required + param_required = param.get("required", True) properties[param_name] = param_schema.copy() properties[param_name]["title"] = param_name @@ -236,6 +237,7 @@ def convert_openapi_to_mcp_tools( # Add body parameters to properties for param_name, param in body_params: param_schema = param.get("schema", {}) + param_desc = param.get("description", "") param_required = param.get("required", False) properties[param_name] = param_schema.copy()