Skip to main content
Glama

connect_database

Connect to a specific MySQL database using the MCP server to enable SQL query execution and database management through Claude.

Instructions

Connect to a specific MySQL database

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
databaseYes

Implementation Reference

  • The connect_database tool handler, decorated with @mcp.tool() for registration. It retrieves the QueryExecutor from context and executes a USE query to switch to the specified database.
    @mcp.tool() def connect_database(database: str, ctx: Context) -> str: """Connect to a specific MySQL database""" try: executor = _get_executor(ctx) result = executor.execute_single_query(f"USE `{database}`") return json.dumps(result, indent=2) except (ConnectionError, QueryError) as e: return str(e)
  • Helper function used by connect_database to obtain the QueryExecutor instance from the MCP context.
    def _get_executor(ctx: Context) -> QueryExecutor: """Helper function to get QueryExecutor from context""" mysql_ctx = ctx.request_context.lifespan_context return QueryExecutor(mysql_ctx)

Other Tools

Related Tools

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/burakdirin/mysqldb-mcp-server'

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