@@ -41,7 +41,7 @@ export const crawlTool: ToolConfig<FirecrawlCrawlParams, FirecrawlCrawlResponse>
4141 required : false ,
4242 visibility : 'user-or-llm' ,
4343 description :
44- 'Maximum depth to crawl from the starting URL (e.g., 1, 2, 3 ). Controls how many levels deep to follow links ' ,
44+ 'Maximum URL path depth (e.g., 1 allows /docs and /docs/index.html ). Independent of link discovery depth ' ,
4545 } ,
4646 formats : {
4747 type : 'json' ,
@@ -130,7 +130,7 @@ export const crawlTool: ToolConfig<FirecrawlCrawlParams, FirecrawlCrawlResponse>
130130 Authorization : `Bearer ${ params . apiKey } ` ,
131131 } ) ,
132132 body : ( params ) => {
133- const body : Record < string , any > = {
133+ const body : Record < string , unknown > = {
134134 url : params . url ,
135135 limit : Number ( params . limit ) || 100 ,
136136 scrapeOptions : params . scrapeOptions || {
@@ -140,8 +140,8 @@ export const crawlTool: ToolConfig<FirecrawlCrawlParams, FirecrawlCrawlResponse>
140140 }
141141
142142 if ( params . prompt ) body . prompt = params . prompt
143- if ( params . maxDepth ) body . maxDiscoveryDepth = Number ( params . maxDepth )
144- if ( params . maxDiscoveryDepth ) body . maxDiscoveryDepth = Number ( params . maxDiscoveryDepth )
143+ if ( params . maxDiscoveryDepth != null )
144+ body . maxDiscoveryDepth = Number ( params . maxDiscoveryDepth )
145145 if ( params . sitemap ) body . sitemap = params . sitemap
146146 if ( typeof params . crawlEntireDomain === 'boolean' )
147147 body . crawlEntireDomain = params . crawlEntireDomain
@@ -154,6 +154,23 @@ export const crawlTool: ToolConfig<FirecrawlCrawlParams, FirecrawlCrawlResponse>
154154 if ( params . maxConcurrency ) body . maxConcurrency = Number ( params . maxConcurrency )
155155 if ( params . excludePaths ) body . excludePaths = params . excludePaths
156156 if ( params . includePaths ) body . includePaths = params . includePaths
157+ if ( params . maxDepth != null ) {
158+ const maxDepth = Number ( params . maxDepth )
159+ if ( ! Number . isSafeInteger ( maxDepth ) || maxDepth < 0 ) {
160+ throw new Error ( 'maxDepth must be a non-negative integer' )
161+ }
162+
163+ // v1 depth counted URL path segments; v2 discovery depth counts link hops.
164+ body . regexOnFullURL = false
165+ if ( params . includePaths ?. length ) {
166+ body . excludePaths = [ ...( params . excludePaths ?? [ ] ) , `^(/+[^/]+){${ maxDepth + 1 } }` ]
167+ } else {
168+ body . includePaths = [
169+ `^(/+[^/]+){0,${ maxDepth } }/*$` ,
170+ `^(/+[^/]+){0,${ maxDepth } }/+index\\.(html|php)/*$` ,
171+ ]
172+ }
173+ }
157174 if ( params . webhook ) body . webhook = params . webhook
158175 if ( typeof params . zeroDataRetention === 'boolean' )
159176 body . zeroDataRetention = params . zeroDataRetention
0 commit comments