Skip to main content
Glama
moosin76

MariaDB Reader MCP Server

by moosin76

query_table

Retrieve data from a specified table in a MariaDB database with a customizable row limit, enabling efficient data exploration and analysis for AI assistants.

Instructions

특정 테이블에서 데이터를 조회합니다 (제한된 행 반환).

Input Schema

NameRequiredDescriptionDefault
databaseYes데이터베이스의 이름입니다.
limitNo반환할 최대 행 수 (기본값 100).
tableYes테이블의 이름입니다.

Input Schema (JSON Schema)

{ "properties": { "database": { "description": "데이터베이스의 이름입니다.", "type": "string" }, "limit": { "default": 100, "description": "반환할 최대 행 수 (기본값 100).", "type": "number" }, "table": { "description": "테이블의 이름입니다.", "type": "string" } }, "required": [ "database", "table" ], "type": "object" }

Implementation Reference

  • The execution handler for the 'query_table' tool. It validates inputs, connects to the specified database, executes a SELECT * query with LIMIT on the table, and returns the results as a JSON string.
    case "query_table": { const dbName = args.database as string; // 데이터베이스 이름 추출 const tableName = args.table as string; // 테이블 이름 추출 // 반환할 행 수 제한 (기본값 100) const limit = typeof args.limit === 'number' && args.limit > 0 ? args.limit : 100; if (!dbName) throw new McpError(ErrorCode.InvalidParams, "필수 파라미터 누락: database"); if (!tableName) throw new McpError(ErrorCode.InvalidParams, "필수 파라미터 누락: table"); connection = await createDbConnection(dbName); // 지정된 DB로 연결 // 데이터 조회 쿼리 (안전을 위해 백틱 사용 및 LIMIT 적용) const query = `SELECT * FROM \`${tableName}\` LIMIT ?;`; const [rows] = await connection.query(query, [limit]); // 쿼리 실행 (limit 값 바인딩) return { content: [{ type: "text", text: JSON.stringify(rows, null, 2) }] }; }
  • src/index.ts:103-116 (registration)
    Registration of the 'query_table' tool in the listTools response, including its name, description, and input schema.
    { name: "query_table", description: "특정 테이블에서 데이터를 조회합니다 (제한된 행 반환).", inputSchema: { type: "object", properties: { database: { type: "string", description: "데이터베이스의 이름입니다." }, table: { type: "string", description: "테이블의 이름입니다." }, limit: { type: "number", description: "반환할 최대 행 수 (기본값 100).", default: 100 }, // 향후 개선: where_clause, columns, order_by 등 추가 }, required: ["database", "table"] } }
  • Input schema definition for the 'query_table' tool, specifying required database and table parameters, optional limit, with descriptions.
    inputSchema: { type: "object", properties: { database: { type: "string", description: "데이터베이스의 이름입니다." }, table: { type: "string", description: "테이블의 이름입니다." }, limit: { type: "number", description: "반환할 최대 행 수 (기본값 100).", default: 100 }, // 향후 개선: where_clause, columns, order_by 등 추가 }, required: ["database", "table"] }
  • Helper function to create a MySQL/MariaDB connection, used by the query_table handler to connect to the specified database.
    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}`); } }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/moosin76/mcp_server_mariadb_reader'

If you have feedback or need assistance with the MCP directory API, please join our Discord server