dgraph-io/dgraph · error

failed to get schema: %v

Error message

failed to get schema: %v

What it means

A second schema retrieval path (a tool/function in the MCP server) wraps failures of the `schema {}` query with `failed to get schema: %v`. Connection failures are returned unwrapped; this message specifically means the query itself failed after a successful connection.

Source

Thrown at dgraph/cmd/mcp/mcp_server.go:430

 							}
						}
					",
				}
				`,
			},
		}, nil
	})

	// Add resource with its handler
	s.AddResource(schemaResource, func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {
		// Execute operation
		conn, err := getConn(connectionString)
		if err != nil {
			return nil, err
		}
		resp, err := conn.NewTxn().Query(ctx, "schema {}")
		if err != nil {
			return nil, fmt.Errorf("failed to get schema: %v", err)
		}

		return []mcp.ResourceContents{
			mcp.TextResourceContents{
				URI:      "dgraph://schema",
				MIMEType: "text/plain",
				Text:     string(resp.Json),
			},
		}, nil
	})

	addPrompt(s)

	return s, nil
}

func addPrompt(s *server.MCPServer) {
	prompt := string(promptBytes)

View on GitHub (pinned to 759e242be6)

Solutions

  1. Check cluster health and ensure a leader is elected before invoking the tool
  2. Inspect Alpha logs for the wrapped underlying error and address it
  3. Retry the tool call after the cluster stabilizes
  4. Raise the client/transport timeout if queries are timing out

Example fix

// before: immediate call at startup
schema := getSchemaFromMCP()
// after: wait for health first
waitUntilHealthy("http://alpha:8080/health")
schema := getSchemaFromMCP()
Defensive patterns

Strategy: retry

Validate before calling

// Verify cluster readiness before calling the schema tool
const h = await (await fetch('http://alpha:8080/health')).json();
if (!Array.isArray(h) || !h.every(x => x.status === 'healthy')) {
  throw new Error('Cluster not fully healthy; schema fetch would fail');
}

Try / catch

try {
  const schema = await getSchemaTool();
} catch (e) {
  if (String(e.message).includes('failed to get schema')) {
    // transient cluster issue — back off and retry once
    await new Promise(r => setTimeout(r, 3000));
    return getSchemaTool();
  }
  throw e;
}

Prevention

When it happens

Trigger: Invoking the MCP tool that fetches schema while the Alpha is unhealthy, has no leader, the transaction fails server-side, or the request context is canceled/timed out.

Common situations: Cluster still initializing when the AI assistant requests schema info; Alpha overloaded or restarting; long-running request canceled by the client.

Related errors


AI-assisted analysis of dgraph-io/dgraph@759e242be6 (2026-09-01). Data as JSON: /api/errors/90e83a4d9bd15a5e. Report an issue: GitHub.