{"record":{"id":"6d6ae55c8a78a6ae","repo":"Tencent/WeKnora","slug":"failed-to-load-mcp-service-w","errorCode":null,"errorMessage":"failed to load MCP service: %w","messagePattern":"failed to load MCP service: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/mcp/oauth_manager.go","lineNumber":165,"sourceCode":"\t\treturn \"\", \"\", fmt.Errorf(\"failed to persist authorization state: %w\", err)\n\t}\n\n\treturn authURL, state, nil\n}\n\n// StartAuthorizationForService loads the MCP service by ID and starts the\n// authorization-code flow, returning the URL the user must open. It is a\n// convenience for callers (e.g. IM channels) that only hold a service ID and\n// cannot reach the MCP service lookup directly.\nfunc (m *OAuthManager) StartAuthorizationForService(\n\tctx context.Context,\n\ttenantID uint64,\n\tprincipal types.Principal,\n\tserviceID, redirectURI, frontendRedirect string,\n) (string, error) {\n\tservice, err := m.serviceRepo.GetByID(ctx, tenantID, serviceID)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to load MCP service: %w\", err)\n\t}\n\tif service == nil {\n\t\treturn \"\", fmt.Errorf(\"MCP service not found\")\n\t}\n\tauthURL, _, err := m.StartAuthorization(ctx, service, tenantID, principal, redirectURI, frontendRedirect)\n\treturn authURL, err\n}\n\n// CompleteAuthorization handles the provider callback: it validates state,\n// exchanges the code for tokens (PKCE), and persists the per-user token.\n// Returns the frontend redirect URL and service ID recorded at\n// StartAuthorization time so the caller can recycle any cached transport that\n// still carries the previous OAuth client registration.\nfunc (m *OAuthManager) CompleteAuthorization(\n\tctx context.Context, state, code string,\n) (frontendRedirect, serviceID string, err error) {\n\tctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), oauthCallbackTimeout)\n\tdefer cancel()","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/Tencent/WeKnora/blob/988cbb03305e055d8ebb7d46d9ac6cc0803cd074/internal/mcp/oauth_manager.go#L147-L183","documentation":"Returned by StartAuthorizationForService when m.serviceRepo.GetByID fails to load the MCP service for the given tenant and service ID — a repository error (connection failure, timeout) rather than a missing record. The authorization flow cannot proceed without the service's OAuth configuration.","triggerScenarios":"Thrown at internal/mcp/oauth_manager.go:165 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check the wrapped error for the underlying repository cause","Verify the service ID and tenant are correct","Retry once the backing store is healthy"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"988cbb03305e055d8ebb7d46d9ac6cc0803cd074","analyzedAt":"2026-09-02T14:41:08.344Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}