Skip to main content
Glama
baidu

Baidu Vector Database MCP Server

Official
by baidu

use_database

Switch between databases in Baidu Cloud Vector Database to manage different datasets for vector search operations.

Instructions

Switch to a different database.

Args:
    database_name (str): Name of the database to use.

Returns:
    str: A message indicating the success of the database switch.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
database_nameYes

Implementation Reference

  • MCP tool handler function for 'use_database'. It retrieves the connector from context, calls the connector's use_database method, and returns a success message. This is also the registration point via @mcp.tool() decorator.
    async def use_database(database_name: str, ctx: Context = None) -> str:
        """
        Switch to a different database.
    
        Args:
            database_name (str): Name of the database to use.
    
        Returns:
            str: A message indicating the success of the database switch.
        """
        connector = ctx.request_context.lifespan_context.connector
        await connector.use_database(database_name)
        
        return f"Switched to database '{database_name}' successfully"
  • Helper method in MochowConnector class that switches the current database by setting self.database to the client for the specified db_name.
    async def use_database(self, db_name: str) -> bool:
        """
        Switch to a different database.
    
        Args:
            db_name (str): Name of the database to use.
    
        Returns:
            bool: True if the database switch is successful, False otherwise.
        """
        try:
            self.database = self.client.database(db_name)
            return True
        except Exception as e:
            raise ValueError(f"Failed to switch database: {str(e)}")

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/baidu/mochow-mcp-server-python'

If you have feedback or need assistance with the MCP directory API, please join our Discord server