create_database
Create a new database in Baidu Vector Database MCP Server by specifying a unique database name, enabling organized storage and management of vector data for efficient search operations.
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
| Name | Required | Description | Default |
|---|---|---|---|
| database_name | Yes |
Input Schema (JSON Schema)
{
"properties": {
"database_name": {
"title": "Database Name",
"type": "string"
}
},
"required": [
"database_name"
],
"title": "create_databaseArguments",
"type": "object"
}
Implementation Reference
- src/mochow_mcp_server/server.py:487-500 (handler)The handler function for the 'create_database' MCP tool. It is registered via the @mcp.tool() decorator and implements the tool logic by delegating to the MochowConnector's create_database method.@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"
- Supporting method in MochowConnector class that performs the actual database creation logic: checks for existence, creates via client if needed, and updates the current database reference.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:473-473 (registration)Initialization of the FastMCP server instance named 'mcp' with lifespan manager, to which all tools including 'create_database' are registered via decorators.mcp = FastMCP("Mochow", lifespan=server_lifespan)