Skip to main content
Glama

delete

Remove data from APIs by making DELETE HTTP requests to specified URLs with optional headers and authentication.

Instructions

Make a DELETE HTTP request

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to make the DELETE request to
headersNoOptional headers to include in the request
authNoOptional auth configuration to load a stored bearer token

Implementation Reference

  • Handler for the 'delete' tool: extracts URL and optional headers/auth, applies authentication if provided, validates required URL, performs DELETE request via makeHttpRequest helper, and returns a formatted text response with status and body.
    case "delete": { const url = String(args?.url || ''); const auth = args?.auth as AuthConfig | undefined; const headers = applyAuthHeader(args?.headers as Record<string, string> || {}, auth); if (!url) { throw new Error("URL is required for DELETE request"); } const result = await makeHttpRequest('DELETE', { url, headers }); return { content: [{ type: "text", text: `DELETE ${url}\nStatus: ${result.status} ${result.statusText}\nResponse: ${JSON.stringify(result.data, null, 2)}` }] }; }
  • src/index.ts:200-234 (registration)
    Registration of the 'delete' tool in the listTools response, defining its name, description, and input schema for URL, optional headers, and auth.
    { name: "delete", description: "Make a DELETE HTTP request", inputSchema: { type: "object", properties: { url: { type: "string", description: "The URL to make the DELETE request to" }, headers: { type: "object", description: "Optional headers to include in the request", additionalProperties: { type: "string" } }, auth: { type: "object", description: "Optional auth configuration to load a stored bearer token", properties: { folder: { type: "string", description: "Folder where tokens are stored (tokens.json)" }, user_title: { type: "string", description: "User title to pick the token from storage (default: 'default')" } } } }, required: ["url"] } },
  • Shared helper function that executes the actual HTTP request for all tools, including DELETE. Handles logging, options preparation, fetch call, response parsing, and error handling.
    async function makeHttpRequest(method: string, config: HttpRequestConfig) { try { server.sendLoggingMessage({ level: "info", data: `Starting ${method.toUpperCase()} request to: ${config.url}`, }); const options: NodeRequestInit = { method: method.toUpperCase(), headers: { ...config.headers, }, }; if (config.body && (method === 'POST' || method === 'PUT')) { if (config.requestType === 'form-data') { server.sendLoggingMessage({ level: "info", data: `Using form-data request type with fieldFiles: ${JSON.stringify(config.fieldFiles)}`, }); // Use FormData for form-data requests const formData = await createFormData(config.body, config.fieldFiles); options.body = formData as any; // Cast to any to handle type incompatibility server.sendLoggingMessage({ level: "info", data: `FormData prepared, not setting Content-Type header (will be auto-set with boundary)`, }); // Don't set Content-Type header for FormData, let the system set it with boundary } else { server.sendLoggingMessage({ level: "info", data: `Using JSON request type`, }); // Use JSON for regular requests options.headers = { 'Content-Type': 'application/json', ...options.headers, }; options.body = typeof config.body === 'string' ? config.body : JSON.stringify(config.body); server.sendLoggingMessage({ level: "info", data: `JSON body prepared: ${options.body}`, }); } } else if (!config.body && method !== 'GET' && method !== 'DELETE') { // Set default Content-Type for POST/PUT without body options.headers = { 'Content-Type': 'application/json', ...options.headers, }; } server.sendLoggingMessage({ level: "info", data: `Request headers: ${JSON.stringify(options.headers)}`, }); server.sendLoggingMessage({ level: "info", data: `Making HTTP request...`, }); const response = await fetch(config.url, options); server.sendLoggingMessage({ level: "info", data: `Response received: ${response.status} ${response.statusText}`, }); const responseText = await response.text(); server.sendLoggingMessage({ level: "info", data: `Response body: ${responseText}`, }); // Try to parse as JSON, fallback to text let responseData; try { responseData = JSON.parse(responseText); } catch { responseData = responseText; } // Store in history requestHistory.push({ method: method.toUpperCase(), config, timestamp: new Date() }); return { status: response.status, statusText: response.statusText, headers: Object.fromEntries(response.headers.entries()), data: responseData }; } catch (error) { server.sendLoggingMessage({ level: "error", data: `HTTP ${method.toUpperCase()} request failed: ${error instanceof Error ? error.message : String(error)}`, }); throw new Error(`HTTP ${method.toUpperCase()} request failed: ${error instanceof Error ? error.message : String(error)}`); } }
  • Helper function to apply stored bearer token Authorization header based on auth config (folder and user_title), used by delete handler.
    function applyAuthHeader(headers: Record<string, string>, auth?: AuthConfig): Record<string, string> { if (!auth) { return headers; } const folder = auth.folder; if (!folder) { throw new Error("auth.folder is required when using auth configuration"); } if (headers.Authorization) { return headers; } const userTitle = auth.user_title || 'default'; const tokens = loadStoredTokens(folder); const tokenEntry = tokens.find((entry) => entry.user_title_name === userTitle); if (!tokenEntry) { throw new Error(`No token found for user_title '${userTitle}' in folder '${folder}'`); } return { ...headers, Authorization: `Bearer ${tokenEntry.token}`, }; }

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/vilasone455/api-mcp'

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