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
| Name | Required | Description | Default |
|---|---|---|---|
| database_name | Yes |
Implementation Reference
- src/mochow_mcp_server/server.py:503-517 (handler)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)}")