Skip to main content
Glama

post

Send POST HTTP requests to APIs with JSON or form data, including file uploads and authentication support.

Instructions

Make a pOST HTTP request

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYesThe URL to make the POST request to
headersNoOptional headers to include in the request
bodyNoThe request body (JSON object, string, etc.)
requestTypeNoRequest type: 'json' for JSON data, 'form-data' for form data with file uploads
fieldFilesNoArray 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.
authNoOptional auth configuration to load a stored bearer token

Implementation Reference

  • Handler for the 'post' tool: extracts parameters, applies authentication headers if provided, validates URL, calls makeHttpRequest with POST method, and returns formatted response including status and data.
    case "post": {
      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 POST request");
      }
    
      const result = await makeHttpRequest('POST', { url, headers, body, requestType, fieldFiles });
      
      return {
        content: [{
          type: "text",
          text: `POST ${url}\nRequest Type: ${requestType}\nStatus: ${result.status} ${result.statusText}\nResponse: ${JSON.stringify(result.data, null, 2)}`
        }]
      };
    }
  • src/index.ts:100-149 (registration)
    Registration of the 'post' tool in the ListTools response, defining its name, description, and input schema including parameters for URL, headers, body, requestType, fieldFiles, and auth.
    {
      name: "post",
      description: "Make a pOST HTTP request",
      inputSchema: {
        type: "object",
        properties: {
          url: {
            type: "string",
            description: "The URL to make the POST 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"]
      }
    },
  • Input schema definition for the 'post' tool, specifying properties like url (required), headers, body, requestType (json|form-data), fieldFiles for file uploads, and auth configuration.
    inputSchema: {
      type: "object",
      properties: {
        url: {
          type: "string",
          description: "The URL to make the POST 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"]
    }
  • Core helper function makeHttpRequest that executes the HTTP POST request, handling different body types (JSON or form-data with file uploads), logging, auth headers, and response parsing.
    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)}`);
      }
    }
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure but offers minimal information. It mentions making a POST request but doesn't describe key traits like error handling, response format, rate limits, or authentication requirements (though the 'auth' parameter hints at token usage). This leaves significant gaps for an agent to understand how the tool behaves in practice.

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

Conciseness4/5

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

The description is extremely concise ('Make a pOST HTTP request'), which is efficient and front-loaded. However, it's overly brief for a tool with 6 parameters and complex functionality like file uploads and authentication, potentially under-specifying rather than being optimally concise. It earns a 4 for zero waste but lacks necessary detail.

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

Completeness2/5

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

Given the tool's complexity (6 parameters, nested objects, no output schema, and no annotations), the description is incomplete. It doesn't explain what the tool returns, error conditions, or how it integrates with sibling tools. For a general-purpose HTTP tool with rich input options, more context is needed to guide effective use.

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?

The description adds no parameter semantics beyond what the input schema provides. Since schema description coverage is 100%, the schema already documents all parameters thoroughly (e.g., 'url' as the target URL, 'requestType' with enums). The baseline score of 3 reflects adequate coverage by the schema alone, with no additional value from the description.

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

Purpose3/5

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

The description 'Make a pOST HTTP request' states the basic action (make a POST request) but is vague about scope and differentiation. It doesn't specify what resources or endpoints it targets, nor how it differs from sibling tools like 'put' or 'delete' beyond the HTTP method. The purpose is clear at a high level but lacks specificity.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention when POST is appropriate (e.g., for creating resources, submitting data) compared to other HTTP methods like GET or PUT, or other tools like 'auth_login'. There's no context on prerequisites, such as authentication needs, leaving usage unclear.

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

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