Tencent/WeKnora · error

mcp service not found

Error message

mcp service not found

What it means

ListByService looks up the parent MCP service by tenantID+serviceID before listing approvals; a nil row (not an error) from mcpRepo.GetByID yields this plain error. It signals the referenced MCP service record does not exist for the tenant.

Source

Thrown at internal/application/service/mcp_tool_approval_service.go:30

	repo    interfaces.MCPToolApprovalRepository
	mcpRepo interfaces.MCPServiceRepository
}

// NewMCPToolApprovalService constructs the MCP tool approval service.
func NewMCPToolApprovalService(
	repo interfaces.MCPToolApprovalRepository,
	mcpRepo interfaces.MCPServiceRepository,
) interfaces.MCPToolApprovalService {
	return &mcpToolApprovalService{repo: repo, mcpRepo: mcpRepo}
}

func (s *mcpToolApprovalService) ListByService(ctx context.Context, tenantID uint64, serviceID string) ([]*types.MCPToolApproval, error) {
	svc, err := s.mcpRepo.GetByID(ctx, tenantID, serviceID)
	if err != nil {
		return nil, err
	}
	if svc == nil {
		return nil, fmt.Errorf("mcp service not found")
	}
	return s.repo.ListByService(ctx, tenantID, serviceID)
}

func (s *mcpToolApprovalService) SetRequireApproval(
	ctx context.Context, tenantID uint64, serviceID, toolName string, require bool,
) error {
	if toolName == "" {
		return fmt.Errorf("tool_name is required")
	}
	svc, err := s.mcpRepo.GetByID(ctx, tenantID, serviceID)
	if err != nil {
		return err
	}
	if svc == nil {
		return fmt.Errorf("mcp service not found")
	}
	row := &types.MCPToolApproval{

View on GitHub (pinned to 988cbb0330)

Solutions

  1. Verify the serviceID exists via the MCP service list/get API for the tenant
  2. Confirm the request targets the correct tenant
  3. Create the MCP service first if it was never provisioned
  4. Return a typed not-found error at the HTTP layer (404) rather than surfacing this raw

Example fix

// before
approvals, err := approvalSvc.ListByService(ctx, tenantID, serviceID)
// after
if _, err := mcpSvc.Get(ctx, tenantID, serviceID); err != nil {
	return nil, err // surface not-found before listing approvals
}
approvals, err := approvalSvc.ListByService(ctx, tenantID, serviceID)
Defensive patterns

Strategy: validation

Validate before calling

svc, err := mcpRepo.GetByID(ctx, tenantID, serviceID)
if err != nil { return err }
if svc == nil {
	return fmt.Errorf("mcp service %q not found for tenant %d", serviceID, tenantID)
}
// now safe
approvals, err := approvalSvc.ListByService(ctx, tenantID, serviceID)

Try / catch

approvals, err := approvalSvc.ListByService(ctx, tenantID, serviceID)
if err != nil {
	if strings.Contains(err.Error(), "mcp service not found") {
		return ErrServiceNotFound // map to 404 at the transport layer
	}
	return err
}

Prevention

When it happens

Trigger: Calling ListByService with a serviceID that does not exist in the tenant's MCP services, or one belonging to another tenant.

Common situations: Stale client cache holding a deleted service ID; wrong tenant header in a multi-tenant deployment; UUID/ID typo in the request; service was soft-deleted but references remain.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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