用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/diegosouzapw/awesome-omni-skill --skill database-connect命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
Token-efficient tracking for AI orchestration. CLI-first for status updates (~50 tokens), agent fallback for complex ops (~1KB). Use when: updating task status, querying blockers, creating progress files, validating phases.
AshAi extension guidelines for integrating AI capabilities with Ash Framework. Use when implementing vectorization/embeddings, exposing Ash actions as LLM tools, creating prompt-backed actions, or setting up MCP servers. Covers semantic search, LangChain integration, and structured outputs.
This skill should be used when solving hard questions, complex architectural problems, or debugging issues that benefit from GPT-5 Pro or GPT-5.1 thinking models with large file context. Use when standard Claude analysis needs deeper reasoning or extended context windows.
基于 SOC 职业分类
正在显示 SKILL.md
| name | database-connect |
| description | Database MCP server integration for PostgreSQL, MySQL, MongoDB |
| disable-model-invocation | true |
I'll help you connect to and manage databases through MCP servers for data exploration, schema inspection, and queries.
Arguments: $ARGUMENTS - database type (postgres, mysql, mongodb), connection details, or query
Supported Databases:
Operations:
This skill uses database-specific patterns to minimize token usage:
Pattern: Cache database connection details and configuration
.database-connection-cache (1 hour TTL)Pattern: Use MCP server for database interactions
Pattern: Use database CLI tools for schema inspection
psql -c "\\dt" (200 tokens)mysql -e "SHOW TABLES" (200 tokens)prisma db pull (200 tokens)Pattern: Store recent schema inspection results
.claude/database/schema-cache.json (15 min TTL)Pattern: Inspect first 20 tables in detail
--full flagPattern: Use SQL templates for common operations
Pattern: Reuse MCP server connections
Pattern: Detect if MCP database server already configured
Typical operation patterns:
Expected per-operation: 1,500-2,500 tokens (60% reduction from 3,500-5,500 baseline) Real-world average: 700 tokens (due to MCP integration, cached schema, early exit)
#!/bin/bash
# Detect database configuration in project
detect_databases() {
echo "=== Database Detection ==="
echo ""
# Check for environment variables
if [ -f ".env" ]; then
echo "✓ .env file found"
if grep -q "DATABASE_URL\|POSTGRES\|MYSQL" .env; then
echo " Contains database configuration"
fi
fi
# Check for database config files
if [ -f "knexfile.js" ] || [ -f "knexfile.ts" ]; then
echo "✓ Knex configuration detected"
DB_TOOL="knex"
fi
if [ -f "prisma/schema.prisma" ]; then
echo "✓ Prisma schema detected"
DB_TOOL="prisma"
DB_TYPE=$(grep "provider" prisma/schema.prisma | head -1 | awk '{print $3}' | tr -d '"')
echo " Provider: $DB_TYPE"
fi
if [ -f "ormconfig.json" ] || [ -f "ormconfig.js" ];
DB_TOOL=
[ -f ];
DB_TOOL=
[ -f ];
grep -q package.json;
DB_TYPE=
[ -f ];
DB_TOOL=
[ -f ];
DB_TOOL=
}
detect_databases
#!/bin/bash
# Check for MCP database server configuration
check_mcp_setup() {
echo "=== MCP Database Server Check ==="
echo ""
if [ ! -f "$HOME/.claude/config.json" ]; then
echo "⚠️ No MCP configuration found"
echo "Run: /mcp-setup postgres|mysql|mongodb"
return 1
fi
# Check for database MCP servers
if grep -q "postgres" "$HOME/.claude/config.json"; then
echo "✓ PostgreSQL MCP server configured"
POSTGRES_MCP=true
fi
if grep -q "mysql" "$HOME/.claude/config.json"; then
echo "✓ MySQL MCP server configured"
MYSQL_MCP=true
fi
if grep -q "mongodb" "$HOME/.claude/config.json"; then
echo "✓ MongoDB MCP server configured"
MONGODB_MCP=true
fi
if [ -z "$POSTGRES_MCP" ] && [ -z "" ] && [ -z ];
1
}
check_mcp_setup
#!/bin/bash
# PostgreSQL connection and inspection
connect_postgres() {
local db_url="$1"
echo "=== PostgreSQL Connection ==="
echo ""
# Test connection
if psql "$db_url" -c "SELECT version();" &> /dev/null; then
echo "✓ Connection successful"
else
echo "❌ Connection failed"
echo "Check your connection string and credentials"
exit 1
fi
echo ""
}
inspect_postgres_schema() {
local db_url="$1"
echo "=== PostgreSQL Schema Inspection ==="
echo ""
# List all tables
echo "Tables:"
psql "$db_url" -c "SELECT schemaname, tablename FROM pg_tables WHERE schemaname NOT IN ('pg_catalog', 'information_schema') ORDER BY tablename;"
echo ""
echo "Views:"
psql "$db_url" -c "SELECT schemaname, viewname FROM pg_views WHERE schemaname NOT IN ('pg_catalog', 'information_schema') ORDER BY viewname;"
}
() {
db_url=
table=
psql -c
psql -c
psql -c
psql -c
}
connect)
connect_postgres
;;
schema)
inspect_postgres_schema
;;
describe)
describe_postgres_table
;;
*)
;;
// scripts/db-query-postgres.ts
import { Client } from 'pg';
interface QueryConfig {
connectionString: string;
query: string;
params?: any[];
timeout?: number;
readOnly?: boolean;
}
async function executeQuery(config: QueryConfig) {
const client = new Client({
connectionString: config.connectionString,
statement_timeout: config.timeout || 30000, // 30s default
});
try {
await client.connect();
console.log('✓ Connected to PostgreSQL');
// Enable read-only mode if requested
if (config.readOnly) {
await client.query('SET default_transaction_read_only = on;');
console.log('✓ Read-only mode enabled');
}
console.log('');
.();
.();
startTime = .();
result = client.(config., config.);
duration = .() - startTime;
.();
.();
.();
(result.. > ) {
.(result..(, ));
(result.. > ) {
.();
}
}
result.;
} (: ) {
.(, error.);
(error.) {
.(, error.);
}
error;
} {
client.();
}
}
query = process.[];
connectionString = process.. || process.[];
(!query || !connectionString) {
.();
.();
process.();
}
dangerousKeywords = [, , , ];
isDangerous = dangerousKeywords.(
query.().(keyword)
);
(isDangerous && !process..()) {
.();
.();
process.();
}
({
connectionString,
query,
: !process..(),
}).( process.());
#!/bin/bash
# MySQL connection and operations
connect_mysql() {
local host="${1:-localhost}"
local user="${2:-root}"
local database="${3}"
echo "=== MySQL Connection ==="
echo ""
# Test connection
if mysql -h "$host" -u "$user" -p -e "SHOW DATABASES;" &> /dev/null; then
echo "✓ Connection successful"
else
echo "❌ Connection failed"
exit 1
fi
if [ -n "$database" ]; then
echo "Database: $database"
fi
echo ""
}
inspect_mysql_schema() {
local host="$1"
local user="$2"
local database="$3"
echo
mysql -h -u -p -e
mysql -h -u -p -e
}
() {
host=
user=
database=
table=
mysql -h -u -p -e
mysql -h -u -p -e
mysql -h -u -p -e
}
connect)
connect_mysql
;;
schema)
inspect_mysql_schema
;;
describe)
describe_mysql_table
;;
*)
;;
// scripts/db-query-mongodb.ts
import { MongoClient } from 'mongodb';
interface MongoConfig {
uri: string;
database: string;
collection?: string;
operation: 'find' | 'aggregate' | 'count' | 'distinct';
query?: any;
projection?: any;
sort?: any;
limit?: number;
}
async function executeMongoOperation(config: MongoConfig) {
const client = new MongoClient(config.uri);
try {
await client.connect();
console.log('✓ Connected to MongoDB');
const db = client.db(config.database);
console.log(`✓ Using database: ${config.database}`);
if (config.collection) {
const collection = db.(config.);
.();
.();
(config.) {
:
docs = collection
.(config. || {})
.(config. || {})
.(config. || {})
.(config. || )
.();
.();
.();
.(.(docs, , ));
;
:
count = collection.(config. || {});
.();
;
:
field = .(config. || {})[];
values = collection.(field);
.();
.(values);
;
:
pipeline = config. [];
results = collection.(pipeline).();
.();
.();
.(.(results, , ));
;
}
} {
collections = db.().();
.();
collections.( {
.();
});
}
} (: ) {
.(, error.);
error;
} {
client.();
}
}
uri = process.. || process.[];
database = process.[];
collection = process.[];
(!uri || !database) {
.();
.();
process.();
}
({
uri,
database,
collection,
: ,
: ,
}).( process.());
#!/bin/bash
# MongoDB shell wrapper
inspect_mongodb() {
local uri="$1"
local database="$2"
echo "=== MongoDB Inspection ==="
echo ""
# List databases
echo "Databases:"
mongosh "$uri" --quiet --eval "db.adminCommand('listDatabases').databases.forEach(d => print(d.name))"
if [ -n "$database" ]; then
echo ""
echo "Collections in $database:"
mongosh "$uri/$database" --quiet --eval "db.getCollectionNames().forEach(c => print(c))"
echo ""
echo "Database stats:"
mongosh "$uri/$database" --quiet --eval "printjson(db.stats())"
fi
echo ""
}
inspect_mongodb "$1" "$2"
// scripts/db-query-builder.ts
interface QueryBuilder {
select(columns: string[]): this;
from(table: string): this;
where(condition: string, params?: any[]): this;
orderBy(column: string, direction: 'ASC' | 'DESC'): this;
limit(count: number): this;
toSQL(): { query: string; params: any[] };
}
class PostgreSQLQueryBuilder implements QueryBuilder {
private columns: string[] = ['*'];
private table: string = '';
private conditions: string[] = [];
private params: any[] = [];
private orderColumn?: ;
: | = ;
?: ;
(: []): {
. = columns;
;
}
(: ): {
. = table;
;
}
(: , ?: []): {
..(condition);
(params) {
..(...params);
}
;
}
(: , : | = ): {
. = column;
. = direction;
;
}
(: ): {
. = count;
;
}
(): { : ; : [] } {
query = ;
(.. > ) {
query += ;
}
(.) {
query += ;
}
(.) {
query += ;
}
{ query, : . };
}
}
builder = ();
{ query, params } = builder
.([, , ])
.()
.(, [])
.(, [ ()])
.(, )
.()
.();
.(, query);
.(, params);
#!/bin/bash
# Database migration helpers
run_migration() {
local db_tool="$1"
local direction="${2:-up}"
echo "=== Running Database Migration ==="
echo "Tool: $db_tool"
echo "Direction: $direction"
echo ""
case "$db_tool" in
prisma)
if [ "$direction" = "up" ]; then
npx prisma migrate deploy
else
echo "Prisma doesn't support down migrations"
echo "Use 'prisma migrate diff' to create a new migration"
fi
;;
knex)
npx knex migrate:$direction
;;
typeorm)
npx typeorm migration:run
;;
alembic)
if [ "$direction" = "up" ]; then
alembic upgrade head
else
alembic downgrade -1
fi
;;
django)
python manage.py migrate
;;
*)
echo "Unsupported migration tool: "
1
;;
[ $? -eq 0 ];
1
}
run_migration
PostgreSQL:
/database-connect postgres --schema
/database-connect postgres --table users
/database-connect postgres --query "SELECT * FROM users LIMIT 10"
MySQL:
/database-connect mysql --schema mydb
/database-connect mysql --describe products
MongoDB:
/database-connect mongodb --list-collections
/database-connect mongodb --query users '{"active": true}'
Query Safety:
Best Practices:
/schema-validate - Validate database schema against ORM/query-optimize - Analyze and optimize queries/migration-generate - Generate database migrations/mcp-setup - Configure database MCP serversImportant: I will NEVER:
All database operations will be safe, validated, and well-documented.
Credits: Based on MCP database server integrations and standard database CLI tools.