MCP Database Server

repository·main·Indexed 18 days ago

https://github.com/executeautomation/mcp-database-server

An MCP (Model Context Protocol) server by ExecuteAutomation that enables Claude to interact with SQLite, SQL Server, PostgreSQL, and MySQL (including AWS RDS via IAM). It provides tools for reading and writing data, managing database schemas, exporting query results as CSV or JSON, and tracking business insights through natural language requests.

Tokens
20.8K
Snippets
64
Records
94
Agent score
62%

What's inside mcp-database-server

  1. Understand connection pooling and security

    main

    Connection Pooling

    All database connections use connection pooling to optimize performance:

    • SQLite: Uses a single persistent connection.
    • SQL Server: Default pool of 5 connections.
    • PostgreSQL: Default pool of 10 connections.

    Connection Security Best Practices

    1. SQL Server: In production, use --trustServerCertificate false and ensure proper SSL certificates are installed on the server.
    2. PostgreSQL: Use --ssl true and ensure the server is configured for SSL connections.
    3. Credentials: Use environment variables instead of command-line arguments to prevent credential leakage in process lists.
    4. Permissions: Store your Claude Desktop configuration file with appropriate file system permissions.
  2. Supported features and limitations of the PostgreSQL adapter

    main

    Supported Features

    • Full SQL query support for SELECT, INSERT, UPDATE, and DELETE operations.
    • Table management (CREATE TABLE, ALTER TABLE, DROP TABLE).
    • Schema introspection.
    • Connection pooling.
    • SSL support for secure connections.

    Limitations

    • ID Retrieval: For the run method with INSERT statements, the adapter attempts to retrieve the last inserted ID by adding a RETURNING clause. This requires your tables to have an id column.
    • Complex Logic: Complex stored procedures or PostgreSQL-specific features may require custom implementation.
  3. Authenticate with SQL Server

    main

    The SQL Server adapter supports three primary authentication methods:

    SQL Server Authentication

    Use the --user and --password flags to provide explicit credentials.

    Windows Authentication

    Omit the --user and --password flags to use a trusted connection (Windows Authentication).

    Azure Active Directory

    For Azure SQL Database, provide the Azure AD user identity via the --user flag and configure the server address accordingly.

    # SQL Server Authentication
    node dist/src/index.js --sqlserver --server myserver --database mydatabase --user myuser --password mypassword
    
    # Windows Authentication
    node dist/src/index.js --sqlserver --server myserver --database mydatabase
  4. SQL Server vs SQLite syntax differences

    main

    When crafting SQL queries via Claude, be aware of these syntax differences between SQL Server and SQLite:

    FeatureSQLiteSQL Server
    String concatenation||+
    Limit/OffsetLIMIT x OFFSET yOFFSET y ROWS FETCH NEXT x ROWS ONLY
    Date formattingstrftime()FORMAT() or CONVERT()
    Auto-incrementINTEGER PRIMARY KEY AUTOINCREMENTINT IDENTITY(1,1)
  5. Supported PostgreSQL Features and Limitations

    main

    Supported Features

    • Full SQL query support for SELECT, INSERT, UPDATE, and DELETE operations.
    • Table management (CREATE TABLE, ALTER TABLE, DROP TABLE).
    • Schema introspection.
    • Connection pooling.
    • SSL support for secure connections.

    Limitations

    • Last Inserted ID: For the run method with INSERT statements, the adapter attempts to retrieve the last inserted ID by adding a RETURNING clause. This requires your tables to have an id column.
    • Advanced Features: Complex stored procedures or highly specific PostgreSQL features may require custom implementation.
  6. Configure Claude Desktop for SQLite

    main

    To use the SQLite adapter within Claude Desktop, add a configuration entry to your mcpServers object. You can use npx to run the package directly or point to a local installation.

    Using npx (Recommended for production/general use):

    {
      "mcpServers": {
        "sqlite": {
          "command": "npx",
          "args": [
            "-y",
            "@executeautomation/database-server",
            "/path/to/your/database.db"
          ]
        }
      }
    }

    Using local installation (For development):

    {
      "mcpServers": {
        "sqlite": {
          "command": "node",
          "args": [
            "/absolute/path/to/mcp-database-server/dist/src/index.js", 
            "/path/to/your/database.db"
          ]
        }
      }
    }
  7. Best Practices for Using MCP Database Server with Claude

    main

    To ensure successful interactions with the database tools, follow these guidelines:

    1. Be specific about database type: If you have multiple database configurations, tell Claude which one you want to use.
    2. Security awareness: Avoid exposing sensitive database credentials in your conversations.
    3. SQL syntax differences: Remember that SQL syntax might differ between database types (e.g., SQLite vs. SQL Server).
    4. Error handling: If Claude encounters an error, it will report the error message; use this information to correct your query or instructions.
    5. Complex operations: For complex operations, consider breaking them down into smaller, incremental steps.
  8. Connect to AWS RDS MySQL via IAM Authentication

    main

    For Amazon RDS MySQL instances using IAM database authentication, use the --aws-iam-auth flag. SSL is automatically enabled.

    Prerequisites: AWS credentials must be configured via aws configure, AWS_PROFILE environment variable, or standard AWS environment variables (AWS_ACCESS_KEY_ID, etc.).

    Required parameters:

    • --host: RDS endpoint hostname
    • --database: Name of the database
    • --aws-iam-auth: Enable AWS IAM authentication
    • --user: AWS IAM username (also the database user)
    • --aws-region: AWS region where RDS instance is located

    CLI Command:

    node dist/src/index.js --mysql --aws-iam-auth --host <rds-endpoint> --database <database-name> --user <aws-username> --aws-region <region>
    node dist/src/index.js --mysql --aws-iam-auth --host <rds-endpoint> --database <database-name> --user <aws-username> --aws-region <region>