@@ -53,4 +53,52 @@ def test_servers_order(self, test_files_path):
53
53
assert op .get_server () == "https://inoperation.example.com"
54
54
op = config .openapi_spec .find_operation_by_id ("missing_operation_id_get" )
55
55
assert op .get_server () == "http://localhost"
56
+
57
+ def test_allowed_operations (self ):
58
+ """
59
+ Although the tool definition is generated from the OpenAPI spec and
60
+ firecrawl's API has multiple operations, only the ones we specify in the
61
+ allowed_operations list are registered with LLMs via the tool definition.
62
+ """
63
+
64
+ spec = "https://raw.githubusercontent.com/mendableai/firecrawl/main/apps/api/openapi.json"
65
+
66
+ config = ClientConfig (
67
+ openapi_spec = create_openapi_spec (spec ),
68
+ request_sender = FastAPITestClient (None ),
69
+ allowed_operations = ["scrape" ],
70
+ )
71
+ tools = config .get_tool_definitions ()
72
+ assert len (tools ) == 1
73
+ assert tools [0 ]["function" ]["name" ] == "scrape"
74
+
75
+ # test two operations
76
+ config = ClientConfig (
77
+ openapi_spec = create_openapi_spec (spec ),
78
+ request_sender = FastAPITestClient (None ),
79
+ allowed_operations = ["scrape" , "crawlUrls" ],
80
+ )
81
+ tools = config .get_tool_definitions ()
82
+ assert len (tools ) == 2
83
+ assert tools [0 ]["function" ]["name" ] == "scrape"
84
+ assert tools [1 ]["function" ]["name" ] == "crawlUrls"
85
+
86
+ # test non-existent operation
87
+ config = ClientConfig (
88
+ openapi_spec = create_openapi_spec (spec ),
89
+ request_sender = FastAPITestClient (None ),
90
+ allowed_operations = ["scrape" , "non-existent-operation" ],
91
+ )
92
+ tools = config .get_tool_definitions ()
93
+ assert len (tools ) == 1
94
+ assert tools [0 ]["function" ]["name" ] == "scrape"
95
+
96
+ # test all non-existent operations
97
+ config = ClientConfig (
98
+ openapi_spec = create_openapi_spec (spec ),
99
+ request_sender = FastAPITestClient (None ),
100
+ allowed_operations = ["non-existent-operation" , "non-existent-operation-2" ],
101
+ )
102
+ tools = config .get_tool_definitions ()
103
+ assert len (tools ) == 0
56
104
0 commit comments