firecrawl-mcp 2.0.2 ā 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index-v1.js +1313 -0
- package/dist/index.js +298 -1262
- package/dist/server-v1.js +1154 -0
- package/dist/server-v2.js +1067 -0
- package/dist/versioned-server.js +203 -0
- package/package.json +12 -22
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
|
|
3
|
+
import express from 'express';
|
|
4
|
+
import dotenv from 'dotenv';
|
|
5
|
+
import { createV1Server } from './server-v1.js';
|
|
6
|
+
import { createV2Server } from './server-v2.js';
|
|
7
|
+
dotenv.config();
|
|
8
|
+
export async function runVersionedSSECloudServer() {
|
|
9
|
+
const transports = {};
|
|
10
|
+
const app = express();
|
|
11
|
+
// Health check endpoint
|
|
12
|
+
app.get('/health', (req, res) => {
|
|
13
|
+
res.status(200).json({
|
|
14
|
+
status: 'OK',
|
|
15
|
+
versions: ['v1', 'v2'],
|
|
16
|
+
endpoints: {
|
|
17
|
+
v1: {
|
|
18
|
+
sse: '/{apiKey}/sse',
|
|
19
|
+
messages: '/{apiKey}/messages'
|
|
20
|
+
},
|
|
21
|
+
v2: {
|
|
22
|
+
sse: '/{apiKey}/v2/sse',
|
|
23
|
+
messages: '/{apiKey}/v2/messages'
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
// Create server instances
|
|
29
|
+
const v1Server = createV1Server();
|
|
30
|
+
const v2Server = createV2Server();
|
|
31
|
+
// V1 SSE endpoint (legacy)
|
|
32
|
+
app.get('/:apiKey/sse', async (req, res) => {
|
|
33
|
+
const apiKey = req.params.apiKey;
|
|
34
|
+
const transport = new SSEServerTransport(`/${apiKey}/messages`, res);
|
|
35
|
+
console.log(`[V1] New SSE connection for API key: ${apiKey}`);
|
|
36
|
+
const compositeKey = `${apiKey}-${transport.sessionId}`;
|
|
37
|
+
transports[compositeKey] = { transport, version: 'v1' };
|
|
38
|
+
res.on('close', () => {
|
|
39
|
+
console.log(`[V1] SSE connection closed for: ${compositeKey}`);
|
|
40
|
+
delete transports[compositeKey];
|
|
41
|
+
});
|
|
42
|
+
await v1Server.connect(transport);
|
|
43
|
+
});
|
|
44
|
+
// V1 SSE HEAD for quick availability checks
|
|
45
|
+
app.head('/:apiKey/sse', (req, res) => {
|
|
46
|
+
res.status(200).end();
|
|
47
|
+
});
|
|
48
|
+
// V2 SSE endpoint (new)
|
|
49
|
+
app.get('/:apiKey/v2/sse', async (req, res) => {
|
|
50
|
+
const apiKey = req.params.apiKey;
|
|
51
|
+
const transport = new SSEServerTransport(`/${apiKey}/v2/messages`, res);
|
|
52
|
+
console.log(`[V2] New SSE connection for API key: ${apiKey}`);
|
|
53
|
+
const compositeKey = `${apiKey}-${transport.sessionId}`;
|
|
54
|
+
transports[compositeKey] = { transport, version: 'v2' };
|
|
55
|
+
res.on('close', () => {
|
|
56
|
+
console.log(`[V2] SSE connection closed for: ${compositeKey}`);
|
|
57
|
+
delete transports[compositeKey];
|
|
58
|
+
});
|
|
59
|
+
await v2Server.connect(transport);
|
|
60
|
+
});
|
|
61
|
+
// V2 SSE HEAD for quick availability checks
|
|
62
|
+
app.head('/:apiKey/v2/sse', (req, res) => {
|
|
63
|
+
res.status(200).end();
|
|
64
|
+
});
|
|
65
|
+
// V1 message endpoint (legacy)
|
|
66
|
+
app.post('/:apiKey/messages', express.json(), async (req, res) => {
|
|
67
|
+
const apiKey = req.params.apiKey;
|
|
68
|
+
const body = req.body;
|
|
69
|
+
// Enrich the body with API key metadata
|
|
70
|
+
const enrichedBody = {
|
|
71
|
+
...body,
|
|
72
|
+
};
|
|
73
|
+
if (enrichedBody && enrichedBody.params && !enrichedBody.params._meta) {
|
|
74
|
+
enrichedBody.params._meta = { apiKey };
|
|
75
|
+
}
|
|
76
|
+
else if (enrichedBody &&
|
|
77
|
+
enrichedBody.params &&
|
|
78
|
+
enrichedBody.params._meta) {
|
|
79
|
+
enrichedBody.params._meta.apiKey = apiKey;
|
|
80
|
+
}
|
|
81
|
+
console.log(`[V1] Message received for API key: ${apiKey}`);
|
|
82
|
+
// Prefer explicit sessionId from query, then common header names
|
|
83
|
+
const rawSessionId = req.query.sessionId ||
|
|
84
|
+
req.headers['mcp-session-id'] ||
|
|
85
|
+
req.headers['x-mcp-session-id'] ||
|
|
86
|
+
'';
|
|
87
|
+
let compositeKey = `${apiKey}-${rawSessionId}`;
|
|
88
|
+
let versionedTransport = transports[compositeKey];
|
|
89
|
+
// Fallback: if not found, and there is exactly one active V1 transport for this apiKey, use it
|
|
90
|
+
if (!versionedTransport) {
|
|
91
|
+
const candidates = Object.entries(transports).filter(([key, vt]) => vt.version === 'v1' && key.startsWith(`${apiKey}-`));
|
|
92
|
+
if (candidates.length === 1) {
|
|
93
|
+
const [fallbackKey, vt] = candidates[0];
|
|
94
|
+
console.warn(`[V1] sessionId not provided or not found. Falling back to single active transport: ${fallbackKey}`);
|
|
95
|
+
compositeKey = fallbackKey;
|
|
96
|
+
versionedTransport = vt;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
if (versionedTransport && versionedTransport.version === 'v1') {
|
|
100
|
+
await versionedTransport.transport.handlePostMessage(req, res, enrichedBody);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
console.error(`[V1] No transport found for sessionId: ${compositeKey}`);
|
|
104
|
+
res.status(400).json({
|
|
105
|
+
error: 'No V1 transport found for sessionId',
|
|
106
|
+
sessionId: compositeKey,
|
|
107
|
+
availableTransports: Object.keys(transports)
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
// V2 message endpoint (new)
|
|
112
|
+
app.post('/:apiKey/v2/messages', express.json(), async (req, res) => {
|
|
113
|
+
const apiKey = req.params.apiKey;
|
|
114
|
+
const body = req.body;
|
|
115
|
+
// Enrich the body with API key metadata
|
|
116
|
+
const enrichedBody = {
|
|
117
|
+
...body,
|
|
118
|
+
};
|
|
119
|
+
if (enrichedBody && enrichedBody.params && !enrichedBody.params._meta) {
|
|
120
|
+
enrichedBody.params._meta = { apiKey };
|
|
121
|
+
}
|
|
122
|
+
else if (enrichedBody &&
|
|
123
|
+
enrichedBody.params &&
|
|
124
|
+
enrichedBody.params._meta) {
|
|
125
|
+
enrichedBody.params._meta.apiKey = apiKey;
|
|
126
|
+
}
|
|
127
|
+
console.log(`[V2] Message received for API key: ${apiKey}`);
|
|
128
|
+
const sessionId = req.query.sessionId;
|
|
129
|
+
const compositeKey = `${apiKey}-${sessionId}`;
|
|
130
|
+
const versionedTransport = transports[compositeKey];
|
|
131
|
+
if (versionedTransport && versionedTransport.version === 'v2') {
|
|
132
|
+
await versionedTransport.transport.handlePostMessage(req, res, enrichedBody);
|
|
133
|
+
}
|
|
134
|
+
else {
|
|
135
|
+
console.error(`[V2] No transport found for sessionId: ${compositeKey}`);
|
|
136
|
+
res.status(400).json({
|
|
137
|
+
error: 'No V2 transport found for sessionId',
|
|
138
|
+
sessionId: compositeKey,
|
|
139
|
+
availableTransports: Object.keys(transports)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
// Catch-all for unsupported endpoints
|
|
144
|
+
app.use((req, res) => {
|
|
145
|
+
res.status(404).json({
|
|
146
|
+
error: 'Endpoint not found',
|
|
147
|
+
supportedEndpoints: {
|
|
148
|
+
health: '/health',
|
|
149
|
+
v1: {
|
|
150
|
+
sse: '/:apiKey/sse',
|
|
151
|
+
messages: '/:apiKey/messages'
|
|
152
|
+
},
|
|
153
|
+
v2: {
|
|
154
|
+
sse: '/:apiKey/v2/sse',
|
|
155
|
+
messages: '/:apiKey/v2/messages'
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
});
|
|
160
|
+
const PORT = process.env.PORT || 3000;
|
|
161
|
+
const server = app.listen(PORT, () => {
|
|
162
|
+
console.log(`š Versioned MCP SSE Server listening on http://localhost:${PORT}`);
|
|
163
|
+
console.log('š Available endpoints:');
|
|
164
|
+
console.log(` Health: http://localhost:${PORT}/health`);
|
|
165
|
+
console.log(` V1 SSE: http://localhost:${PORT}/{apiKey}/sse`);
|
|
166
|
+
console.log(` V1 Messages: http://localhost:${PORT}/{apiKey}/messages`);
|
|
167
|
+
console.log(` V2 SSE: http://localhost:${PORT}/{apiKey}/v2/sse`);
|
|
168
|
+
console.log(` V2 Messages: http://localhost:${PORT}/{apiKey}/v2/messages`);
|
|
169
|
+
console.log('');
|
|
170
|
+
console.log('š§ Versions:');
|
|
171
|
+
console.log(' V1: Firecrawl JS 1.29.3 (legacy tools + deep research + llms.txt)');
|
|
172
|
+
console.log(' V2: Firecrawl JS 3.1.0 (modern API + JSON extraction)');
|
|
173
|
+
});
|
|
174
|
+
server.on('error', (error) => {
|
|
175
|
+
console.error('ā Server error:', error);
|
|
176
|
+
if (error.code === 'EADDRINUSE') {
|
|
177
|
+
console.error(`ā Port ${PORT} is already in use. Please use a different port.`);
|
|
178
|
+
}
|
|
179
|
+
process.exit(1);
|
|
180
|
+
});
|
|
181
|
+
// Graceful shutdown
|
|
182
|
+
process.on('SIGINT', () => {
|
|
183
|
+
console.log('\nš Shutting down server...');
|
|
184
|
+
console.log(`š Active connections: ${Object.keys(transports).length}`);
|
|
185
|
+
// Close all transports
|
|
186
|
+
for (const [key, versionedTransport] of Object.entries(transports)) {
|
|
187
|
+
try {
|
|
188
|
+
console.log(`š Closing transport: ${key} (${versionedTransport.version})`);
|
|
189
|
+
// Note: SSEServerTransport doesn't have a close method, connections will close naturally
|
|
190
|
+
delete transports[key];
|
|
191
|
+
}
|
|
192
|
+
catch (error) {
|
|
193
|
+
console.error(`ā Error closing transport ${key}:`, error);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
console.log('ā
Server shutdown complete');
|
|
197
|
+
process.exit(0);
|
|
198
|
+
});
|
|
199
|
+
}
|
|
200
|
+
// Start the server if this file is run directly
|
|
201
|
+
// if (import.meta.url === `file://${process.argv[1]}`) {
|
|
202
|
+
// runVersionedSSECloudServer().catch(console.error);
|
|
203
|
+
// }
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "firecrawl-mcp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"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.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"bin": {
|
|
@@ -15,7 +15,10 @@
|
|
|
15
15
|
"scripts": {
|
|
16
16
|
"build": "tsc && node -e \"require('fs').chmodSync('dist/index.js', '755')\"",
|
|
17
17
|
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
|
|
18
|
+
"test:endpoints": "node test-endpoints.js",
|
|
18
19
|
"start": "node dist/index.js",
|
|
20
|
+
"start:cloud": "CLOUD_SERVICE=true node dist/index.js",
|
|
21
|
+
"start:fastmcp": "node dist/fastmcp/server.js",
|
|
19
22
|
"lint": "eslint src/**/*.ts",
|
|
20
23
|
"lint:fix": "eslint src/**/*.ts --fix",
|
|
21
24
|
"format": "prettier --write .",
|
|
@@ -25,27 +28,11 @@
|
|
|
25
28
|
},
|
|
26
29
|
"license": "MIT",
|
|
27
30
|
"dependencies": {
|
|
28
|
-
"@mendable/firecrawl-js": "^3.
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"express": "^5.1.0",
|
|
32
|
-
"shx": "^0.3.4",
|
|
31
|
+
"@mendable/firecrawl-js": "^4.3.4",
|
|
32
|
+
"dotenv": "^17.2.2",
|
|
33
|
+
"fastmcp": "^3.16.0",
|
|
33
34
|
"typescript": "^5.9.2",
|
|
34
|
-
"
|
|
35
|
-
},
|
|
36
|
-
"devDependencies": {
|
|
37
|
-
"@jest/globals": "^29.7.0",
|
|
38
|
-
"@types/express": "^5.0.1",
|
|
39
|
-
"@types/jest": "^29.5.14",
|
|
40
|
-
"@types/node": "^20.10.5",
|
|
41
|
-
"@typescript-eslint/eslint-plugin": "^7.0.0",
|
|
42
|
-
"@typescript-eslint/parser": "^7.0.0",
|
|
43
|
-
"eslint": "^8.56.0",
|
|
44
|
-
"eslint-config-prettier": "^9.1.0",
|
|
45
|
-
"jest": "^29.7.0",
|
|
46
|
-
"jest-mock-extended": "^4.0.0-beta1",
|
|
47
|
-
"prettier": "^3.1.1",
|
|
48
|
-
"ts-jest": "^29.1.1"
|
|
35
|
+
"zod": "^4.1.5"
|
|
49
36
|
},
|
|
50
37
|
"engines": {
|
|
51
38
|
"node": ">=18.0.0"
|
|
@@ -65,5 +52,8 @@
|
|
|
65
52
|
"bugs": {
|
|
66
53
|
"url": "https://github.com/firecrawl/firecrawl-mcp-server/issues"
|
|
67
54
|
},
|
|
68
|
-
"homepage": "https://github.com/firecrawl/firecrawl-mcp-server#readme"
|
|
55
|
+
"homepage": "https://github.com/firecrawl/firecrawl-mcp-server#readme",
|
|
56
|
+
"devDependencies": {
|
|
57
|
+
"@types/node": "^24.3.1"
|
|
58
|
+
}
|
|
69
59
|
}
|