Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 38 additions & 0 deletions src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ interface MockFirecrawlClient {
checkBatchScrapeStatus(id: string): Promise<BatchScrapeStatusResponse>;
asyncCrawlUrl(url: string, options?: any): Promise<CrawlResponse>;
checkCrawlStatus(id: string): Promise<CrawlStatusResponse>;
cancelCrawl(id: string): Promise<{ success: boolean; error?: string }>;
mapUrl(url: string, options?: any): Promise<{ links: string[] }>;
}

Expand Down Expand Up @@ -257,6 +258,27 @@ describe('Firecrawl Tool Tests', () => {
});
});

// Test cancel crawl functionality
test('should handle cancel crawl request', async () => {
const crawlId = 'test-crawl-id';

mockClient.cancelCrawl.mockResolvedValueOnce({
success: true,
});

const response = await requestHandler({
method: 'call_tool',
params: {
name: 'firecrawl_cancel_crawl',
arguments: { id: crawlId },
},
});

expect(response.isError).toBe(false);
expect(response.content[0].text).toContain('cancelled successfully');
expect(mockClient.cancelCrawl).toHaveBeenCalledWith(crawlId);
});

// Test error handling
test('should handle API errors', async () => {
const url = 'https://example.com';
Expand Down Expand Up @@ -371,6 +393,22 @@ async function handleRequest(
};
}

case 'firecrawl_cancel_crawl': {
const response = await client.cancelCrawl(args.id);
if (!response.success) {
throw new Error(response.error || 'Failed to cancel crawl');
}
return {
content: [
{
type: 'text',
text: `Crawl job ${args.id} has been cancelled successfully.`,
},
],
isError: false,
};
}

default:
throw new Error(`Unknown tool: ${name}`);
}
Expand Down
61 changes: 61 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,35 @@ Check the status of a crawl job.
},
};

const CANCEL_CRAWL_TOOL: Tool = {
name: 'firecrawl_cancel_crawl',
description: `
Cancel a running crawl job.

**Best for:** Stopping crawl operations that are taking too long or are no longer needed.
**Usage Example:**
\`\`\`json
{
"name": "firecrawl_cancel_crawl",
"arguments": {
"id": "550e8400-e29b-41d4-a716-446655440000"
}
}
\`\`\`
**Returns:** Confirmation that the crawl job has been cancelled.
`,
inputSchema: {
type: 'object',
properties: {
id: {
type: 'string',
description: 'Crawl job ID to cancel',
},
},
required: ['id'],
},
};

const SEARCH_TOOL: Tool = {
name: 'firecrawl_search',
description: `
Expand Down Expand Up @@ -818,6 +847,15 @@ function isStatusCheckOptions(args: unknown): args is StatusCheckOptions {
);
}

function isCancelCrawlOptions(args: unknown): args is StatusCheckOptions {
return (
typeof args === 'object' &&
args !== null &&
'id' in args &&
typeof (args as { id: unknown }).id === 'string'
);
}

function isSearchOptions(args: unknown): args is SearchOptions {
return (
typeof args === 'object' &&
Expand Down Expand Up @@ -965,6 +1003,7 @@ server.setRequestHandler(ListToolsRequestSchema, async () => ({
MAP_TOOL,
CRAWL_TOOL,
CHECK_CRAWL_STATUS_TOOL,
CANCEL_CRAWL_TOOL,
SEARCH_TOOL,
EXTRACT_TOOL,
DEEP_RESEARCH_TOOL,
Expand Down Expand Up @@ -1155,6 +1194,28 @@ ${
};
}

case 'firecrawl_cancel_crawl': {
if (!isCancelCrawlOptions(args)) {
throw new Error('Invalid arguments for firecrawl_cancel_crawl');
}
const response = await withRetry(
async () => client.cancelCrawl(args.id),
'cancel crawl operation'
);
if (!response.success) {
throw new Error(response.error || 'Failed to cancel crawl');
}
return {
content: [
{
type: 'text',
text: trimResponseText(`Crawl job ${args.id} has been cancelled successfully.`),
},
],
isError: false,
};
}

case 'firecrawl_search': {
if (!isSearchOptions(args)) {
throw new Error('Invalid arguments for firecrawl_search');
Expand Down