use_database
Switch to a specified database within Baidu Vector Database MCP Server by providing the database name, enabling efficient management and access to vector data for LLM applications.
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:502-516 (handler)The main MCP tool handler for 'use_database'. It retrieves the connector from context, calls the connector's use_database method, and returns a success message. The @mcp.tool() decorator registers it as an MCP tool.@mcp.tool() 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"
- Supporting helper method in the MochowConnector class that switches the current database by setting self.database.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)}")