DB 쿼리 MCP 서버
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
const server = new McpServer({ name: "db-tools", version: "1.0.0" });
server.tool("query_db",
{ sql: z.string(), params: z.array(z.any()).optional() },
async ({ sql, params }) => {
// 읽기 전용 쿼리만 허용
if (!sql.trim().toUpperCase().startsWith("SELECT")) {
throw new Error("Only SELECT queries allowed");
}
const result = await db.query(sql, params);
return { content: [{ type: "text", text: JSON.stringify(result.rows) }] };
}
);리소스 노출
MCP 리소스로 스키마 정보를 AI에 제공할 수 있습니다.
댓글 0