googleapis/mcp-toolbox · error

dgraph url should not be empty

Error message

dgraph url should not be empty

What it means

initDgraphHttpClient validates the source Config during Initialize and rejects an empty DgraphUrl with this sentinel error. The Dgraph client cannot function without a base URL, so initialization fails fast rather than erroring per-request.

Source

Thrown at internal/sources/dgraph/dgraph.go:150

	var result struct {
		Data map[string]interface{} `json:"data"`
	}

	if err := json.Unmarshal(resp, &result); err != nil {
		return nil, fmt.Errorf("error parsing JSON: %v", err)
	}

	return result.Data, nil
}

func initDgraphHttpClient(ctx context.Context, tracer trace.Tracer, r Config) (*DgraphClient, error) {
	//nolint:all // Reassigned ctx
	ctx, span := sources.InitConnectionSpan(ctx, tracer, SourceType, r.Name)
	defer span.End()

	if r.DgraphUrl == "" {
		return nil, fmt.Errorf("dgraph url should not be empty")
	}

	hc := &DgraphClient{
		httpClient: &http.Client{},
		baseUrl:    r.DgraphUrl,
		HttpToken: &HttpToken{
			UserId:    r.User,
			Namespace: r.Namespace,
			Password:  r.Password,
		},
		apiKey: r.ApiKey,
	}

	if r.User != "" || r.Password != "" {
		if err := hc.loginWithCredentials(); err != nil {
			return nil, err
		}
	}

View on GitHub (pinned to 8cc6e09de2)

Solutions

  1. Set dgraphUrl in the source config, e.g. dgraphUrl: http://localhost:8080
  2. Check the YAML key spelling and indentation in the toolbox config
  3. If using env substitution, confirm the environment variable is set in the runtime environment
  4. Validate the config before starting the toolbox

Example fix

// before
sources:
  my-dgraph:
    kind: dgraph
// after
sources:
  my-dgraph:
    kind: dgraph
    dgraphUrl: http://localhost:8080
Defensive patterns

Strategy: validation

Validate before calling

cfg := dgraph.Config()
if cfg.DgraphUrl == "" {
	return fmt.Errorf("dgraph source %q: dgraphUrl must be set, e.g. http://localhost:8080", cfg.Name)
}
if u, err := url.Parse(cfg.DgraphUrl); err != nil || u.Host == "" {
	return fmt.Errorf("dgraphUrl is not a valid URL: %q", cfg.DgraphUrl)
}

Try / catch

if err := toolbox.Start(ctx); err != nil {
	if strings.Contains(err.Error(), "dgraph url should not be empty") {
		// fix the dgraph source config before restarting
	}
}

Prevention

When it happens

Trigger: Initializing a Dgraph source whose YAML/config omits the dgraphUrl field or sets it to an empty string.

Common situations: Missing key in the tools YAML config, wrong YAML field name (e.g. 'url' instead of 'dgraphUrl'), environment substitution producing an empty value.

Understand the failure class

Background: "missing required config value" errors: why libraries refuse to start when a configuration key is empty, unset, or blank — this error's family across 48 libraries.

Related errors


AI-assisted analysis of googleapis/mcp-toolbox@8cc6e09de2 (2026-09-05). Data as JSON: /api/errors/56a4e6367b5af802. Report an issue: GitHub.