Skip to main content
Glama

run-raw-sql

Execute raw SQL queries with optional parameters to directly modify database data. Requires admin access and caution due to direct database interaction.

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)
queryYes
paramsNo

Implementation Reference

  • The handler function for the 'run-raw-sql' tool. It authenticates using the API key, constructs a RawSQLRequest with the provided query and parameters, sends a POST request to the backend API endpoint `/api/database/advance/rawsql`, handles the response, adds background context if applicable, and returns formatted success/error messages.
    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, }; } })
  • Input parameters schema defined using Zod. Includes an optional 'apiKey' field and spreads the shape of 'rawSQLRequestSchema' which provides 'query' (string) and 'params' (array) fields for the SQL execution.
    { apiKey: z .string() .optional() .describe('API key for authentication (optional if provided via --api_key)'), ...rawSQLRequestSchema.shape, },
  • Registration of the 'run-raw-sql' tool on the MCP server using server.tool(). Specifies the tool name, description, input schema, and references the wrapped handler function with usage tracking.
    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, }; } }) );

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