create_database
Create a new vector database in Baidu Cloud to store and organize vector embeddings for AI applications.
Instructions
Create a database in the Mochow instance.
Args:
database_name (str): Name of the database.
Returns:
str: A message indicating the success of database creation.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database_name | Yes |
Implementation Reference
- src/mochow_mcp_server/server.py:487-500 (handler)MCP tool handler for 'create_database'. Registers the tool with FastMCP and implements the logic by delegating to MochowConnector.create_database.@mcp.tool() async def create_database(database_name: str, ctx: Context = None) -> str: """ Create a database in the Mochow instance. Args: database_name (str): Name of the database. Returns: str: A message indicating the success of database creation. """ connector = ctx.request_context.lifespan_context.connector await connector.create_database(database_name) return f"Created a database named '{database_name}'in Mochow instance:\n"
- Helper method in MochowConnector class that performs the actual database creation using the pymochow client, first checking if it already exists.async def create_database(self, db_name: str) -> bool: """ Create a new database. Args: db_name (str): Name of the database to create. Returns: bool: True if the database is created or already exists, False otherwise. """ try: # database already existed for db in self.client.list_databases(): if db.database_name == db_name: return True # create the new database self.client.create_database(db_name) self.database = self.client.database(db_name) return True except Exception as e: raise ValueError(f"Failed to create database: {str(e)}")
- src/mochow_mcp_server/server.py:487-487 (registration)FastMCP decorator that registers the create_database function as a tool.@mcp.tool()
- Function signature and docstring defining the input schema (database_name: str) and output (str message).async def create_database(database_name: str, ctx: Context = None) -> str: """ Create a database in the Mochow instance. Args: database_name (str): Name of the database. Returns: str: A message indicating the success of database creation. """