{"record":{"id":"90e83a4d9bd15a5e","repo":"dgraph-io/dgraph","slug":"failed-to-get-schema-v","errorCode":null,"errorMessage":"failed to get schema: %v","messagePattern":"failed to get schema: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"dgraph/cmd/mcp/mcp_server.go","lineNumber":430,"sourceCode":" \t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\",\n\t\t\t\t}\n\t\t\t\t`,\n\t\t\t},\n\t\t}, nil\n\t})\n\n\t// Add resource with its handler\n\ts.AddResource(schemaResource, func(ctx context.Context, request mcp.ReadResourceRequest) ([]mcp.ResourceContents, error) {\n\t\t// Execute operation\n\t\tconn, err := getConn(connectionString)\n\t\tif err != nil {\n\t\t\treturn nil, err\n\t\t}\n\t\tresp, err := conn.NewTxn().Query(ctx, \"schema {}\")\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to get schema: %v\", err)\n\t\t}\n\n\t\treturn []mcp.ResourceContents{\n\t\t\tmcp.TextResourceContents{\n\t\t\t\tURI:      \"dgraph://schema\",\n\t\t\t\tMIMEType: \"text/plain\",\n\t\t\t\tText:     string(resp.Json),\n\t\t\t},\n\t\t}, nil\n\t})\n\n\taddPrompt(s)\n\n\treturn s, nil\n}\n\nfunc addPrompt(s *server.MCPServer) {\n\tprompt := string(promptBytes)","sourceCodeStart":412,"sourceCodeEnd":448,"githubUrl":"https://github.com/dgraph-io/dgraph/blob/759e242be62c91f8d084da06ad0c8d21256d9c07/dgraph/cmd/mcp/mcp_server.go#L412-L448","documentation":"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.","triggerScenarios":"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.","commonSituations":"Cluster still initializing when the AI assistant requests schema info; Alpha overloaded or restarting; long-running request canceled by the client.","solutions":["Check cluster health and ensure a leader is elected before invoking the tool","Inspect Alpha logs for the wrapped underlying error and address it","Retry the tool call after the cluster stabilizes","Raise the client/transport timeout if queries are timing out"],"exampleFix":"// before: immediate call at startup\nschema := getSchemaFromMCP()\n// after: wait for health first\nwaitUntilHealthy(\"http://alpha:8080/health\")\nschema := getSchemaFromMCP()","handlingStrategy":"retry","validationCode":"// Verify cluster readiness before calling the schema tool\nconst h = await (await fetch('http://alpha:8080/health')).json();\nif (!Array.isArray(h) || !h.every(x => x.status === 'healthy')) {\n  throw new Error('Cluster not fully healthy; schema fetch would fail');\n}","typeGuard":null,"tryCatchPattern":"try {\n  const schema = await getSchemaTool();\n} catch (e) {\n  if (String(e.message).includes('failed to get schema')) {\n    // transient cluster issue — back off and retry once\n    await new Promise(r => setTimeout(r, 3000));\n    return getSchemaTool();\n  }\n  throw e;\n}","preventionTips":["Gate schema-dependent AI workflows on a health check","Retry transient consensus errors instead of surfacing them to end users","Keep context deadlines generous for the schema query"],"tags":["query","schema","cluster-health","mcp"],"backgroundTag":"query-failed","analyzedSha":"759e242be62c91f8d084da06ad0c8d21256d9c07","analyzedAt":"2026-09-01T14:42:12.034Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}