Database Credential Security is a documentation skill that teaches how to manage database credentials securely using MGC Blackbox. Supports MySQL, PostgreSQL, SQLite, MariaDB and other databases. It enables AI agents to execute database operations without ever exposing database passwords or connection strings to the AI model.
This skill contains no executable code and is safe for automatic approval.
After reading this documentation, an AI agent will understand how to:
Production environments
Automation tasks
Multi‑node collaboration
mgc_seal to encrypt the script with target node's public keyAI needs database access but must not see passwords
This skill is NOT needed in these scenarios:
Public databases
Local development with no sensitive data
Interactive manual access
This skill has specific boundaries that users must understand:
The skill provides credential management only. All sensitive database operations (connect, query, migrate, backup) must be performed by local scripts.
pip install mgc-blackboxmgc (runs at http://127.0.0.1:57219)~/.mgc/database/mgc_black_box/.mgc_tokenThis section demonstrates a complete flow from credential storage to secure database operation.
Tool: mgc_save
Parameters:
info_type: "config"
info_owner: "my_mysql_prod"
content: "{
\"host\": \"db.example.com\",
\"port\": 3306,
\"database\": \"production_db\",
\"user\": \"app_user\",
\"password\": \"your_secure_password\"
}"
Tool: mgc_save
Parameters:
info_type: "config"
info_owner: "my_postgres_prod"
content: "{
\"host\": \"db.example.com\",
\"port\": 5432,
\"database\": \"production_db\",
\"user\": \"app_user\",
\"password\": \"your_secure_password\",
\"sslmode\": \"require\"
}"
Tool: mgc_save
Parameters:
info_type: "config"
info_owner: "my_sqlserver_prod"
content: "{
\"host\": \"db.example.com\",
\"port\": 1433,
\"database\": \"production_db\",
\"user\": \"app_user\",
\"password\": \"your_secure_password\"
}"
Note: Replace placeholder values with actual database credentials. The
info_ownervalue is your reference identifier—you'll use this same value when retrieving credentials.
# In your SKILL.md:
database_reference:
info_type: "config"
info_owner: "my_mysql_prod"
# The AI never sees actual credentials, only the reference
Tool: mgc_get
Parameters:
info_type: "config"
info_owner: "my_mysql_prod"
The MCP tool returns the stored JSON content. The AI receives:
A local script performs the actual database operation:
# Conceptual script flow (NOT executable):
1. Call mgc_get with info_owner="my_mysql_prod"
2. Parse returned JSON for connection parameters
3. Use database driver to connect
4. Execute SQL query
5. Return only query results (no credentials)
6. NEVER log or expose the password
When Node A needs Node B to execute a database script:
Tool: mgc_seal
Parameters:
info_type: "script"
info_owner: "mysql_backup_script"
ext01: "python"
ext04: "-----BEGIN PUBLIC KEY-----\n...Node B's public key...\n-----END PUBLIC KEY-----"
Returns: Encrypted capsule containing the database script
Tool: mgc_get
Parameters:
info_type: "script"
info_owner: "mysql_backup_script"
action: "run"
Node B uses its private key to decrypt and execute. Node A's database script is never exposed to Node B.
A: Install MGC Blackbox: pip install mgc-blackbox
A: Start MGC: mgc in a terminal. Service runs at http://127.0.0.1:57219
A: Open http://127.0.0.1:57219 in a browser. If you see a response, MGC is running.
A: Stop other applications using that port, or configure MGC to use a different port.
A: Call mgc_save again with the same info_type and info_owner. The old credentials will be replaced.
A: Use different info_owner values for each database:
A:
mgc_save with new credentials (same info_owner)A:
info_owner matches exactly (case‑sensitive)info_type matchesmgc_listA:
A: Yes, if AI calls mgc_get. Never call mgc_get unless you want AI to process the result. For zero‑exposure, use local scripts that call MGC, not AI directly.
A: Ensure your local script:
A:
mgc_seal with Node B's public keymgc_runA: Currently, mgc_seal targets one node at a time. For multiple nodes, seal separately with each node's public key.
# WRONG - Never do this
def connect_to_db():
connection = pymysql.connect(
host="db.example.com",
password="secret_password" # Exposed!
)
Correct Practice:
# RIGHT - Retrieve from MGC
def connect_to_db():
credentials = get_credentials_from_mgc("my_mysql_prod")
connection = pymysql.connect(
host=credentials["host"],
password=credentials["password"]
)
# WRONG - In SKILL.md
Use the following database credentials:
- Host: db.example.com
- Password: my_secret_password
Correct Practice:
# RIGHT - In SKILL.md
Database credentials are stored securely in MGC.
Reference: info_owner="my_mysql_prod"
AI should NOT handle credentials directly.
// WRONG
{
"info_owner": "my_database",
"ext04": "password=secret123" // This is NOT for passwords!
}
Correct Practice:
// RIGHT
{
"info_owner": "my_database",
"info_type": "config",
"ext04": "-----BEGIN PUBLIC KEY-----\nNodeB_Public_Key...\n-----END PUBLIC KEY-----"
}
// ext04 is ONLY for public keys when sealing
# WRONG
echo "password=secret" > db_credentials.txt
Correct Practice:
# RIGHT
# Store in MGC using mgc_save
# Never write credentials to disk files
# WRONG
Execute SQL: SELECT * FROM users WHERE password='{user_password}'
Correct Practice:
# RIGHT
Execute SQL using credentials stored in MGC.
Reference: info_owner="my_mysql_prod"
The local script handles credential retrieval.
# WRONG
def execute_query(sql):
creds = get_credentials_from_mgc("my_database")
print(f"Connecting with password: {creds['password']}") # Exposed!
# ... execute query
Correct Practice:
# RIGHT
def execute_query(sql):
creds = get_credentials_from_mgc("my_database")
logger.info(f"Connecting to {creds['host']}") # No password logged
# ... execute query
Symptoms: mgc_get returns empty or error
Solutions:
info_owner matches exactly (case‑sensitive)info_type matchesmgc_listSymptoms: API returns wrong data or error
Solutions:
info_type used when savinginfo_type when retrievingSymptoms: Cannot connect to database
Solutions:
訪問小蔥技能站7w4.net,解鎖更多實用的AI技能外掛。
Symptoms: Authentication fails when connecting
Solutions:
mgc_saveSymptoms: Cannot connect to MGC service
Solutions:
mgc in terminal~/.mgc/database/mgc_black_box/.mgc_tokenSymptoms: Tool execution error
Solutions:
Symptoms: Cannot access MGC storage
Solutions:
~/.mgc/Endpoint: /api/mgc/sensitive/get Method: POST Headers:
Body fields:
Response fields:
Endpoint: /api/mgc/sensitive/save Method: POST Headers: same as above
Body fields:
Manage credentials for multiple databases:
# Storage identifiers:
info_owner: "my_mysql_prod" # MySQL production
info_owner: "my_postgres_prod" # PostgreSQL production
info_owner: "my_mysql_dev" # MySQL development
info_owner: "my_mysql_test" # MySQL testing
Tool: mgc_seal
Parameters:
info_type: "script"
info_owner: "mysql_migration_script"
ext01: "python"
ext04: "-----BEGIN PUBLIC KEY-----\nNodeB_Public_Key...\n-----END PUBLIC KEY-----"
Tool: mgc_get
Parameters:
info_type: "script"
info_owner: "mysql_migration_script"
action: "run"
Regularly rotate database credentials:
Tool: mgc_save
Parameters:
info_type: "config"
info_owner: "my_mysql_prod"
content: "{new_credentials}"Track credential versions using info_owner suffixes:
info_owner: "my_mysql_prod_v1" # Version 1
info_owner: "my_mysql_prod_v2" # Version 2 (after rotation)
When creating a database skill:
database_skill/
SKILL.md # Skill definition
README.md # User documentation
scripts/ # Local scripts (conceptual)
execute_query.py
backup.py
migrate.py
import mysql.connector
def get_connection(credentials):
return mysql.connector.connect(
host=credentials["host"],
port=credentials["port"],
database=credentials["database"],
user=credentials["user"],
password=credentials["password"]
)
def execute_query(sql):
creds = retrieve_from_mgc("my_mysql_prod")
conn = get_connection(creds)
cursor = conn.cursor()
cursor.execute(sql)
result = cursor.fetchall()
cursor.close()
conn.close()
return result
When creating a new database skill:
---
spec: usk/3.0
id: your_skill_id
version: 1.0.0
name: Your Database Skill
description: Brief description
author: Your Name
license: MIT
tags: database, mgc, zero-exposure
platform_compatibility: windows, macos, linux
---
# Overview
What this skill does.
# Prerequisites
- Install MGC Blackbox
- Store database credentials in MGC (info_owner: "your_reference")
- Install required database driver
# Usage
How to use this skill.
# Database Credentials
- info_type: "config"
- info_owner: "your_reference"
- Required fields: host, port, database, user, password
# Security
This skill uses Zero‑Exposure design.
Credentials are stored in MGC, never exposed to AI.
---
# Entrypoint
Describe how to use this skill.
# Template structure (documentation only)
import json
import pymysql # or psycopg2, pymssql, etc.
# MGC Configuration
MGC_BASE_URL = "http://127.0.0.1:57219"
TOKEN_FILE = "~/.mgc/database/mgc_black_box/.mgc_token"
def get_mgc_token():
# Read token from file
pass
def get_credentials(info_owner, info_type="config"):
# Call MGC API to retrieve credentials
# Return: dict of credential data
pass
def execute_query(credentials, sql):
# Use credentials to connect and execute
# NEVER log credential values
# Return: query results only
pass
def main():
# 1. Get credentials from MGC
creds = get_credentials(info_owner="your_database_reference")
# 2. Execute query
result = execute_query(creds, "SELECT * FROM users")
# 3. Return result (not credentials!)
print(result)
if __name__ == "__main__":
main()
MIT
這是一份質量較高的資料庫安全憑證管理文件包,結構清晰、內容全面,特別適合需要安全訪問資料庫的開發者。優點是提供了多種資料庫的完整示例,FAQ 和故障排除指南非常實用,反模式部分能有效防止常見錯誤。不足之處在於文件中部分工具的使用說明不夠詳細,部分內容比較概念化,缺少可直接使用的指令碼模板。對於需要安全管理資料庫憑證的使用者來說,這個 Skill 很有價值,但需要一定的技術基礎才能很好地使用。