|
1 | 1 | from examples.shared.apps import items |
2 | 2 | from examples.shared.setup import setup_logging |
3 | 3 |
|
| 4 | +from fastapi import FastAPI |
4 | 5 | from fastapi_mcp import FastApiMCP |
5 | 6 |
|
6 | 7 | setup_logging() |
7 | 8 |
|
| 9 | +app = FastAPI() |
| 10 | +app.include_router(items.router) |
| 11 | + |
8 | 12 | # Example demonstrating how to filter MCP tools by operation IDs and tags |
9 | 13 |
|
10 | 14 | # Filter by including specific operation IDs |
11 | 15 | include_operations_mcp = FastApiMCP( |
12 | | - items.app, |
| 16 | + app, |
13 | 17 | name="Item API MCP - Included Operations", |
14 | 18 | description="MCP server showing only specific operations", |
15 | | - base_url="http://localhost:8000", |
16 | 19 | include_operations=["get_item", "list_items"], |
17 | 20 | ) |
18 | 21 |
|
19 | 22 | # Filter by excluding specific operation IDs |
20 | 23 | exclude_operations_mcp = FastApiMCP( |
21 | | - items.app, |
| 24 | + app, |
22 | 25 | name="Item API MCP - Excluded Operations", |
23 | 26 | description="MCP server showing all operations except the excluded ones", |
24 | | - base_url="http://localhost:8000", |
25 | 27 | exclude_operations=["create_item", "update_item", "delete_item"], |
26 | 28 | ) |
27 | 29 |
|
28 | 30 | # Filter by including specific tags |
29 | 31 | include_tags_mcp = FastApiMCP( |
30 | | - items.app, |
| 32 | + app, |
31 | 33 | name="Item API MCP - Included Tags", |
32 | 34 | description="MCP server showing operations with specific tags", |
33 | | - base_url="http://localhost:8000", |
34 | 35 | include_tags=["items"], |
35 | 36 | ) |
36 | 37 |
|
37 | 38 | # Filter by excluding specific tags |
38 | 39 | exclude_tags_mcp = FastApiMCP( |
39 | | - items.app, |
| 40 | + app, |
40 | 41 | name="Item API MCP - Excluded Tags", |
41 | 42 | description="MCP server showing operations except those with specific tags", |
42 | | - base_url="http://localhost:8000", |
43 | 43 | exclude_tags=["search"], |
44 | 44 | ) |
45 | 45 |
|
46 | 46 | # Combine operation IDs and tags (include mode) |
47 | 47 | combined_include_mcp = FastApiMCP( |
48 | | - items.app, |
| 48 | + app, |
49 | 49 | name="Item API MCP - Combined Include", |
50 | 50 | description="MCP server showing operations by combining include filters", |
51 | | - base_url="http://localhost:8000", |
52 | 51 | include_operations=["delete_item"], |
53 | 52 | include_tags=["search"], |
54 | 53 | ) |
|
69 | 68 | print(" - /include-tags-mcp: Only operations with the 'items' tag") |
70 | 69 | print(" - /exclude-tags-mcp: All operations except those with the 'search' tag") |
71 | 70 | print(" - /combined-include-mcp: Operations with 'search' tag or delete_item operation") |
72 | | - uvicorn.run(items.app, host="0.0.0.0", port=8000) |
| 71 | + uvicorn.run(items.router, host="0.0.0.0", port=8000) |
0 commit comments