Tencent/WeKnora · error

failed to load MCP service: %w

Error message

failed to load MCP service: %w

What it means

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.

Source

Thrown at internal/mcp/oauth_manager.go:165

		return "", "", fmt.Errorf("failed to persist authorization state: %w", err)
	}

	return authURL, state, nil
}

// StartAuthorizationForService loads the MCP service by ID and starts the
// authorization-code flow, returning the URL the user must open. It is a
// convenience for callers (e.g. IM channels) that only hold a service ID and
// cannot reach the MCP service lookup directly.
func (m *OAuthManager) StartAuthorizationForService(
	ctx context.Context,
	tenantID uint64,
	principal types.Principal,
	serviceID, redirectURI, frontendRedirect string,
) (string, error) {
	service, err := m.serviceRepo.GetByID(ctx, tenantID, serviceID)
	if err != nil {
		return "", fmt.Errorf("failed to load MCP service: %w", err)
	}
	if service == nil {
		return "", fmt.Errorf("MCP service not found")
	}
	authURL, _, err := m.StartAuthorization(ctx, service, tenantID, principal, redirectURI, frontendRedirect)
	return authURL, err
}

// CompleteAuthorization handles the provider callback: it validates state,
// exchanges the code for tokens (PKCE), and persists the per-user token.
// Returns the frontend redirect URL and service ID recorded at
// StartAuthorization time so the caller can recycle any cached transport that
// still carries the previous OAuth client registration.
func (m *OAuthManager) CompleteAuthorization(
	ctx context.Context, state, code string,
) (frontendRedirect, serviceID string, err error) {
	ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), oauthCallbackTimeout)
	defer cancel()

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Check the wrapped error for the underlying repository cause
  2. Verify the service ID and tenant are correct
  3. Retry once the backing store is healthy
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at internal/mcp/oauth_manager.go:165 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of Tencent/WeKnora@988cbb0330 (2026-09-02). Data as JSON: /api/errors/6d6ae55c8a78a6ae. Report an issue: GitHub.