siyuan-note/siyuan · error

unsupported method: %s

Error message

unsupported method: %s

What it means

Raised by sendByMethod when the HTTP method is not one of GET, POST, PUT, DELETE, PATCH (empty string defaults to GET). The method is uppercased and trimmed in HTTPRequest before dispatch, so any other verb (HEAD, OPTIONS, CONNECT, TRACE) or typo falls through to the default case and returns this fmt.Errorf.

Source

Thrown at kernel/util/httprequest.go:143

	return statusCode, contentType, truncateRunes(string(respBody), maxHTTPRequestChars), nil
}

// sendByMethod 按 method 分发请求,统一走 NewBrowserRequest 返回的 *req.Request。
func sendByMethod(request *req.Request, method, rawURL string) (*req.Response, error) {
	switch method {
	case "GET", "":
		return request.Get(rawURL)
	case "POST":
		return request.Post(rawURL)
	case "PUT":
		return request.Put(rawURL)
	case "DELETE":
		return request.Delete(rawURL)
	case "PATCH":
		return request.Patch(rawURL)
	default:
		return nil, fmt.Errorf("unsupported method: %s", method)
	}
}

// isTextContentType 判断 Content-Type 是否为可直接展示给智能体的文本类响应。
// 覆盖 text/*、application/json、application/xml、application/*+json 等。
func isTextContentType(contentType string) bool {
	ct := strings.ToLower(strings.TrimSpace(strings.SplitN(contentType, ";", 2)[0]))
	if ct == "" {
		return false
	}
	if strings.HasPrefix(ct, "text/") {
		return true
	}
	switch ct {
	case "application/json", "application/xml":
		return true
	}
	if strings.HasPrefix(ct, "application/") && (strings.HasSuffix(ct, "+json") || strings.HasSuffix(ct, "+xml")) {

View on GitHub (pinned to 251596fc0d)

Solutions

  1. Restrict the method to the allow-list {GET, POST, PUT, DELETE, PATCH} (empty defaults to GET) before calling HTTPRequest.
  2. If you only need headers, use GET and ignore the body rather than HEAD.
  3. Validate/normalize the action string in the MCP tool layer so unsupported verbs are rejected with a clearer upstream message.

Example fix

// before
util.HTTPRequest("HEAD", rawURL, headers, body)

// after: whitelist the method
allowed := map[string]bool{"GET": true, "POST": true, "PUT": true, "DELETE": true, "PATCH": true}
method = strings.ToUpper(strings.TrimSpace(method))
if method == "" {
    method = "GET"
}
if !allowed[method] {
    return fmt.Errorf("unsupported method: %s", method)
}
util.HTTPRequest(method, rawURL, headers, body)
Defensive patterns

Strategy: validation

Validate before calling

allowed := map[string]bool{"GET": true, "POST": true, "PUT": true, "DELETE": true, "PATCH": true}
method = strings.ToUpper(strings.TrimSpace(method))
if method == "" {
    method = "GET"
}
if !allowed[method] {
    return fmt.Errorf("unsupported method: %s", method)
}

Prevention

When it happens

Trigger: An agent or caller passes method="HEAD", "OPTIONS", "CONNECT", "TRACE", a lowercase variant that still isn't in the allow-list after ToUpper, or a misspelling like "POTS". The MCP http_request tool forwards args["action"] verbatim, so a malformed action reaches sendByMethod.

Common situations: An LLM agent invents a method string; a caller expects HEAD support for a lightweight existence check; a typo in a scripted action; integration code reusing a generic 'method' field that permits arbitrary values.

Related errors


AI-assisted analysis of siyuan-note/siyuan@251596fc0d (2026-08-12). Data as JSON: /api/errors/f6c411c631e0b2bc. Report an issue: GitHub.