File tree Expand file tree Collapse file tree 4 files changed +37
-59
lines changed Expand file tree Collapse file tree 4 files changed +37
-59
lines changed Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ import { StreamableHTTPServerTransport } from '@modelcontextprotocol/sdk/server/
19
19
import express , { Request , Response } from 'express' ;
20
20
import dotenv from 'dotenv' ;
21
21
import { randomUUID } from 'node:crypto' ;
22
+ import { safeLog } from './utils/log.js' ;
22
23
23
24
dotenv . config ( ) ;
24
25
@@ -933,29 +934,6 @@ function delay(ms: number): Promise<void> {
933
934
934
935
let isStdioTransport = false ;
935
936
936
- function safeLog (
937
- level :
938
- | 'error'
939
- | 'debug'
940
- | 'info'
941
- | 'notice'
942
- | 'warning'
943
- | 'critical'
944
- | 'alert'
945
- | 'emergency' ,
946
- data : any
947
- ) : void {
948
- try {
949
- // Always log to stderr to avoid relying on MCP logging capability
950
- const message = `[${ level } ] ${
951
- typeof data === 'object' ? JSON . stringify ( data ) : String ( data )
952
- } `;
953
- console . error ( message ) ;
954
- } catch ( _ ) {
955
- // ignore
956
- }
957
- }
958
-
959
937
// Add retry logic with exponential backoff
960
938
async function withRetry < T > (
961
939
operation : ( ) = > Promise < T > ,
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ import FirecrawlApp, {
16
16
17
17
// import express, { Request, Response } from 'express';
18
18
import dotenv from 'dotenv' ;
19
+ import { safeLog } from './utils/log.js' ;
19
20
20
21
dotenv . config ( ) ;
21
22
@@ -875,24 +876,7 @@ export function createV1Server() {
875
876
return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
876
877
}
877
878
878
- function safeLog (
879
- level :
880
- | 'error'
881
- | 'debug'
882
- | 'info'
883
- | 'notice'
884
- | 'warning'
885
- | 'critical'
886
- | 'alert'
887
- | 'emergency' ,
888
- data : any
889
- ) : void {
890
- // Always log to stderr to avoid relying on MCP logging capability
891
- const message = `[ V1 ] [ $ { level} ] $ {
892
- typeof data === 'object' ? JSON . stringify ( data ) : String ( data )
893
- } `;
894
- console.error(message);
895
- }
879
+ // use shared safeLog via import (scope V1)
896
880
897
881
// Add retry logic with exponential backoff
898
882
async function withRetry < T > (
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import FirecrawlApp, {
15
15
16
16
// import express, { Request, Response } from 'express';
17
17
import dotenv from 'dotenv' ;
18
+ import { safeLog } from './utils/log.js' ;
18
19
19
20
dotenv . config ( ) ;
20
21
@@ -869,24 +870,7 @@ export function createV2Server() {
869
870
return new Promise ( ( resolve ) => setTimeout ( resolve , ms ) ) ;
870
871
}
871
872
872
- function safeLog (
873
- level :
874
- | 'error'
875
- | 'debug'
876
- | 'info'
877
- | 'notice'
878
- | 'warning'
879
- | 'critical'
880
- | 'alert'
881
- | 'emergency' ,
882
- data : any
883
- ) : void {
884
- // Always log to stderr to avoid relying on MCP logging capability
885
- const message = `[ V2 ] [ $ { level} ] $ {
886
- typeof data === 'object' ? JSON . stringify ( data ) : String ( data )
887
- } `;
888
- console.error(message);
889
- }
873
+ // use shared safeLog via import (scope V2 if desired)
890
874
891
875
// Add retry logic with exponential backoff
892
876
async function withRetry < T > (
Original file line number Diff line number Diff line change
1
+ export type LogLevel =
2
+ | 'error'
3
+ | 'debug'
4
+ | 'info'
5
+ | 'notice'
6
+ | 'warning'
7
+ | 'critical'
8
+ | 'alert'
9
+ | 'emergency' ;
10
+
11
+ export function safeLog ( level : LogLevel , data : any , scope ?: string ) : void {
12
+ try {
13
+ const prefix = scope ? `[${ scope } ]` : '' ;
14
+ const message = `${ prefix } [${ level } ] ${
15
+ typeof data === 'object' ? JSON . stringify ( data ) : String ( data )
16
+ } `;
17
+ if ( level === 'warning' ) {
18
+ console . warn ( message ) ;
19
+ } else if (
20
+ level === 'error' ||
21
+ level === 'critical' ||
22
+ level === 'alert' ||
23
+ level === 'emergency'
24
+ ) {
25
+ console . error ( message ) ;
26
+ } else {
27
+ console . log ( message ) ;
28
+ }
29
+ } catch ( _ ) {
30
+ // ignore logging failures
31
+ }
32
+ }
You can’t perform that action at this time.
0 commit comments