File tree Expand file tree Collapse file tree 3 files changed +16
-7
lines changed Expand file tree Collapse file tree 3 files changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -2,3 +2,12 @@ export enum ErrorCodes {
22    NotConnectedToMongoDB  =  1_000_000 , 
33    InvalidParams  =  1_000_001 , 
44} 
5+ 
6+ export  class  MongoDBError  extends  Error  { 
7+     constructor ( 
8+         public  code : ErrorCodes , 
9+         message : string 
10+     )  { 
11+         super ( message ) ; 
12+     } 
13+ } 
Original file line number Diff line number Diff line change 11import  {  z  }  from  "zod" ; 
2- import  {  CallToolResult ,   McpError  }  from  "@modelcontextprotocol/sdk/types.js" ; 
2+ import  {  CallToolResult  }  from  "@modelcontextprotocol/sdk/types.js" ; 
33import  {  NodeDriverServiceProvider  }  from  "@mongosh/service-provider-node-driver" ; 
44import  {  DbOperationType ,  MongoDBToolBase  }  from  "./mongodbTool.js" ; 
55import  {  ToolArgs  }  from  "../tool" ; 
6- import  {  ErrorCodes  }  from  "../../errors.js" ; 
6+ import  {  ErrorCodes ,   MongoDBError  }  from  "../../errors.js" ; 
77
88export  class  ConnectTool  extends  MongoDBToolBase  { 
99    protected  name  =  "connect" ; 
@@ -54,7 +54,7 @@ export class ConnectTool extends MongoDBToolBase {
5454                } ; 
5555            } 
5656        }  else  { 
57-             throw  new  McpError ( ErrorCodes . InvalidParams ,  "Invalid connection options" ) ; 
57+             throw  new  MongoDBError ( ErrorCodes . InvalidParams ,  "Invalid connection options" ) ; 
5858        } 
5959
6060        await  this . connect ( connectionString ) ; 
Original file line number Diff line number Diff line change @@ -2,8 +2,8 @@ import { z } from "zod";
22import  {  ToolBase  }  from  "../tool.js" ; 
33import  {  State  }  from  "../../state.js" ; 
44import  {  NodeDriverServiceProvider  }  from  "@mongosh/service-provider-node-driver" ; 
5- import  {  CallToolResult ,   McpError  }  from  "@modelcontextprotocol/sdk/types.js" ; 
6- import  {  ErrorCodes  }  from  "../../errors.js" ; 
5+ import  {  CallToolResult  }  from  "@modelcontextprotocol/sdk/types.js" ; 
6+ import  {  ErrorCodes ,   MongoDBError  }  from  "../../errors.js" ; 
77
88export  type  MongoDBToolState  =  {  serviceProvider ?: NodeDriverServiceProvider  } ; 
99
@@ -27,14 +27,14 @@ export abstract class MongoDBToolBase extends ToolBase {
2727    protected  ensureConnected ( ) : NodeDriverServiceProvider  { 
2828        const  provider  =  this . mongodbState . serviceProvider ; 
2929        if  ( ! provider )  { 
30-             throw  new  McpError ( ErrorCodes . NotConnectedToMongoDB ,  "Not connected to MongoDB" ) ; 
30+             throw  new  MongoDBError ( ErrorCodes . NotConnectedToMongoDB ,  "Not connected to MongoDB" ) ; 
3131        } 
3232
3333        return  provider ; 
3434    } 
3535
3636    protected  handleError ( error : unknown ) : CallToolResult  |  undefined  { 
37-         if  ( error  instanceof  McpError  &&  error . code  ===  ErrorCodes . NotConnectedToMongoDB )  { 
37+         if  ( error  instanceof  MongoDBError  &&  error . code  ===  ErrorCodes . NotConnectedToMongoDB )  { 
3838            return  { 
3939                content : [ 
4040                    { 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments