it-tools-mcp
Version:
Full MCP 2025-06-18 compliant server with 121+ IT tools, logging, ping, progress tracking, cancellation, and sampling utilities
47 lines (46 loc) • 2.17 kB
JavaScript
import { z } from "zod";
export function registerFormatSql(server) {
server.registerTool("format_sql", {
description: "Format and prettify SQL queries",
inputSchema: {
sql: z.string().describe("SQL query to format"),
dialect: z.string().optional().describe("SQL dialect to use for formatting (e.g., 'sql', 'mysql', 'postgresql', 'sqlite', 'mariadb', 'db2', 'plsql', 'n1ql', 'redshift', 'spark', 'tsql', 'trino', 'bigquery'). Default is 'sql'."),
},
// VS Code compliance annotations
annotations: {
title: "Format Sql",
description: "Format and prettify SQL queries",
readOnlyHint: false
}
}, async ({ sql, dialect = "sql" }) => {
try {
const { format: formatSQL } = await import("sql-formatter");
// Validate dialect and cast to correct type
const supportedDialects = [
"sql", "mysql", "postgresql", "sqlite", "mariadb", "db2", "plsql", "n1ql", "redshift", "spark", "tsql", "trino", "bigquery"
];
const language = supportedDialects.includes(dialect) ? dialect : "sql";
const formatted = formatSQL(sql, {
language
});
return {
content: [
{
type: "text",
text: `Formatted SQL (dialect: ${language}):\n\n${formatted}\n\n✅ SQL formatted successfully\n🎯 Features: uppercase keywords, proper indentation, clean structure`,
},
],
};
}
catch (error) {
return {
content: [
{
type: "text",
text: `Error formatting SQL: ${error instanceof Error ? error.message : 'Unknown error'}\n\n💡 Common SQL issues:\n• Check syntax for missing semicolons\n• Ensure proper table and column names\n• Validate string quoting (single quotes for strings)\n• Check for balanced parentheses in subqueries`,
},
],
};
}
});
}