Skip to main content
Glama

run-raw-sql

Execute raw SQL queries with parameters to directly interact with database tables. Admin access required for data modification operations.

Instructions

Execute raw SQL query with optional parameters. Admin access required. Use with caution as it can modify data directly.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
apiKeyNoAPI key for authentication (optional if provided via --api_key)
paramsNo
queryYes

Implementation Reference

  • The core handler function for the 'run-raw-sql' MCP tool. It constructs a RawSQLRequest, sends a POST to the backend API endpoint `/api/database/advance/rawsql`, processes the response with handleApiResponse, adds background context, and handles errors appropriately.
    withUsageTracking('run-raw-sql', async ({ apiKey, query, params }) => { try { const actualApiKey = getApiKey(apiKey); const requestBody: RawSQLRequest = { query, params: params || [], }; const response = await fetch(`${API_BASE_URL}/api/database/advance/rawsql`, { method: 'POST', headers: { 'x-api-key': actualApiKey, 'Content-Type': 'application/json', }, body: JSON.stringify(requestBody), }); const result = await handleApiResponse(response); return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage('SQL query executed', result), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error executing SQL query: ${errMsg}`, }, ], isError: true, }; } })
  • The MCP server.tool registration for 'run-raw-sql', including description, input schema, and wrapped handler.
    server.tool( 'run-raw-sql', 'Execute raw SQL query with optional parameters. Admin access required. Use with caution as it can modify data directly.', { apiKey: z .string() .optional() .describe('API key for authentication (optional if provided via --api_key)'), ...rawSQLRequestSchema.shape, }, withUsageTracking('run-raw-sql', async ({ apiKey, query, params }) => { try { const actualApiKey = getApiKey(apiKey); const requestBody: RawSQLRequest = { query, params: params || [], }; const response = await fetch(`${API_BASE_URL}/api/database/advance/rawsql`, { method: 'POST', headers: { 'x-api-key': actualApiKey, 'Content-Type': 'application/json', }, body: JSON.stringify(requestBody), }); const result = await handleApiResponse(response); return await addBackgroundContext({ content: [ { type: 'text', text: formatSuccessMessage('SQL query executed', result), }, ], }); } catch (error) { const errMsg = error instanceof Error ? error.message : 'Unknown error occurred'; return { content: [ { type: 'text', text: `Error executing SQL query: ${errMsg}`, }, ], isError: true, }; } }) );
  • Zod input schema for the tool: optional apiKey and spread from rawSQLRequestSchema (provides 'query' string and optional 'params' array). rawSQLRequestSchema imported from '@insforge/shared-schemas'.
    { apiKey: z .string() .optional() .describe('API key for authentication (optional if provided via --api_key)'), ...rawSQLRequestSchema.shape, },
  • Import of rawSQLRequestSchema and RawSQLRequest type used in the tool's input schema and request body.
    import { CreateBucketRequest, createBucketRequestSchema, rawSQLRequestSchema, RawSQLRequest,
  • Helper wrapper function that adds usage tracking around tool handlers, used for 'run-raw-sql'.
    function withUsageTracking<T extends unknown[], R>( toolName: string, handler: (...args: T) => Promise<R> ): (...args: T) => Promise<R> { return async (...args: T): Promise<R> => { try { const result = await handler(...args); await trackToolUsage(toolName, true); return result; } catch (error) { await trackToolUsage(toolName, false); throw error; } }; }

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/InsForge/insforge-mcp'

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