list_tables
Display all tables within a specified MariaDB database to enable exploration and interaction with its structure and content.
Instructions
특정 데이터베이스 내의 모든 테이블 목록을 보여줍니다.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| database | Yes | 데이터베이스의 이름입니다. |
Input Schema (JSON Schema)
{
"properties": {
"database": {
"description": "데이터베이스의 이름입니다.",
"type": "string"
}
},
"required": [
"database"
],
"type": "object"
}
Implementation Reference
- src/index.ts:137-144 (handler)Executes SHOW TABLES query on the specified database to list all tables and returns the result as JSON.case "list_tables": { const dbName = args.database as string; // 데이터베이스 이름 추출 if (!dbName) throw new McpError(ErrorCode.InvalidParams, "필수 파라미터 누락: database"); connection = await createDbConnection(dbName); // 지정된 DB로 연결 // 테이블 목록 조회 쿼리 (백틱 사용은 안전하지만 SHOW TABLES에서는 필수는 아님) const [rows] = await connection.query(`SHOW TABLES;`); return { content: [{ type: "text", text: JSON.stringify(rows, null, 2) }] }; }
- src/index.ts:80-90 (registration)Registers the list_tables tool, specifying its name, description, and required input schema (database name).{ name: "list_tables", description: "특정 데이터베이스 내의 모든 테이블 목록을 보여줍니다.", inputSchema: { type: "object", properties: { database: { type: "string", description: "데이터베이스의 이름입니다." } }, required: ["database"] } },
- src/index.ts:83-89 (schema)Defines the input schema for list_tables tool, requiring a 'database' string parameter.inputSchema: { type: "object", properties: { database: { type: "string", description: "데이터베이스의 이름입니다." } }, required: ["database"] }
- src/index.ts:37-49 (helper)Helper function to create a database connection, used by list_tables and other tools.async function createDbConnection(dbName?: string) { try { const connection = await mysql.createConnection({ ...dbConfig, database: dbName || dbConfig.database, // 특정 DB가 제공되면 사용, 아니면 기본값 사용 }); return connection; } catch (error: any) { console.error("데이터베이스 연결 오류:", error.message); // MCP 클라이언트에게 더 구체적인 오류 제공 throw new McpError(ErrorCode.InternalError, `데이터베이스 연결 실패: ${error.message}`); } }