flipped-aurora/gin-vue-admin · error
上游接口路径不能为空
Error message
上游接口路径不能为空
What it means
doUpstream validates that the endpoint argument is non-empty after trimming whitespace; an empty path means no upstream API was specified, so the request is rejected early. This is a programming/configuration guard, not a runtime network condition.
Source
Thrown at server/mcp/http_client.go:162
}
func postUpstream[T any](ctx context.Context, endpoint string, body any) (*upstreamEnvelope[T], error) {
return doUpstream[T](ctx, http.MethodPost, endpoint, nil, body)
}
func deleteUpstream[T any](ctx context.Context, endpoint string, body any) (*upstreamEnvelope[T], error) {
return doUpstream[T](ctx, http.MethodDelete, endpoint, nil, body)
}
func doUpstream[T any](ctx context.Context, method, endpoint string, query url.Values, body any) (*upstreamEnvelope[T], error) {
token := authTokenFromContext(ctx)
if token == "" {
return nil, fmt.Errorf("缺少MCP鉴权请求头: %s", configuredAuthHeader())
}
endpoint = strings.TrimSpace(endpoint)
if endpoint == "" {
return nil, fmt.Errorf("上游接口路径不能为空")
}
if !strings.HasPrefix(endpoint, "/") {
endpoint = "/" + endpoint
}
baseURL := upstreamBaseURL()
requestURL, err := url.Parse(baseURL + endpoint)
if err != nil {
return nil, fmt.Errorf("构建上游请求地址失败: %w", err)
}
if len(query) > 0 {
requestURL.RawQuery = query.Encode()
}
var reader io.Reader
if body != nil {
payload, err := json.Marshal(body)
if err != nil {View on GitHub (pinned to 3136500ef3)
Solutions
- Check the call site of getUpstream/postUpstream/deleteUpstream for the empty endpoint value
- Define endpoints as non-empty constants in one place instead of inline strings
- Add a startup assertion/config validation that all endpoint paths are set
- Log the calling tool name to identify which handler passed the empty path
Example fix
// before const userDetailEndpoint = "" resp, err := getUpstream[User](ctx, userDetailEndpoint, nil) // after const userDetailEndpoint = "/api/user/detail" resp, err := getUpstream[User](ctx, userDetailEndpoint, nil)
Defensive patterns
Strategy: validation
Validate before calling
func safeEndpoint(path string) (string, error) {
path = strings.TrimSpace(path)
if path == "" {
return "", errors.New("endpoint path must not be empty")
}
return path, nil
} Try / catch
result, err := getUpstream[Data](ctx, endpoint, nil)
if err != nil {
if strings.Contains(err.Error(), "上游接口路径不能为空") {
// log the tool name + call site; it is a config/code bug
}
return err
} Prevention
- Define endpoint paths as package-level constants, never computed empty values
- Validate config-driven endpoint values at startup
- Add unit tests for every tool handler asserting its endpoint constant is non-empty
- Avoid building paths dynamically from optional inputs without a default
When it happens
Trigger: A constant or config value holding the endpoint path is empty; a function building the path from parts returned ""; a tool handler passes an unset variable to getUpstream/postUpstream/deleteUpstream.
Common situations: Missing env var or config key for a configurable endpoint; refactoring left a placeholder empty; path assembled with strings that ended up blank.
Related errors
- 参数错误:executionPlan 必须提供
- packageName 不能为空
- packageType 必须是 'package' 或 'plugin'
- packageType 和 packageInfo.template 必须保持一致
- 当 needCreatedPackage=true 时,packageInfo 不能为空
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/69ee78f091ac2c97.
Report an issue: GitHub.