@aditya-vaish/kusto-mcp-server
Version:
MCP server for interacting with Kusto databases
79 lines • 3.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.executeQueryTool = void 0;
const zod_1 = require("zod");
const kustoService_1 = require("../services/kustoService");
// Tool to execute KQL queries
exports.executeQueryTool = {
name: "execute_query",
description: `This tool executes a Kusto query against the database and returns the results.
The query must be a valid KQL query without administrative commands.
The result is a JSON object containing the query results.
Inputs: clusterUrl, database, query, maxRows (optional, default is 100).
Note: When querying external tables make sure to use apppropriate syntax (e.g. 'external_table(<table_name>)').
Note: The query *must* not contain any administrative commands or control commands.
Note: For listing tables, use the 'list_tables' tool.
Note: For getting table schema, use the 'get_table_schema' tool.`,
parameters: {
clusterUrl: zod_1.z.string().describe("The Kusto cluster URL (e.g., https://yourcluster.kusto.windows.net)"),
database: zod_1.z.string().describe("The name of the database in the Kusto cluster"),
query: zod_1.z.string().min(1).max(10000).describe("The KQL query to execute"),
maxRows: zod_1.z.number().int().min(1).max(10000).optional().default(100).describe("Maximum number of rows to return (default: 100)")
},
handler: async ({ clusterUrl, database, query, maxRows = 100 }) => {
// Check for forbidden administrative commands
const controlCommandPatterns = [
/alter\s+table/i,
/create\s+table/i,
/drop\s+table/i,
/set\s+/i,
/function/i,
/policy/i,
/purge/i,
/ingestion/i,
/database/i,
/cluster/i,
/management/i,
/\|\s*render/i,
/let\s+\w+\s*=/i
];
for (const pattern of controlCommandPatterns) {
if (pattern.test(query)) {
return {
content: [
{
type: "text",
text: `Error: The query contains forbidden administrative commands or syntax.
Please use only Kusto query language (KQL) operations.
Note: For listing tables, use the \`list_tables\` tool.
Note: For getting table schema, use the \`get_table_schema\` tool.`
}
]
};
}
}
try {
const safeQuery = `${query} | take ${maxRows}`;
const result = await kustoService_1.KustoService.executeQuery(clusterUrl, database, safeQuery);
return {
content: [
{
type: "text",
text: `Query results: ${JSON.stringify(result, null, 2)}`
}
]
};
}
catch (error) {
return {
content: [
{
type: "text",
text: `Error executing query: ${error.message}`
}
]
};
}
}
};
//# sourceMappingURL=execute-query.js.map