Skip to content

Granular control over which endpoints are being exposed as tools #49

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 10, 2025

Conversation

shahar4499
Copy link
Contributor

This PR allows selectively exposing a subset of FastAPI endpoints as MCP tools, instead of all-or-nothing.

This provides granular control over which API endpoints are exposed as tools

How it works

New optional parameters have been added to the FastApiMCP constructor:

  • include_operations: List of operation IDs to expose as MCP tools
  • exclude_operations: List of operation IDs to exclude from MCP tools
  • include_tags: List of OpenAPI tags to include as MCP tools
  • exclude_tags: List of OpenAPI tags to exclude from MCP tools

Notes:

  • You can combine operation filtering with tag filtering (e.g., use include_operations with include_tags)
  • When combining filters, endpoints matching either criteria will be included (union operation)
  • You cannot use both include_operations and exclude_operations simultaneously
  • You cannot use both include_tags and exclude_tags simultaneously

Usage Example

from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

app = FastAPI()

# Only include specific operations
mcp = FastApiMCP(
    app,
    include_operations=["get_user", "create_user"]
)

# Or exclude operations with specific tags
mcp = FastApiMCP(
    app,
    exclude_tags=["admin", "internal"]
)

mcp.mount()

Copy link

codecov bot commented Apr 10, 2025

Codecov Report

Attention: Patch coverage is 95.65217% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
fastapi_mcp/server.py 95.65% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@shahar4499 shahar4499 merged commit ca7b1f4 into main Apr 10, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant