Skip to content

Commit 3450638

Browse files
committed
Nick: fix self hosted instances do not require an api key
1 parent 467cafd commit 3450638

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "firecrawl-mcp",
3-
"version": "3.1.13",
3+
"version": "3.2.0",
44
"description": "MCP server for Firecrawl web scraping integration. Supports both cloud and self-hosted instances. Features include web scraping, search, batch processing, structured data extraction, and LLM-powered content analysis.",
55
"type": "module",
66
"bin": {

src/index.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import type { IncomingHttpHeaders } from 'http';
88
dotenv.config({ debug: false, quiet: true });
99

1010
interface SessionData {
11-
firecrawlApiKey: string;
11+
firecrawlApiKey?: string;
1212
[key: string]: unknown;
1313
}
1414

@@ -99,8 +99,9 @@ const server = new FastMCP<SessionData>({
9999
}
100100
return { firecrawlApiKey: apiKey };
101101
} else {
102-
if (!process.env.FIRECRAWL_API_KEY) {
103-
console.error('Firecrawl API key is required');
102+
// For self-hosted instances, API key is optional if FIRECRAWL_API_URL is provided
103+
if (!process.env.FIRECRAWL_API_KEY && !process.env.FIRECRAWL_API_URL) {
104+
console.error('Either FIRECRAWL_API_KEY or FIRECRAWL_API_URL must be provided');
104105
process.exit(1);
105106
}
106107
return { firecrawlApiKey: process.env.FIRECRAWL_API_KEY };
@@ -115,22 +116,38 @@ const server = new FastMCP<SessionData>({
115116
},
116117
});
117118

118-
function createClient(apiKey: string): FirecrawlApp {
119-
return new FirecrawlApp({
120-
apiKey,
119+
function createClient(apiKey?: string): FirecrawlApp {
120+
const config: any = {
121121
...(process.env.FIRECRAWL_API_URL && {
122122
apiUrl: process.env.FIRECRAWL_API_URL,
123123
}),
124-
});
124+
};
125+
126+
// Only add apiKey if it's provided (required for cloud, optional for self-hosted)
127+
if (apiKey) {
128+
config.apiKey = apiKey;
129+
}
130+
131+
return new FirecrawlApp(config);
125132
}
126133

127134
const ORIGIN = 'mcp-fastmcp';
128135

129136
function getClient(session?: SessionData): FirecrawlApp {
130-
if (!session || !session.firecrawlApiKey) {
131-
throw new Error('Unauthorized');
137+
// For cloud service, API key is required
138+
if (process.env.CLOUD_SERVICE === 'true') {
139+
if (!session || !session.firecrawlApiKey) {
140+
throw new Error('Unauthorized');
141+
}
142+
return createClient(session.firecrawlApiKey);
143+
}
144+
145+
// For self-hosted instances, API key is optional if FIRECRAWL_API_URL is provided
146+
if (!process.env.FIRECRAWL_API_URL && (!session || !session.firecrawlApiKey)) {
147+
throw new Error('Unauthorized: API key is required when not using a self-hosted instance');
132148
}
133-
return createClient(session.firecrawlApiKey);
149+
150+
return createClient(session?.firecrawlApiKey);
134151
}
135152

136153
function asText(data: unknown): string {

0 commit comments

Comments
 (0)