UNPKG

@bilims/mcp-sqlserver

Version:

MCP Server for Microsoft SQL Server with CRUD operations and data analysis capabilities

213 lines (212 loc) 7.4 kB
import { z } from 'zod'; import { DatabaseConnection } from '../database/connection.js'; import { QueryOptions } from '../types/config.js'; export declare const SelectToolSchema: z.ZodObject<{ table: z.ZodString; columns: z.ZodOptional<z.ZodArray<z.ZodString, "many">>; where: z.ZodOptional<z.ZodArray<z.ZodObject<{ column: z.ZodString; operator: z.ZodEnum<["=", "!=", ">", "<", ">=", "<=", "LIKE", "IN", "NOT IN", "IS NULL", "IS NOT NULL"]>; value: z.ZodOptional<z.ZodAny>; }, "strip", z.ZodTypeAny, { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }, { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }>, "many">>; joins: z.ZodOptional<z.ZodArray<z.ZodObject<{ type: z.ZodEnum<["INNER", "LEFT", "RIGHT", "FULL"]>; table: z.ZodString; on: z.ZodString; }, "strip", z.ZodTypeAny, { type: "INNER" | "LEFT" | "RIGHT" | "FULL"; on: string; table: string; }, { type: "INNER" | "LEFT" | "RIGHT" | "FULL"; on: string; table: string; }>, "many">>; orderBy: z.ZodOptional<z.ZodArray<z.ZodObject<{ column: z.ZodString; direction: z.ZodDefault<z.ZodEnum<["ASC", "DESC"]>>; }, "strip", z.ZodTypeAny, { column: string; direction: "ASC" | "DESC"; }, { column: string; direction?: "ASC" | "DESC" | undefined; }>, "many">>; limit: z.ZodOptional<z.ZodNumber>; offset: z.ZodOptional<z.ZodNumber>; }, "strip", z.ZodTypeAny, { table: string; columns?: string[] | undefined; where?: { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }[] | undefined; joins?: { type: "INNER" | "LEFT" | "RIGHT" | "FULL"; on: string; table: string; }[] | undefined; orderBy?: { column: string; direction: "ASC" | "DESC"; }[] | undefined; limit?: number | undefined; offset?: number | undefined; }, { table: string; columns?: string[] | undefined; where?: { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }[] | undefined; joins?: { type: "INNER" | "LEFT" | "RIGHT" | "FULL"; on: string; table: string; }[] | undefined; orderBy?: { column: string; direction?: "ASC" | "DESC" | undefined; }[] | undefined; limit?: number | undefined; offset?: number | undefined; }>; export declare const InsertToolSchema: z.ZodObject<{ table: z.ZodString; data: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodAny>, Record<string, any>, Record<string, any>>; }, "strip", z.ZodTypeAny, { table: string; data: Record<string, any>; }, { table: string; data: Record<string, any>; }>; export declare const UpdateToolSchema: z.ZodObject<{ table: z.ZodString; data: z.ZodEffects<z.ZodRecord<z.ZodString, z.ZodAny>, Record<string, any>, Record<string, any>>; where: z.ZodArray<z.ZodObject<{ column: z.ZodString; operator: z.ZodEnum<["=", "!=", ">", "<", ">=", "<=", "LIKE", "IN", "NOT IN", "IS NULL", "IS NOT NULL"]>; value: z.ZodOptional<z.ZodAny>; }, "strip", z.ZodTypeAny, { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }, { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }>, "many">; }, "strip", z.ZodTypeAny, { table: string; where: { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }[]; data: Record<string, any>; }, { table: string; where: { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }[]; data: Record<string, any>; }>; export declare const DeleteToolSchema: z.ZodObject<{ table: z.ZodString; where: z.ZodArray<z.ZodObject<{ column: z.ZodString; operator: z.ZodEnum<["=", "!=", ">", "<", ">=", "<=", "LIKE", "IN", "NOT IN", "IS NULL", "IS NOT NULL"]>; value: z.ZodOptional<z.ZodAny>; }, "strip", z.ZodTypeAny, { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }, { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }>, "many">; }, "strip", z.ZodTypeAny, { table: string; where: { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }[]; }, { table: string; where: { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }[]; }>; export declare const CustomQuerySchema: z.ZodObject<{ query: z.ZodString; parameters: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodAny>>; }, "strip", z.ZodTypeAny, { query: string; parameters?: Record<string, any> | undefined; }, { query: string; parameters?: Record<string, any> | undefined; }>; export declare class CrudTools { private db; constructor(db: DatabaseConnection); executeSelect(params: z.infer<typeof SelectToolSchema>, options?: QueryOptions): Promise<{ success: boolean; rowCount: number; data: import("mssql").IRecordSet<any>; query: string; executionTime: string; }>; executeInsert(params: z.infer<typeof InsertToolSchema>): Promise<{ success: boolean; rowsAffected: any; query: string; insertedData: Record<string, any>; }>; executeUpdate(params: z.infer<typeof UpdateToolSchema>): Promise<{ success: boolean; rowsAffected: any; query: string; updatedData: Record<string, any>; whereConditions: { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }[]; }>; executeDelete(params: z.infer<typeof DeleteToolSchema>): Promise<{ success: boolean; rowsAffected: any; query: string; whereConditions: { column: string; operator: "=" | "!=" | ">" | "<" | ">=" | "<=" | "LIKE" | "IN" | "NOT IN" | "IS NULL" | "IS NOT NULL"; value?: any; }[]; }>; executeCustomQuery(params: z.infer<typeof CustomQuerySchema>, options?: QueryOptions): Promise<{ success: boolean; rowCount: number; data: any[]; query: string; executionTime: string; truncated: boolean; }>; }