put
Send PUT HTTP requests to update or replace resources at specified URLs, supporting JSON data, form data with file uploads, custom headers, and authentication.
Instructions
Make a PUT HTTP request
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | The URL to make the PUT request to | |
| headers | No | Optional headers to include in the request | |
| body | No | The request body (JSON object, string, etc.) | |
| requestType | No | Request type: 'json' for JSON data, 'form-data' for form data with file uploads | |
| fieldFiles | No | Array of field names that should be treated as files. Values can be URLs (http/https) for remote files or local file paths for local files. The system will automatically download remote files or read local files and include them as file attachments in the form data. | |
| auth | No | Optional auth configuration to load a stored bearer token |
Implementation Reference
- src/index.ts:820-840 (handler)The handler function for the 'put' tool within the CallToolRequestSchema handler. It processes input arguments, applies authentication headers if provided, validates the URL, calls the makeHttpRequest helper with method 'PUT', and formats the response as text content.case "put": { const url = String(args?.url || ''); const auth = args?.auth as AuthConfig | undefined; const headers = applyAuthHeader(args?.headers as Record<string, string> || {}, auth); const body = args?.body; const requestType = args?.requestType as 'json' | 'form-data' || 'json'; const fieldFiles = args?.fieldFiles as string[] || []; if (!url) { throw new Error("URL is required for PUT request"); } const result = await makeHttpRequest('PUT', { url, headers, body, requestType, fieldFiles }); return { content: [{ type: "text", text: `PUT ${url}\nRequest Type: ${requestType}\nStatus: ${result.status} ${result.statusText}\nResponse: ${JSON.stringify(result.data, null, 2)}` }] }; }
- src/index.ts:150-199 (registration)The registration of the 'put' tool in the ListToolsRequestSchema response, defining its name, description, and input schema.{ name: "put", description: "Make a PUT HTTP request", inputSchema: { type: "object", properties: { url: { type: "string", description: "The URL to make the PUT request to" }, headers: { type: "object", description: "Optional headers to include in the request", additionalProperties: { type: "string" } }, body: { description: "The request body (JSON object, string, etc.)" }, requestType: { type: "string", enum: ["json", "form-data"], description: "Request type: 'json' for JSON data, 'form-data' for form data with file uploads" }, fieldFiles: { type: "array", items: { type: "string" }, description: "Array of field names that should be treated as files. Values can be URLs (http/https) for remote files or local file paths for local files. The system will automatically download remote files or read local files and include them as file attachments in the form data." }, 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"] } },
- src/index.ts:153-198 (schema)The input schema for the 'put' tool, specifying required 'url' and optional properties like headers, body, requestType (json/form-data), fieldFiles for uploads, and auth config.inputSchema: { type: "object", properties: { url: { type: "string", description: "The URL to make the PUT request to" }, headers: { type: "object", description: "Optional headers to include in the request", additionalProperties: { type: "string" } }, body: { description: "The request body (JSON object, string, etc.)" }, requestType: { type: "string", enum: ["json", "form-data"], description: "Request type: 'json' for JSON data, 'form-data' for form data with file uploads" }, fieldFiles: { type: "array", items: { type: "string" }, description: "Array of field names that should be treated as files. Values can be URLs (http/https) for remote files or local file paths for local files. The system will automatically download remote files or read local files and include them as file attachments in the form data." }, 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"] }
- src/index.ts:662-770 (helper)Shared helper function that executes the actual HTTP request for PUT (and other methods). Handles body formatting for JSON or form-data (including file uploads from URLs/local paths), authentication headers, logging, 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)}`); } }