@@ -703,7 +703,9 @@ const runner = new StreamableHttpRunner({
703703});
704704
705705await runner .start ();
706- console .log (" MongoDB MCP Server running with minimal toolset" );
706+ console .log (
707+ ` MongoDB MCP Server running with minimal toolset at ${runner .serverAddress } `
708+ );
707709```
708710
709711In this configuration:
@@ -910,14 +912,16 @@ The default connection manager factory (`createMCPConnectionManager`) is also ex
910912
911913``` typescript
912914import {
915+ ConnectionManager ,
913916 StreamableHttpRunner ,
917+ UserConfigSchema ,
914918 createMCPConnectionManager ,
915919} from " mongodb-mcp-server" ;
916920import type { ConnectionManagerFactoryFn } from " mongodb-mcp-server" ;
917921
918922// Using the default connection manager (this is the default behavior)
919923const runner1 = new StreamableHttpRunner ({
920- userConfig: config ,
924+ userConfig: UserConfigSchema . parse ({}) ,
921925 createConnectionManager: createMCPConnectionManager ,
922926});
923927
@@ -926,13 +930,15 @@ const customConnectionManager: ConnectionManagerFactoryFn = async ({
926930 logger ,
927931 userConfig ,
928932 deviceId ,
929- }) => {
930- // Return a custom ConnectionManager implementation
931- // that could delegate to your application's existing connection logic
933+ }): Promise <ConnectionManager > => {
934+ // Just for types we're using the internal mcp connection manager factory but
935+ // its an example. You can return a custom ConnectionManager implementation
936+ // that could delegate to your application's existing connection logic.
937+ return createMCPConnectionManager ({ logger , userConfig , deviceId });
932938};
933939
934940const runner2 = new StreamableHttpRunner ({
935- userConfig: config ,
941+ userConfig: UserConfigSchema . parse ({}) ,
936942 createConnectionManager: customConnectionManager ,
937943});
938944```
@@ -984,9 +990,10 @@ const customErrorHandler: ConnectionErrorHandler = (error, context) => {
984990 console .error (" Connection error:" , error .code , error .message );
985991
986992 // Access available tools and connection state
987- const connectTools = context .availableTools .filter (
988- (t ) => t .operationType === " connect"
989- );
993+ const connectTools = context .availableTools
994+ .filter ((t ) => t .operationType === " connect" )
995+ .map ((tool ) => tool .name )
996+ .join (" , " );
990997
991998 if (error .code === ErrorCodes .NotConnectedToMongoDB ) {
992999 // Provide custom error message
@@ -996,7 +1003,7 @@ const customErrorHandler: ConnectionErrorHandler = (error, context) => {
9961003 content: [
9971004 {
9981005 type: " text" ,
999- text: " Please connect to MongoDB first using one of the available connect tools. " ,
1006+ text: ` Please connect to MongoDB first using one of the available connect tools - (${ connectTools }) ` ,
10001007 },
10011008 ],
10021009 isError: true ,
@@ -1009,7 +1016,7 @@ const customErrorHandler: ConnectionErrorHandler = (error, context) => {
10091016};
10101017
10111018const runner2 = new StreamableHttpRunner ({
1012- userConfig: config ,
1019+ userConfig: UserConfigSchema . parse ({}) ,
10131020 connectionErrorHandler: customErrorHandler ,
10141021});
10151022```
@@ -1023,16 +1030,36 @@ import {
10231030 StreamableHttpRunner ,
10241031 LoggerBase ,
10251032 UserConfigSchema ,
1033+ Keychain ,
10261034 type LogPayload ,
1035+ type LogLevel ,
1036+ type LoggerType ,
10271037} from " mongodb-mcp-server" ;
10281038
10291039class CustomLogger extends LoggerBase {
1030- log(payload : LogPayload ): void {
1031- // Send to your logging service
1032- console .log (` [${payload .id }] ${payload .message } ` );
1040+ // Optional: specify the logger type for redaction control
1041+ protected readonly type: LoggerType = " console" ;
1042+
1043+ constructor () {
1044+ // Pass keychain for automatic secret redaction
1045+ // Use Keychain.root for the global keychain or create your own
1046+ super (Keychain .root );
10331047 }
10341048
1035- // Implement other log level methods...
1049+ // Required: implement the core logging method
1050+ protected logCore(level : LogLevel , payload : LogPayload ): void {
1051+ // Send to your logging service
1052+ const timestamp = new Date ().toISOString ();
1053+ const logMessage = ` [${timestamp }] [${level .toUpperCase ()}] [${payload .id }] ${payload .context }: ${payload .message } ` ;
1054+
1055+ // Example: Send to external logging service
1056+ console .log (logMessage );
1057+
1058+ // You can also access payload.attributes for additional context
1059+ if (payload .attributes ) {
1060+ console .log (" Attributes:" , JSON .stringify (payload .attributes ));
1061+ }
1062+ }
10361063}
10371064
10381065const runner = new StreamableHttpRunner ({
0 commit comments