Skip to main content
Glama
Switchboard666

HaloPSA MCP Server

halopsa_build_query

Construct SQL queries for HaloPSA data with proper syntax. Build SELECT queries with WHERE conditions, ORDER BY, and LIMIT clauses without writing raw SQL code.

Instructions

Build a basic SQL query for HaloPSA with a helper that ensures proper syntax. Useful for constructing simple SELECT queries with WHERE conditions, ORDER BY, and LIMIT clauses without writing raw SQL.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
tableNameYesTable to query from (e.g., FAULTS, USERS, SITE)
columnsNoColumns to select (optional, defaults to all). Example: ["Faultid", "Symptom", "Status"]
conditionsNoWHERE conditions as key-value pairs. Example: {"Status": 1, "Priority": 3}
orderByNoColumn to order results by. Example: "datereported DESC"
limitNoMaximum number of rows to return. Example: 10

Implementation Reference

  • Handler for 'halopsa_build_query' tool. Parses input parameters (tableName, columns, conditions, orderBy, limit) and constructs a SQL SELECT query string with proper escaping for strings and NULL handling. Returns the generated query and input components as JSON.
    case 'halopsa_build_query': {
      const { tableName, columns, conditions, orderBy, limit } = args as any;
      if (!tableName) {
        throw new Error('Table name is required');
      }
      
      let query = 'SELECT ';
      
      if (limit && typeof limit === 'number') {
        query += `TOP ${limit} `;
      }
      
      if (columns && Array.isArray(columns) && columns.length > 0) {
        query += columns.join(', ');
      } else {
        query += '*';
      }
      
      query += ` FROM ${tableName}`;
      
      if (conditions && typeof conditions === 'object' && Object.keys(conditions).length > 0) {
        const whereClauses = Object.entries(conditions).map(([key, value]) => {
          if (typeof value === 'string') {
            const escapedValue = value.replace(/'/g, "''");
            return `${key} = '${escapedValue}'`;
          } else if (value === null) {
            return `${key} IS NULL`;
          } else {
            return `${key} = ${value}`;
          }
        });
        query += ' WHERE ' + whereClauses.join(' AND ');
      }
      
      if (orderBy) {
        query += ` ORDER BY ${orderBy}`;
      }
      
      return {
        content: [{
          type: 'text',
          text: JSON.stringify({
            generatedQuery: query,
            components: {
              table: tableName,
              columns: columns || ['*'],
              conditions: conditions || {},
              orderBy: orderBy || 'none',
              limit: limit || 'none'
            }
          }, null, 2)
        }]
      };
    }
  • Tool schema definition including name, description, and inputSchema with properties for tableName (required), columns (array), conditions (object), orderBy (string), limit (number).
    {
      name: 'halopsa_build_query',
      description: 'Build a basic SQL query for HaloPSA with a helper that ensures proper syntax. Useful for constructing simple SELECT queries with WHERE conditions, ORDER BY, and LIMIT clauses without writing raw SQL.',
      inputSchema: {
        type: 'object',
        properties: {
          tableName: {
            type: 'string',
            description: 'Table to query from (e.g., FAULTS, USERS, SITE)'
          },
          columns: {
            type: 'array',
            items: { type: 'string' },
            description: 'Columns to select (optional, defaults to all). Example: ["Faultid", "Symptom", "Status"]'
          },
          conditions: {
            type: 'object',
            description: 'WHERE conditions as key-value pairs. Example: {"Status": 1, "Priority": 3}'
          },
          orderBy: {
            type: 'string',
            description: 'Column to order results by. Example: "datereported DESC"'
          },
          limit: {
            type: 'number',
            description: 'Maximum number of rows to return. Example: 10'
          }
        },
        required: ['tableName']
      }
    },
  • src/index.ts:42-276 (registration)
    The tool is registered in the tools array used by ListToolsRequestHandler to advertise available tools.
    const tools: Tool[] = [
      {
        name: 'halopsa_list_tables',
        description: 'List all available tables in the HaloPSA database by querying sys.tables. Returns a complete list of all tables that can be queried. Use this to discover what data is available before writing queries.',
        inputSchema: {
          type: 'object',
          properties: {
            filter: {
              type: 'string',
              description: 'Optional filter to search for specific tables. Example: "fault", "user", "ticket"'
            }
          }
        }
      },
      {
        name: 'halopsa_list_columns',
        description: 'List columns for a specific table in the HaloPSA database using information_schema.columns. Returns detailed column information including data types, max length, and nullable status.',
        inputSchema: {
          type: 'object',
          properties: {
            tableName: {
              type: 'string',
              description: 'Table name to get columns for. Example: FAULTS, USERS, SITE'
            },
            columnFilter: {
              type: 'string',
              description: 'Optional filter to search for specific column names. Example: "id", "name", "date"'
            }
          },
          required: ['tableName']
        }
      },
      {
        name: 'halopsa_query',
        description: 'Execute a SQL query against HaloPSA reporting API. Use this to retrieve data from any HaloPSA table including tickets (FAULTS), users (USERS), sites (SITE), actions (ACTIONS), request types (REQUESTTYPE), and more. Returns the full report response with data rows, column metadata, and available filters.',
        inputSchema: {
          type: 'object',
          properties: {
            sql: {
              type: 'string',
              description: 'SQL query to execute against HaloPSA database. Supports standard SQL syntax including SELECT, JOIN, WHERE, ORDER BY, GROUP BY, etc. Example: SELECT * FROM FAULTS WHERE Status = 1'
            },
            loadReportOnly: {
              type: 'boolean',
              description: 'Whether to load report data only (default: true)',
              default: true
            }
          },
          required: ['sql']
        }
      },
      {
        name: 'halopsa_table_info',
        description: 'Get detailed information about a specific HaloPSA table including all columns, data types, nullable fields, and relationship suggestions. Use this to understand table structure before writing queries.',
        inputSchema: {
          type: 'object',
          properties: {
            tableName: {
              type: 'string',
              description: 'Name of the table to inspect. Example: FAULTS, USERS, SITE, ACTIONS, REQUESTTYPE'
            }
          },
          required: ['tableName']
        }
      },
      {
        name: 'halopsa_build_query',
        description: 'Build a basic SQL query for HaloPSA with a helper that ensures proper syntax. Useful for constructing simple SELECT queries with WHERE conditions, ORDER BY, and LIMIT clauses without writing raw SQL.',
        inputSchema: {
          type: 'object',
          properties: {
            tableName: {
              type: 'string',
              description: 'Table to query from (e.g., FAULTS, USERS, SITE)'
            },
            columns: {
              type: 'array',
              items: { type: 'string' },
              description: 'Columns to select (optional, defaults to all). Example: ["Faultid", "Symptom", "Status"]'
            },
            conditions: {
              type: 'object',
              description: 'WHERE conditions as key-value pairs. Example: {"Status": 1, "Priority": 3}'
            },
            orderBy: {
              type: 'string',
              description: 'Column to order results by. Example: "datereported DESC"'
            },
            limit: {
              type: 'number',
              description: 'Maximum number of rows to return. Example: 10'
            }
          },
          required: ['tableName']
        }
      },
      {
        name: 'halopsa_list_api_endpoints',
        description: 'List all API endpoints with their paths, methods, and summaries. Use this first to discover available endpoints, then use halopsa_get_api_endpoint_details for full details. Supports pagination.',
        inputSchema: {
          type: 'object',
          properties: {
            category: {
              type: 'string',
              description: 'Optional category filter (e.g., "Tickets", "Actions", "Clients", "Sites")'
            },
            limit: {
              type: 'number',
              description: 'Maximum number of endpoints to return (default: 100)',
              default: 100
            },
            skip: {
              type: 'number',
              description: 'Number of endpoints to skip for pagination (default: 0)',
              default: 0
            }
          }
        }
      },
      {
        name: 'halopsa_get_api_endpoint_details',
        description: 'Get complete details for specific API endpoints including parameters, request/response schemas, and examples. Use after finding endpoints with halopsa_list_api_endpoints.',
        inputSchema: {
          type: 'object',
          properties: {
            pathPattern: {
              type: 'string',
              description: 'Path pattern to match endpoints (e.g., "ticket", "action", "client", "agent")'
            },
            summaryOnly: {
              type: 'boolean',
              description: 'Return only basic endpoint information (path, methods, summary) without detailed schemas - ideal for quick API exploration',
              default: false
            },
            includeSchemas: {
              type: 'boolean',
              description: 'Include detailed request/response schemas (default: true, set to false to significantly reduce response size)',
              default: true
            },
            maxEndpoints: {
              type: 'number',
              description: 'Maximum number of endpoints to return (default: 10, max: 50) - helps manage response size',
              default: 10
            },
            includeExamples: {
              type: 'boolean',
              description: 'Include request/response examples (default: false to keep responses smaller)',
              default: false
            }
          },
          required: ['pathPattern']
        }
      },
      {
        name: 'halopsa_search_api_endpoints',
        description: 'Search for API endpoints by keywords. Returns matching endpoints with basic info. Use halopsa_get_api_endpoint_details for full details of specific endpoints. Supports pagination.',
        inputSchema: {
          type: 'object',
          properties: {
            query: {
              type: 'string',
              description: 'Search query to find endpoints (searches in paths, summaries, descriptions, and tags)'
            },
            limit: {
              type: 'number',
              description: 'Maximum number of results to return (default: 50)',
              default: 50
            },
            skip: {
              type: 'number',
              description: 'Number of results to skip for pagination (default: 0)',
              default: 0
            }
          },
          required: ['query']
        }
      },
      {
        name: 'halopsa_get_api_schemas',
        description: 'Get API schemas/models from the swagger definition. Shows the structure of request/response objects used by the API endpoints. Supports pagination.',
        inputSchema: {
          type: 'object',
          properties: {
            schemaPattern: {
              type: 'string',
              description: 'Optional pattern to filter schemas by name (e.g., "Ticket", "Action", "Client")'
            },
            limit: {
              type: 'number',
              description: 'Maximum number of schemas to return (default: 50)',
              default: 50
            },
            skip: {
              type: 'number',
              description: 'Number of matching schemas to skip for pagination (default: 0)',
              default: 0
            },
            listNames: {
              type: 'boolean',
              description: 'Include list of all matching schema names (default: false, auto-included if ≤20 matches)',
              default: false
            }
          }
        }
      },
      {
        name: 'halopsa_api_call',
        description: 'Make authenticated API calls to any HaloPSA endpoint. Use this after finding the right endpoint with schema tools.',
        inputSchema: {
          type: 'object',
          properties: {
            path: {
              type: 'string',
              description: 'API endpoint path (e.g., "/api/Ticket", "/api/Actions")'
            },
            method: {
              type: 'string',
              enum: ['GET', 'POST', 'PUT', 'PATCH', 'DELETE'],
              description: 'HTTP method to use',
              default: 'GET'
            },
            body: {
              type: 'object',
              description: 'Request body data for POST/PUT/PATCH requests'
            },
            queryParams: {
              type: 'object',
              description: 'URL query parameters as key-value pairs',
              additionalProperties: { type: 'string' }
            }
          },
          required: ['path']
        }
      }
    ];
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It mentions the tool 'ensures proper syntax' and is for 'constructing' queries, implying it's a read-only helper without execution. However, it lacks details on behavioral traits such as error handling, output format (e.g., returns a query string), or any limitations (e.g., complexity constraints).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and well-structured in two sentences. The first sentence states the core purpose, and the second adds context on utility and scope. Every sentence earns its place without redundancy, making it easy to parse.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (5 parameters, no output schema, no annotations), the description is adequate but incomplete. It covers the basic purpose and usage but lacks details on behavioral aspects and output (e.g., what the built query looks like). Without annotations or output schema, more context on results would be helpful.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema fully documents all 5 parameters. The description adds minimal value beyond the schema, mentioning 'SELECT queries with WHERE conditions, ORDER BY, and LIMIT clauses,' which aligns with parameters like 'conditions,' 'orderBy,' and 'limit.' This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Build a basic SQL query for HaloPSA with a helper that ensures proper syntax.' It specifies the action (build SQL query) and resource (HaloPSA), and distinguishes it from raw SQL writing. However, it doesn't explicitly differentiate from sibling tools like 'halopsa_query' which might execute queries.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides implied usage guidance: 'Useful for constructing simple SELECT queries with WHERE conditions, ORDER BY, and LIMIT clauses.' This suggests when to use it (for simple queries) but doesn't explicitly state when not to use it or mention alternatives among sibling tools like 'halopsa_query' for execution.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/Switchboard666/halopsa-mcp'

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