Skip to main content
Glama
DeanWard

HAL (HTTP API Layer)

HTTP PATCH Request

http-patch

Send HTTP PATCH requests to a specific URL with optional body, headers, and secret substitution. Use {secrets.key} syntax to securely include environment variables in URL, headers, or body.

Instructions

Make an HTTP PATCH request to a specified URL with optional body and headers. Supports secret substitution using {secrets.key} syntax in URL, headers, and body where 'key' corresponds to HAL_SECRET_KEY environment variables.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bodyNo
contentTypeNoapplication/json
headersNo
urlYes

Implementation Reference

  • src/index.ts:628-647 (registration)
    Registration of the 'http-patch' MCP tool, including title, description, input schema (url, body, headers, contentType), and handler function that prepares headers and delegates to makeHttpRequest.
    server.registerTool(
      "http-patch",
      {
        title: "HTTP PATCH Request",
        description: "Make an HTTP PATCH request to a specified URL with optional body and headers. Supports secret substitution using {secrets.key} syntax in URL, headers, and body where 'key' corresponds to HAL_SECRET_KEY environment variables.",
        inputSchema: {
          url: z.string().url(),
          body: z.string().optional(),
          headers: z.record(z.string()).optional(),
          contentType: z.string().default('application/json')
        }
      },
      async ({ url, body, headers = {}, contentType }: { url: string; body?: string; headers?: Record<string, string>; contentType: string }) => {
        const requestHeaders = {
          'Content-Type': contentType,
          ...headers
        };
        return makeHttpRequest('PATCH', url, { headers: requestHeaders, body });
      }
    );
  • The handler function for 'http-patch' tool: constructs Content-Type header and calls shared makeHttpRequest with method 'PATCH'.
    async ({ url, body, headers = {}, contentType }: { url: string; body?: string; headers?: Record<string, string>; contentType: string }) => {
      const requestHeaders = {
        'Content-Type': contentType,
        ...headers
      };
      return makeHttpRequest('PATCH', url, { headers: requestHeaders, body });
    }
  • Input schema for 'http-patch' tool using Zod: requires url (validated as URL), optional body (string), headers (record<string>), contentType default 'application/json'.
    {
      title: "HTTP PATCH Request",
      description: "Make an HTTP PATCH request to a specified URL with optional body and headers. Supports secret substitution using {secrets.key} syntax in URL, headers, and body where 'key' corresponds to HAL_SECRET_KEY environment variables.",
      inputSchema: {
        url: z.string().url(),
        body: z.string().optional(),
        headers: z.record(z.string()).optional(),
        contentType: z.string().default('application/json')
      }
  • Core helper function makeHttpRequest implements all HTTP logic: secret substitution in URL/headers/body/query, global URL filtering, fetch execution, JSON/text response handling, secret redaction in output. Called by http-patch and other HTTP tools.
    async function makeHttpRequest(
      method: string,
      url: string,
      options: {
        headers?: Record<string, string>;
        body?: string;
        queryParams?: Record<string, any>;
      } = {}
    ) {
      try {
        const { headers = {}, body, queryParams = {} } = options;
        
        // First, substitute secrets in URL to get the final URL for validation
        // We need to do this in two passes to handle URL restrictions properly
        const processedUrl = substituteSecrets(url, url);
        
        // Now substitute secrets in headers, body, and query parameters using the processed URL
        const processedHeaders = substituteSecretsInObject(headers, processedUrl);
        const processedBody = body ? substituteSecrets(body, processedUrl) : body;
        const processedQueryParams = substituteSecretsInObject(queryParams, processedUrl);
        
        // Build URL with query parameters
        const urlObj = new URL(processedUrl);
        Object.entries(processedQueryParams).forEach(([key, value]) => {
          if (value !== undefined && value !== null) {
            urlObj.searchParams.set(key, String(value));
          }
        });
        
        const finalUrl = urlObj.toString();
        
        // Check global URL whitelist/blacklist
        const urlCheck = isUrlAllowedGlobal(finalUrl);
        if (!urlCheck.allowed) {
          throw new Error(urlCheck.reason || 'URL is not allowed');
        }
        
        const defaultHeaders = {
          'User-Agent': 'HAL-MCP/1.0.0',
          ...processedHeaders
        };
        
             // Add Content-Type for methods that typically send data
         if (['POST', 'PUT', 'PATCH'].includes(method.toUpperCase()) && processedBody && !('Content-Type' in processedHeaders)) {
           (defaultHeaders as any)['Content-Type'] = 'application/json';
         }
        
        const response = await fetch(finalUrl, {
          method: method.toUpperCase(),
          headers: defaultHeaders,
          body: processedBody
        });
    
        const contentType = response.headers.get('content-type') || 'text/plain';
        let content: string;
        
        // HEAD requests don't have a body by design
        if (method.toUpperCase() === 'HEAD') {
          content = '(No body - HEAD request)';
        } else {
          try {
            if (contentType.includes('application/json')) {
              const text = await response.text();
              if (text.trim()) {
                content = JSON.stringify(JSON.parse(text), null, 2);
              } else {
                content = '(Empty response)';
              }
            } else {
              content = await response.text();
            }
          } catch (parseError) {
            // If JSON parsing fails, try to get text
            try {
              content = await response.text();
            } catch (textError) {
              content = '(Unable to parse response)';
            }
          }
        }
    
        // Redact secrets from response headers and content before returning
        const redactedHeaders = Array.from(response.headers.entries())
          .map(([key, value]) => `${key}: ${redactSecretsFromText(value)}`)
          .join('\n');
        const redactedContent = redactSecretsFromText(content);
    
             return {
           content: [{
             type: "text" as const,
             text: `Status: ${response.status} ${response.statusText}\n\nHeaders:\n${redactedHeaders}\n\nBody:\n${redactedContent}`
           }]
         };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : 'Unknown error';
        const redactedErrorMessage = redactSecretsFromText(errorMessage);
             return {
           content: [{
             type: "text" as const,
             text: `Error making ${method.toUpperCase()} request: ${redactedErrorMessage}`
           }],
           isError: true
         };
      }
    }
Behavior4/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. It effectively describes key traits: it performs an HTTP request (implying network interaction), supports secret substitution with specific syntax, and mentions environment variable integration. However, it lacks details on error handling, timeouts, or response formats, which are important for a network tool.

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

Conciseness5/5

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

The description is appropriately sized and front-loaded, with the first sentence stating the core purpose and the second adding critical behavioral context about secret substitution. Every sentence earns its place by providing essential information without redundancy or fluff.

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

Completeness3/5

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

Given the complexity of an HTTP request tool with 4 parameters, no annotations, and no output schema, the description is incomplete. It covers the basic operation and secret substitution but lacks details on response handling, error cases, or practical usage examples, which are needed for full contextual understanding.

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?

Schema description coverage is 0%, so the description must compensate. It adds meaning by explaining that parameters like URL, headers, and body support secret substitution with {secrets.key} syntax, which is not evident from the schema alone. However, it does not detail the purpose or format of each parameter beyond this, leaving gaps for parameters like contentType.

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

Purpose5/5

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

The description clearly states the specific verb ('Make an HTTP PATCH request') and resource ('to a specified URL'), distinguishing it from siblings like http-get or http-post by specifying the HTTP method. It also mentions optional body and headers, providing a complete picture of what the tool does.

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

Usage Guidelines4/5

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

The description implies usage context by specifying it's for HTTP PATCH requests, which helps differentiate from other HTTP methods in sibling tools. However, it does not explicitly state when to use PATCH vs. alternatives like PUT or POST, nor does it provide exclusions or detailed scenarios for choosing this tool.

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

Related 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/DeanWard/HAL'

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