firecrawl_mcp/controller/
map.rs

1use async_claude::define_tool;
2use firecrawl_sdk::map::MapUrlInput;
3use rmcp::{handler::server::tool::parse_json_object, model::JsonObject};
4use serde_json::json;
5
6use crate::controller::FirecrawlMCP;
7
8pub const MAP_TOOL_NAME: &str = "firecrawl_map";
9pub const MAP_TOOL_DESCRIPTION: &str =
10    "Discover URLs from a starting point. Can use both sitemap.xml and HTML link discovery.";
11
12define_tool!(
13    FIRECRAWL_MAP,
14    MAP_TOOL_NAME,
15    MAP_TOOL_DESCRIPTION,
16    MapUrlInput
17);
18
19impl FirecrawlMCP {
20    pub async fn map(&self, input: JsonObject) -> Result<String, rmcp::Error> {
21        // Deserialize the json object into a MapUrlInput struct
22        let options = parse_json_object::<MapUrlInput>(input)?;
23
24        // Call the map_url method from the firecrawl SDK
25        let result = self
26            .client
27            .map_url(options.url, Some(options.options))
28            .await
29            .map_err(|e| rmcp::Error::internal_error(e.to_string(), None))?;
30
31        // Format the result as a JSON array of URLs
32        let json_result = json!(result);
33        serde_json::to_string_pretty(&json_result)
34            .map_err(|e| rmcp::Error::internal_error(e.to_string(), None))
35    }
36}