spec: usk/3.0 id: mgc_database_security version: 1.2.0 name: Database Credential Security (Zero‑Exposure Edition) description: Secure database credential management using MGC Blackbox. Supports MySQL, PostgreSQL, SQLite, MariaDB and other databases. Store credentials locally in encrypted form, retrieve at runtime without exposing to AI models. Requires MGC 1.4.7+. author: MirginCipher Team license: MIT tags: database, mysql, postgresql, sqlite, mariadb, security, credential-management, zero-exposure, mgc platform_compatibility: windows, macos, linux changelog: - version: 1.2.0 changes: - Requires MGC 1.4.7+ for mgc_run support - Use mgc_run instead of mgc_get action="run" - version: 1.1.0 changes: - Added complete example section with workflow templates - Added comprehensive troubleshooting section - Added FAQ section - Added anti‑patterns section with correct practices - Added when to use / when not to use sections - Added capability boundary explanation - Added advanced scenarios section - Added templates for SKILL.md and local scripts - version: 1.0.1 changes: - Updated to emphasize MCP tools over CLI - version: 1.0.0 changes: - Initial release with database zero-exposure pattern
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:
Prevents credential leakage in logs, prompts, and AI context
Automation tasks
CI/CD pipelines that connect to databases
Multi‑node collaboration
Use mgc_seal to encrypt the script with target node's public key
AI needs database access but must not see passwords
This skill is NOT needed in these scenarios:
Read‑only public data sources
Local development with no sensitive data
Demo environments with mock 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: - Host and port (non‑sensitive) - Database name (non‑sensitive) - Username (may be non‑sensitive) - But never the password
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:
- "my_mysql_prod"
- "my_postgres_dev"
- "my_mysql_reporting"
A:
1. Update credentials in the database
2. Call mgc_save with new credentials (same info_owner)
3. Local scripts automatically retrieve new credentials on next run
A:
1. Verify info_owner matches exactly (case‑sensitive)
2. Verify info_type matches
3. List all stored credentials: mgc_list
A: 1. Never include credentials in SKILL.md prompts 2. Never pass credentials as parameters to AI 3. Always use MGC to store credentials 4. Local scripts retrieve credentials directly from MGC 5. AI only receives non‑sensitive query results
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: - Never prints or logs credential values - Only logs non‑sensitive information (query, row count, etc.) - Uses secure logging practices
A:
1. Node A creates the database script
2. Use mgc_seal with Node B's public key
3. Node B decrypts and executes using mgc_run
A: 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:
1. Verify info_owner matches exactly (case‑sensitive)
2. Verify info_type matches
3. List all credentials: mgc_list
4. Re‑store credentials if needed
Symptoms: API returns wrong data or error
Solutions:
1. Check the info_type used when saving
2. Use the same info_type when retrieving
3. Common types: "config", "credential", "script"
Symptoms: Cannot connect to database
Solutions: 1. Verify credentials are correct in MGC 2. Check database server is running 3. Verify network connectivity to database host 4. Check port is correct (MySQL: 3306, PostgreSQL: 5432, SQL Server: 1433) 5. Verify firewall allows connection
Symptoms: Authentication fails when connecting
Solutions:
1. Verify username and password in MGC storage
2. Check if password was recently changed
3. Update credentials in MGC using mgc_save
4. Verify user has permission to access the database
Symptoms: Cannot connect to MGC service
Solutions:
1. Start MGC: mgc in terminal
2. Check service URL: http://127.0.0.1:57219
3. Verify token file exists: ~/.mgc/database/mgc_black_box/.mgc_token
4. Restart MGC if needed
Symptoms: Tool execution error
Solutions: 1. Verify MGC is running 2. Check service URL 3. Verify token file is readable 4. Check MCP tool parameters are correct
Symptoms: Cannot access MGC storage
Solutions:
1. Check file permissions on ~/.mgc/
2. Verify token file is readable
3. Run MGC with appropriate permissions
Endpoint: /api/mgc/sensitive/get Method: POST Headers: - X-MGC-Token: (string token read from token file) - Content-Type: application/json
Body fields: - info_type: "config" - info_owner: your chosen identifier
更多技能请访问小葱技能站7w4.net。
Response fields: - code: status code - data.content: JSON string containing stored credentials
Endpoint: /api/mgc/sensitive/save Method: POST Headers: same as above
Body fields: - info_type: "config" - info_owner: your identifier - content: JSON string of credentials
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 很有价值,但需要一定的技术基础才能很好地使用。