flipped-aurora/gin-vue-admin · error

path 参数是必需的

Error message

path 参数是必需的

What it means

RoleAPIAssigner.Handle requires a non-empty 'path' argument identifying the API route to assign. The error is thrown when it is absent, not a string, or whitespace-only. It is the path validation guard; 'method' defaults to "POST" and is optional.

Source

Thrown at server/mcp/role_api_assigner.go:67

		),
		mcp.WithString("method",
			mcp.Description("HTTP方法,默认POST"),
			mcp.DefaultString("POST"),
		),
	)
}

func (a *RoleAPIAssigner) Handle(ctx context.Context, request mcp.CallToolRequest) (*mcp.CallToolResult, error) {
	args := request.GetArguments()

	authorityID, err := parseAuthorityID(args["authorityId"])
	if err != nil {
		return nil, err
	}

	path, ok := args["path"].(string)
	if !ok || strings.TrimSpace(path) == "" {
		return nil, errors.New("path 参数是必需的")
	}
	method := "POST"
	if value, ok := args["method"].(string); ok && strings.TrimSpace(value) != "" {
		method = value
	}

	path, method = normalizePolicy(path, method)
	currentResp, err := postUpstream[map[string][]systemReq.CasbinInfo](ctx, "/casbin/getPolicyPathByAuthorityId", map[string]any{
		"authorityId": authorityID,
	})
	if err != nil {
		return nil, fmt.Errorf("获取角色当前API权限失败: %w", err)
	}

	current := currentResp.Data["paths"]
	updated, added := appendPolicyIfMissing(current, path, method)
	if added {
		if _, err = postUpstream[map[string]any](ctx, "/casbin/updateCasbin", map[string]any{

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Pass a non-empty 'path' string such as "/api/user/list"
  2. Verify the argument key is spelled exactly 'path'
  3. Trim and validate the path on the client before invoking

Example fix

// before
args["path"] = ""
// after
args["path"] = "/api/user/list"
Defensive patterns

Strategy: type-guard

Validate before calling

const p = args["path"]
if (typeof p !== "string" || p.trim() === "") {
  throw new Error("path 参数是必需的")
}

Type guard

function isNonEmptyString(v: unknown): v is string {
  return typeof v === "string" && v.trim().length > 0
}

Try / catch

try {
  await callTool("role_api_assigner", { path, method })
} catch (e) {
  if (String(e.message).includes("path 参数")) {
    // 提示用户输入路由路径
  }
  throw e
}

Prevention

When it happens

Trigger: Calling the tool with no 'path' argument, path set to "" or " ", or path as a non-string (number/object/null).

Common situations: Agent-built payload with wrong field name (e.g. 'route' or 'url'); template leaving path empty; upstream JSON payload serializing path as null.

Understand the failure class

Background: Missing required parameter errors: what 'X is required' and 'the required X param is missing' mean, and how to fix them — this error's family across 27 libraries.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/52106aef461396ba. Report an issue: GitHub.